Added valid_since and valid_until columns to shoirt_urls table

This commit is contained in:
Alejandro Celaya 2017-10-21 11:39:27 +02:00
parent 97a54aef06
commit 68b4cfbae0
5 changed files with 49 additions and 18 deletions

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace ShlinkMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Types\Type;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171021093246 extends AbstractMigration
{
/**
* @param Schema $schema
* @throws SchemaException
*/
public function up(Schema $schema)
{
$shortUrls = $schema->getTable('short_urls');
$shortUrls->addColumn('valid_since', Type::DATETIME, [
'notnull' => false,
]);
$shortUrls->addColumn('valid_until', Type::DATETIME, [
'notnull' => false,
]);
}
/**
* @param Schema $schema
* @throws SchemaException
*/
public function down(Schema $schema)
{
$shortUrls = $schema->getTable('short_urls');
$shortUrls->dropColumn('valid_since');
$shortUrls->dropColumn('valid_until');
}
}

View File

@ -49,7 +49,7 @@ return [
Service\Tag\TagService::class => ['em'],
// Middleware
Action\RedirectAction::class => [Service\UrlShortener::class, Service\VisitsTracker::class, 'Logger_Shlink'],
Action\RedirectAction::class => [Service\UrlShortener::class, Service\VisitsTracker::class],
Action\QrCodeAction::class => [RouterInterface::class, Service\UrlShortener::class, 'Logger_Shlink'],
Action\PreviewAction::class => [PreviewGenerator::class, Service\UrlShortener::class],
Middleware\QrCodeCacheMiddleware::class => [Cache::class],

View File

@ -7,8 +7,6 @@ use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Shlinkio\Shlink\Core\Action\Util\ErrorResponseBuilderTrait;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
@ -28,19 +26,11 @@ class RedirectAction implements MiddlewareInterface
* @var VisitsTrackerInterface
*/
private $visitTracker;
/**
* @var null|LoggerInterface
*/
private $logger;
public function __construct(
UrlShortenerInterface $urlShortener,
VisitsTrackerInterface $visitTracker,
LoggerInterface $logger = null
) {
public function __construct(UrlShortenerInterface $urlShortener, VisitsTrackerInterface $visitTracker)
{
$this->urlShortener = $urlShortener;
$this->visitTracker = $visitTracker;
$this->logger = $logger ?: new NullLogger();
}
/**

View File

@ -60,13 +60,13 @@ class UrlShortener implements UrlShortenerInterface
* @throws InvalidUrlException
* @throws RuntimeException
*/
public function urlToShortCode(UriInterface $url, array $tags = [])
public function urlToShortCode(UriInterface $url, array $tags = []): string
{
// If the url already exists in the database, just return its short code
$shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([
'originalUrl' => $url,
]);
if (isset($shortUrl)) {
if ($shortUrl !== null) {
return $shortUrl->getShortCode();
}
@ -147,7 +147,7 @@ class UrlShortener implements UrlShortenerInterface
* @throws InvalidShortCodeException
* @throws EntityDoesNotExistException
*/
public function shortCodeToUrl($shortCode): string
public function shortCodeToUrl(string $shortCode): string
{
$cacheKey = sprintf('%s_longUrl', $shortCode);
// Check if the short code => URL map is already cached

View File

@ -20,7 +20,7 @@ interface UrlShortenerInterface
* @throws InvalidUrlException
* @throws RuntimeException
*/
public function urlToShortCode(UriInterface $url, array $tags = []);
public function urlToShortCode(UriInterface $url, array $tags = []): string;
/**
* Tries to find the mapped URL for provided short code. Returns null if not found
@ -30,5 +30,5 @@ interface UrlShortenerInterface
* @throws InvalidShortCodeException
* @throws EntityDoesNotExistException
*/
public function shortCodeToUrl($shortCode): string;
public function shortCodeToUrl(string $shortCode): string;
}