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;
|
|
|
|
|
2020-01-06 16:08:14 -06:00
|
|
|
use Doctrine\DBAL\Types\Types;
|
2018-12-16 05:08:03 -06:00
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
2020-01-29 03:06:42 -06:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
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
|
|
|
|
2020-01-29 03:53:06 -06:00
|
|
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
2020-01-29 03:06:42 -06:00
|
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
|
2020-01-29 03:53:06 -06:00
|
|
|
$builder->setTable(determineTableName('visits', $emConfig))
|
2020-01-29 03:06:42 -06:00
|
|
|
->setCustomRepositoryClass(Repository\VisitRepository::class);
|
|
|
|
|
|
|
|
$builder->createField('id', Types::BIGINT)
|
|
|
|
->columnName('id')
|
|
|
|
->makePrimaryKey()
|
|
|
|
->generatedValue('IDENTITY')
|
|
|
|
->option('unsigned', true)
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('referer', Types::STRING)
|
|
|
|
->nullable()
|
|
|
|
->length(Visitor::REFERER_MAX_LENGTH)
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('date', ChronosDateTimeType::CHRONOS_DATETIME)
|
|
|
|
->columnName('`date`')
|
|
|
|
->build();
|
|
|
|
|
2020-05-03 12:15:26 -05:00
|
|
|
$builder->addIndex(['date'], 'IDX_visits_date');
|
|
|
|
|
2020-01-29 03:06:42 -06:00
|
|
|
$builder->createField('remoteAddr', Types::STRING)
|
|
|
|
->columnName('remote_addr')
|
|
|
|
->length(Visitor::REMOTE_ADDRESS_MAX_LENGTH)
|
|
|
|
->nullable()
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('userAgent', Types::STRING)
|
|
|
|
->columnName('user_agent')
|
|
|
|
->length(Visitor::USER_AGENT_MAX_LENGTH)
|
|
|
|
->nullable()
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createManyToOne('shortUrl', Entity\ShortUrl::class)
|
2021-02-07 04:26:01 -06:00
|
|
|
->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE')
|
2020-01-29 03:06:42 -06:00
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createManyToOne('visitLocation', Entity\VisitLocation::class)
|
|
|
|
->addJoinColumn('visit_location_id', 'id', true, false, 'Set NULL')
|
|
|
|
->cascadePersist()
|
|
|
|
->build();
|
2021-02-07 04:26:01 -06:00
|
|
|
|
|
|
|
$builder->createField('visitedUrl', Types::STRING)
|
|
|
|
->columnName('visited_url')
|
|
|
|
->length(Visitor::VISITED_URL_MAX_LENGTH)
|
|
|
|
->nullable()
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createField('type', Types::STRING)
|
|
|
|
->columnName('type')
|
|
|
|
->length(255)
|
|
|
|
->build();
|
2021-05-22 08:09:14 -05:00
|
|
|
|
|
|
|
$builder->createField('potentialBot', Types::BOOLEAN)
|
|
|
|
->columnName('potential_bot')
|
|
|
|
->option('default', false)
|
|
|
|
->build();
|
2020-01-29 03:06:42 -06:00
|
|
|
};
|