Skip to content

Commit

Permalink
Merge pull request #199 from acelaya/feature/delete-short-codes
Browse files Browse the repository at this point in the history
Delete short URLs
  • Loading branch information
acelaya authored Sep 15, 2018
2 parents 5b9784c + 9d8fb05 commit ff8441f
Show file tree
Hide file tree
Showing 46 changed files with 1,171 additions and 409 deletions.
1 change: 1 addition & 0 deletions config/autoload/app_options.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'name' => 'Shlink',
'version' => '%SHLINK_VERSION%',
'secret_key' => env('SECRET_KEY'),
'disable_track_param' => null,
],

];
13 changes: 13 additions & 0 deletions config/autoload/delete_short_urls.global.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace Shlinkio\Shlink;

return [

'delete_short_urls' => [
'visits_threshold' => 15,
'check_visits_threshold' => true,
],

];
50 changes: 50 additions & 0 deletions data/migrations/Version20180915110857.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace ShlinkMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20180915110857 extends AbstractMigration
{
private const ON_DELETE_MAP = [
'visit_locations' => 'SET NULL',
'short_urls' => 'CASCADE',
];

/**
* @param Schema $schema
* @throws SchemaException
*/
public function up(Schema $schema): void
{
$visits = $schema->getTable('visits');
$foreignKeys = $visits->getForeignKeys();

// Remove all existing foreign keys and add them again with CASCADE delete
foreach ($foreignKeys as $foreignKey) {
$visits->removeForeignKey($foreignKey->getName());
$foreignTable = $foreignKey->getForeignTableName();

$visits->addForeignKeyConstraint(
$foreignTable,
$foreignKey->getLocalColumns(),
$foreignKey->getForeignColumns(),
[
'onDelete' => self::ON_DELETE_MAP[$foreignTable],
'onUpdate' => 'RESTRICT',
]
);
}
}

public function down(Schema $schema): void
{
// Nothing to run
}
}
65 changes: 65 additions & 0 deletions docs/swagger/paths/v1_short-codes_{shortCode}.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,70 @@
}
}
}
},

