mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Create new entities for redirect rules
This commit is contained in:
parent
752100f1ce
commit
c91a534d1a
@ -28,15 +28,18 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||
fieldWithUtf8Charset($builder->createField('baseUrlRedirect', Types::TEXT), $emConfig)
|
||||
->columnName('base_url_redirect')
|
||||
->nullable()
|
||||
->length(2048)
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('regular404Redirect', Types::TEXT), $emConfig)
|
||||
->columnName('regular_not_found_redirect')
|
||||
->nullable()
|
||||
->length(2048)
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('invalidShortUrlRedirect', Types::TEXT), $emConfig)
|
||||
->columnName('invalid_short_url_redirect')
|
||||
->nullable()
|
||||
->length(2048)
|
||||
->build();
|
||||
};
|
||||
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core;
|
||||
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
||||
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Shlinkio\Shlink\Core\RedirectRule\Model\RedirectConditionType;
|
||||
|
||||
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||
$builder = new ClassMetadataBuilder($metadata);
|
||||
|
||||
$builder->setTable(determineTableName('redirect_conditions', $emConfig));
|
||||
|
||||
$builder->createField('id', Types::BIGINT)
|
||||
->columnName('id')
|
||||
->makePrimaryKey()
|
||||
->generatedValue('IDENTITY')
|
||||
->option('unsigned', true)
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('name', Types::STRING), $emConfig)
|
||||
->columnName('name')
|
||||
->length(512)
|
||||
->build();
|
||||
|
||||
$builder->addUniqueConstraint(['name'], 'UQ_name');
|
||||
|
||||
(new FieldBuilder($builder, [
|
||||
'fieldName' => 'type',
|
||||
'type' => Types::STRING,
|
||||
'enumType' => RedirectConditionType::class,
|
||||
]))->columnName('type')
|
||||
->length(255)
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('matchKey', Types::STRING), $emConfig)
|
||||
->columnName('match_key')
|
||||
->length(512)
|
||||
->nullable()
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('matchValue', Types::STRING), $emConfig)
|
||||
->columnName('match_value')
|
||||
->length(512)
|
||||
->build();
|
||||
};
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core;
|
||||
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
|
||||
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||
$builder = new ClassMetadataBuilder($metadata);
|
||||
|
||||
$builder->setTable(determineTableName('short_url_redirect_rules', $emConfig));
|
||||
|
||||
$builder->createField('id', Types::BIGINT)
|
||||
->columnName('id')
|
||||
->makePrimaryKey()
|
||||
->generatedValue('IDENTITY')
|
||||
->option('unsigned', true)
|
||||
->build();
|
||||
|
||||
$builder->createField('priority', Types::INTEGER)
|
||||
->columnName('priority')
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('longUrl', Types::TEXT), $emConfig)
|
||||
->columnName('long_url')
|
||||
->length(2048)
|
||||
->build();
|
||||
|
||||
$builder->createManyToOne('shortUrl', ShortUrl\Entity\ShortUrl::class)
|
||||
->addJoinColumn('short_url_id', 'id', false, false, 'CASCADE')
|
||||
->build();
|
||||
|
||||
$builder->createManyToMany('conditions', RedirectRule\Entity\RedirectCondition::class)
|
||||
->setJoinTable(determineTableName('redirect_conditions_in_short_url_redirect_rules', $emConfig))
|
||||
->addInverseJoinColumn('redirect_condition_id', 'id', onDelete: 'CASCADE')
|
||||
->addJoinColumn('short_url_redirect_rule_id', 'id', onDelete: 'CASCADE')
|
||||
->build();
|
||||
};
|
@ -32,6 +32,7 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('longUrl', Types::TEXT), $emConfig)
|
||||
->columnName('long_url')
|
||||
->length(2048)
|
||||
->build();
|
||||
|
||||
$builder->createManyToOne('shortUrl', ShortUrl\Entity\ShortUrl::class)
|
||||
|
@ -25,6 +25,7 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('longUrl', Types::TEXT), $emConfig)
|
||||
->columnName('original_url') // Rename to long_url some day? ¯\_(ツ)_/¯
|
||||
->length(2048)
|
||||
->build();
|
||||
|
||||
fieldWithUtf8Charset($builder->createField('shortCode', Types::STRING), $emConfig, 'bin')
|
||||
|
17
module/Core/src/RedirectRule/Entity/RedirectCondition.php
Normal file
17
module/Core/src/RedirectRule/Entity/RedirectCondition.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Shlinkio\Shlink\Core\RedirectRule\Entity;
|
||||
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Core\RedirectRule\Model\RedirectConditionType;
|
||||
|
||||
class RedirectCondition extends AbstractEntity
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $name,
|
||||
public readonly RedirectConditionType $type,
|
||||
public readonly string $matchValue,
|
||||
public readonly ?string $matchKey = null,
|
||||
) {
|
||||
}
|
||||
}
|
22
module/Core/src/RedirectRule/Entity/ShortUrlRedirectRule.php
Normal file
22
module/Core/src/RedirectRule/Entity/ShortUrlRedirectRule.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Shlinkio\Shlink\Core\RedirectRule\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
|
||||
class ShortUrlRedirectRule extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @param Collection<RedirectCondition> $conditions
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ShortUrl $shortUrl, // No need to read this field. It's used by doctrine
|
||||
public readonly int $priority,
|
||||
public readonly string $longUrl,
|
||||
public readonly Collection $conditions = new ArrayCollection(),
|
||||
) {
|
||||
}
|
||||
}
|
10
module/Core/src/RedirectRule/Model/RedirectConditionType.php
Normal file
10
module/Core/src/RedirectRule/Model/RedirectConditionType.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Shlinkio\Shlink\Core\RedirectRule\Model;
|
||||
|
||||
enum RedirectConditionType: string
|
||||
{
|
||||
case DEVICE = 'device';
|
||||
// case LANGUAGE = 'language';
|
||||
// case QUERY_PARAM = 'query';
|
||||
}
|
Loading…
Reference in New Issue
Block a user