2018-12-16 05:08:03 -06:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2018-12-16 05:08:03 -06:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink\Core;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Types\Type;
|
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
2019-08-24 03:25:43 -05:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; // @codingStandardsIgnoreLine
|
2019-08-11 06:44:42 -05:00
|
|
|
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
2019-08-24 03:25:43 -05:00
|
|
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
2018-12-16 05:08:03 -06:00
|
|
|
|
2019-10-05 10:26:10 -05:00
|
|
|
/** @var $metadata ClassMetadata */ // @codingStandardsIgnoreLine
|
2018-12-16 05:08:03 -06:00
|
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
|
|
|
|
$builder->setTable('visits')
|
|
|
|
->setCustomRepositoryClass(Repository\VisitRepository::class);
|
|
|
|
|
|
|
|
$builder->createField('id', Type::BIGINT)
|
|
|
|
->columnName('id')
|
|
|
|
->makePrimaryKey()
|
|
|
|
->generatedValue('IDENTITY')
|
|
|
|
->option('unsigned', true)
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('referer', Type::STRING)
|
|
|
|
->nullable()
|
2019-08-24 03:25:43 -05:00
|
|
|
->length(Visitor::REFERER_MAX_LENGTH)
|
2018-12-16 05:08:03 -06:00
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('date', ChronosDateTimeType::CHRONOS_DATETIME)
|
|
|
|
->columnName('`date`')
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('remoteAddr', Type::STRING)
|
|
|
|
->columnName('remote_addr')
|
2019-08-24 03:25:43 -05:00
|
|
|
->length(Visitor::REMOTE_ADDRESS_MAX_LENGTH)
|
2018-12-16 05:08:03 -06:00
|
|
|
->nullable()
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('userAgent', Type::STRING)
|
|
|
|
->columnName('user_agent')
|
2019-08-24 03:25:43 -05:00
|
|
|
->length(Visitor::USER_AGENT_MAX_LENGTH)
|
2018-12-16 05:08:03 -06:00
|
|
|
->nullable()
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createManyToOne('shortUrl', Entity\ShortUrl::class)
|
2019-03-05 13:36:35 -06:00
|
|
|
->addJoinColumn('short_url_id', 'id', false, false, 'CASCADE')
|
2018-12-16 05:08:03 -06:00
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createManyToOne('visitLocation', Entity\VisitLocation::class)
|
2019-03-05 13:36:35 -06:00
|
|
|
->addJoinColumn('visit_location_id', 'id', true, false, 'Set NULL')
|
2018-12-16 05:08:03 -06:00
|
|
|
->cascadePersist()
|
|
|
|
->build();
|