mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added isEmpty column to VisitLocation
This commit is contained in:
parent
75f77ed929
commit
c88401ef29
44
data/migrations/Version20200323190014.php
Normal file
44
data/migrations/Version20200323190014.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20200323190014 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$visitLocations = $schema->getTable('visit_locations');
|
||||||
|
$this->skipIf($visitLocations->hasColumn('is_empty'));
|
||||||
|
|
||||||
|
$visitLocations->addColumn('is_empty', Types::BOOLEAN, ['default' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$qb = $this->connection->createQueryBuilder();
|
||||||
|
$qb->update('visit_locations')
|
||||||
|
->set('is_empty', true)
|
||||||
|
->where($qb->expr()->eq('country_code', ':empty'))
|
||||||
|
->andWhere($qb->expr()->eq('country_name', ':empty'))
|
||||||
|
->andWhere($qb->expr()->eq('region_name', ':empty'))
|
||||||
|
->andWhere($qb->expr()->eq('city_name', ':empty'))
|
||||||
|
->andWhere($qb->expr()->eq('timezone', ':empty'))
|
||||||
|
->andWhere($qb->expr()->eq('lat', 0))
|
||||||
|
->andWhere($qb->expr()->eq('lon', 0))
|
||||||
|
->setParameter('empty', '')
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$visitLocations = $schema->getTable('visit_locations');
|
||||||
|
$this->skipIf(!$visitLocations->hasColumn('is_empty'));
|
||||||
|
|
||||||
|
$visitLocations->dropColumn('is_empty');
|
||||||
|
}
|
||||||
|
}
|
@ -44,4 +44,10 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
|||||||
->columnName('lon')
|
->columnName('lon')
|
||||||
->nullable(false)
|
->nullable(false)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
|
$builder->createField('isEmpty', Types::BOOLEAN)
|
||||||
|
->columnName('is_empty')
|
||||||
|
->option('default', false)
|
||||||
|
->nullable(false)
|
||||||
|
->build();
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,7 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
|||||||
private float $latitude;
|
private float $latitude;
|
||||||
private float $longitude;
|
private float $longitude;
|
||||||
private string $timezone;
|
private string $timezone;
|
||||||
|
private bool $isEmpty;
|
||||||
|
|
||||||
public function __construct(Location $location)
|
public function __construct(Location $location)
|
||||||
{
|
{
|
||||||
@ -43,6 +44,11 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
|||||||
return $this->cityName;
|
return $this->cityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isEmpty(): bool
|
||||||
|
{
|
||||||
|
return $this->isEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
private function exchangeLocationInfo(Location $info): void
|
private function exchangeLocationInfo(Location $info): void
|
||||||
{
|
{
|
||||||
$this->countryCode = $info->countryCode();
|
$this->countryCode = $info->countryCode();
|
||||||
@ -52,6 +58,15 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
|||||||
$this->latitude = $info->latitude();
|
$this->latitude = $info->latitude();
|
||||||
$this->longitude = $info->longitude();
|
$this->longitude = $info->longitude();
|
||||||
$this->timezone = $info->timeZone();
|
$this->timezone = $info->timeZone();
|
||||||
|
$this->isEmpty = (
|
||||||
|
$this->countryCode === '' &&
|
||||||
|
$this->countryName === '' &&
|
||||||
|
$this->regionName === '' &&
|
||||||
|
$this->cityName === '' &&
|
||||||
|
$this->latitude === 0.0 &&
|
||||||
|
$this->longitude === 0.0 &&
|
||||||
|
$this->timezone === ''
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array
|
public function jsonSerialize(): array
|
||||||
@ -64,18 +79,7 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
|||||||
'latitude' => $this->latitude,
|
'latitude' => $this->latitude,
|
||||||
'longitude' => $this->longitude,
|
'longitude' => $this->longitude,
|
||||||
'timezone' => $this->timezone,
|
'timezone' => $this->timezone,
|
||||||
|
'isEmpty' => $this->isEmpty,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEmpty(): bool
|
|
||||||
{
|
|
||||||
return
|
|
||||||
$this->countryCode === '' &&
|
|
||||||
$this->countryName === '' &&
|
|
||||||
$this->regionName === '' &&
|
|
||||||
$this->cityName === '' &&
|
|
||||||
$this->latitude === 0.0 &&
|
|
||||||
$this->longitude === 0.0 &&
|
|
||||||
$this->timezone === '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user