"delete": {
"tags": [
"ShortCodes"
],
"summary": "Delete short code",
"description": "Deletes the short URL for provided short code.",
"parameters": [
{
"name": "shortCode",
"in": "path",
"description": "The short code to edit.",
"required": true,
"schema": {
"type": "string"
}
}
],
"security": [
{
"Bearer": []
}
],
"responses": {
"204": {
"description": "The short code has been properly deleted."
},
"400": {
"description": "The visits threshold in shlink does not allow this short URL to be deleted.",
"content": {
"application/json": {
"schema": {
"$ref": "../definitions/Error.json"
}
}
},
"examples": {
"application/json": {
"error": "INVALID_SHORTCODE_DELETION",
"message": "It is not possible to delete URL with short code \"abc123\" because it has reached more than \"15\" visits."
}
}
},
"404": {
"description": "No short URL was found for provided short code.",
"content": {
"application/json": {
"schema": {
"$ref": "../definitions/Error.json"
}
}
}
},
"500": {
"description": "Unexpected error.",
"content": {
"application/json": {
"schema": {
"$ref": "../definitions/Error.json"
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions module/CLI/config/cli.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Command\Shortcode\ListShortcodesCommand::NAME => Command\Shortcode\ListShortcodesCommand::class,
Command\Shortcode\GetVisitsCommand::NAME => Command\Shortcode\GetVisitsCommand::class,
Command\Shortcode\GeneratePreviewCommand::NAME => Command\Shortcode\GeneratePreviewCommand::class,
Command\Shortcode\DeleteShortCodeCommand::NAME => Command\Shortcode\DeleteShortCodeCommand::class,

Command\Visit\ProcessVisitsCommand::NAME => Command\Visit\ProcessVisitsCommand::class,

Expand Down
13 changes: 13 additions & 0 deletions module/CLI/config/dependencies.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
Command\Shortcode\ListShortcodesCommand::class => ConfigAbstractFactory::class,
Command\Shortcode\GetVisitsCommand::class => ConfigAbstractFactory::class,
Command\Shortcode\GeneratePreviewCommand::class => ConfigAbstractFactory::class,
Command\Shortcode\DeleteShortCodeCommand::class => ConfigAbstractFactory::class,

Command\Visit\ProcessVisitsCommand::class => ConfigAbstractFactory::class,

Command\Config\GenerateCharsetCommand::class => ConfigAbstractFactory::class,
Command\Config\GenerateSecretCommand::class => ConfigAbstractFactory::class,

Command\Api\GenerateKeyCommand::class => ConfigAbstractFactory::class,
Command\Api\DisableKeyCommand::class => ConfigAbstractFactory::class,
Command\Api\ListKeysCommand::class => ConfigAbstractFactory::class,

Command\Tag\ListTagsCommand::class => ConfigAbstractFactory::class,
Command\Tag\CreateTagCommand::class => ConfigAbstractFactory::class,
Command\Tag\RenameTagCommand::class => ConfigAbstractFactory::class,
Expand All @@ -53,16 +58,24 @@
PreviewGenerator::class,
'translator',
],
Command\Shortcode\DeleteShortCodeCommand::class => [
Service\ShortUrl\DeleteShortUrlService::class,
'translator',
],

Command\Visit\ProcessVisitsCommand::class => [
Service\VisitService::class,
IpApiLocationResolver::class,
'translator',
],

Command\Config\GenerateCharsetCommand::class => ['translator'],
Command\Config\GenerateSecretCommand::class => ['translator'],

Command\Api\GenerateKeyCommand::class => [ApiKeyService::class, 'translator'],
Command\Api\DisableKeyCommand::class => [ApiKeyService::class, 'translator'],
Command\Api\ListKeysCommand::class => [ApiKeyService::class, 'translator'],

Command\Tag\ListTagsCommand::class => [Service\Tag\TagService::class, Translator::class],
Command\Tag\CreateTagCommand::class => [Service\Tag\TagService::class, Translator::class],
Command\Tag\RenameTagCommand::class => [Service\Tag\TagService::class, Translator::class],
Expand Down
Binary file modified module/CLI/lang/es.mo
Binary file not shown.
62 changes: 51 additions & 11 deletions module/CLI/lang/es.po
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: Shlink 1.0\n"
"POT-Creation-Date: 2018-08-04 16:35+0200\n"
"PO-Revision-Date: 2018-08-04 16:37+0200\n"
"POT-Creation-Date: 2018-09-15 17:57+0200\n"
"PO-Revision-Date: 2018-09-15 18:02+0200\n"
"Last-Translator: Alejandro Celaya <[email protected]>\n"
"Language-Team: \n"
"Language: es_ES\n"
Expand Down Expand Up @@ -80,6 +80,41 @@ msgstr ""
msgid "Secret key: \"%s\""
msgstr "Clave secreta: \"%s\""

msgid "Deletes a short URL"
msgstr "Elimina una URL"

msgid "The short code to be deleted"
msgstr "El código corto a eliminar"

msgid ""
"Ignores the safety visits threshold check, which could make short URLs with "
"many visits to be accidentally deleted"
msgstr ""
"Ignora el límite de seguridad de visitas, pudiendo resultar en el borrado "
"accidental de URLs con muchas visitas"

#, php-format
msgid "Provided short code \"%s\" could not be found."
msgstr "El código corto proporcionado \"%s\" no ha podido ser encontrado."

#, php-format
msgid ""
"It was not possible to delete the short URL with short code \"%s\" because "
"it has more than %s visits."
msgstr ""
"No se pudo eliminar la URL acortada con código corto \"%s\" porque tiene más "
"de %s visitas."

msgid "Do you want to delete it anyway?"
msgstr "¿Aún así quieres eliminarla?"

msgid "Short URL was not deleted."
msgstr "La URL corta no ha sido eliminada."

#, php-format
msgid "Short URL with short code \"%s\" successfully deleted."
msgstr "La URL acortada con el código corto \"%s\" eliminada correctamente."

msgid ""
"Processes and generates the previews for every URL, improving performance "
"for later web requests."
Expand Down Expand Up @@ -183,12 +218,12 @@ msgstr "Origen"
msgid "Date"
msgstr "Fecha"

msgid "Remote Address"
msgstr "Dirección remota"

msgid "User agent"
msgstr "Agente de usuario"

msgid "Country"
msgstr "País"

msgid "List all short URLs"
msgstr "Listar todas las URLs cortas"

Expand Down Expand Up @@ -218,8 +253,11 @@ msgstr "Si se desea mostrar las etiquetas o no"
msgid "Short code"
msgstr "Código corto"

msgid "Original URL"
msgstr "URL original"
msgid "Short URL"
msgstr "URL corta"

msgid "Long URL"
msgstr "URL larga"

msgid "Date created"
msgstr "Fecha de creación"
Expand Down Expand Up @@ -253,10 +291,6 @@ msgstr "URL larga:"
msgid "Provided short code \"%s\" has an invalid format."
msgstr "El código corto proporcionado \"%s\" tiene un formato inválido."

#, php-format
msgid "Provided short code \"%s\" could not be found."
msgstr "El código corto proporcionado \"%s\" no ha podido ser encontrado."

msgid "Creates one or more tags."
msgstr "Crea una o más etiquetas."

Expand Down Expand Up @@ -327,6 +361,12 @@ msgstr "Limite del localizador de IPs alcanzado. Esperando %s segundos..."
msgid "Finished processing all IPs"
msgstr "Finalizado el procesado de todas las IPs"

#~ msgid "Remote Address"
#~ msgstr "Dirección remota"

#~ msgid "Original URL"
#~ msgstr "URL original"

#~ msgid "You have reached last page"
#~ msgstr "Has alcanzado la última página"

Expand Down
Loading

0 comments on commit ff8441f

Please sign in to comment.