failed updates won't clear database anymore
This commit is contained in:
parent
9373d70422
commit
60fe5c1acd
@ -5,6 +5,7 @@ namespace App\Entity;
|
||||
use App\Model\Fillable;
|
||||
use App\Model\FillTrait;
|
||||
use App\Model\Referable;
|
||||
use Carbon\Carbon;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
@ -29,6 +30,21 @@ class ProviderEntity implements Fillable, Referable
|
||||
*/
|
||||
private $class;
|
||||
|
||||
/**
|
||||
* Time and date of last data update
|
||||
*
|
||||
* @ORM\Column(type="datetime", nullable=false)
|
||||
*/
|
||||
private $updateDate;
|
||||
|
||||
/**
|
||||
* ProviderEntity constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->updateDate = Carbon::now();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
@ -48,4 +64,12 @@ class ProviderEntity implements Fillable, Referable
|
||||
{
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getUpdateDate()
|
||||
{
|
||||
return Carbon::instance($this->updateDate);
|
||||
}
|
||||
}
|
36
src/Migrations/Version20181027124203.php
Normal file
36
src/Migrations/Version20181027124203.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20181027124203 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', 'Migration can only be executed safely on \'sqlite\'.');
|
||||
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__provider AS SELECT id, name, class FROM provider');
|
||||
$this->addSql('DROP TABLE provider');
|
||||
$this->addSql('CREATE TABLE provider (id VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, class VARCHAR(255) NOT NULL, update_date DATETIME NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY(id))');
|
||||
$this->addSql('INSERT INTO provider (id, name, class) SELECT id, name, class FROM __temp__provider');
|
||||
$this->addSql('DROP TABLE __temp__provider');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', 'Migration can only be executed safely on \'sqlite\'.');
|
||||
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__provider AS SELECT id, name, class FROM provider');
|
||||
$this->addSql('DROP TABLE provider');
|
||||
$this->addSql('CREATE TABLE provider (id VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, class VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql('INSERT INTO provider (id, name, class) SELECT id, name, class FROM __temp__provider');
|
||||
$this->addSql('DROP TABLE __temp__provider');
|
||||
}
|
||||
}
|
@ -23,9 +23,13 @@ trait FillTrait
|
||||
|
||||
public static function createFromArray(array $vars = [], ...$args)
|
||||
{
|
||||
$object = empty($args)
|
||||
? (new \ReflectionClass(static::class))->newInstanceWithoutConstructor()
|
||||
: new static(...$args);
|
||||
$reflection = new \ReflectionClass(static::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
|
||||
|
||||
$object = empty($args) && ($constructor && $constructor->getNumberOfRequiredParameters() > 0)
|
||||
? $reflection->newInstanceWithoutConstructor()
|
||||
: $reflection->newInstanceArgs($args);
|
||||
|
||||
$object->fill($vars);
|
||||
|
||||
|
@ -9,6 +9,7 @@ use App\Provider\MessageRepository;
|
||||
use App\Provider\Provider;
|
||||
use App\Provider\StopRepository;
|
||||
use App\Provider\TrackRepository;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DummyProvider implements Provider
|
||||
{
|
||||
@ -70,4 +71,9 @@ class DummyProvider implements Provider
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getLastUpdate(): ?Carbon
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Provider;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
interface Provider
|
||||
{
|
||||
public function getDepartureRepository(): DepartureRepository;
|
||||
@ -14,4 +16,6 @@ interface Provider
|
||||
public function getShortName(): string;
|
||||
public function getIdentifier(): string;
|
||||
public function getAttribution(): ?string;
|
||||
|
||||
public function getLastUpdate(): ?Carbon;
|
||||
}
|
@ -15,6 +15,7 @@ use App\Provider\StopRepository;
|
||||
use App\Provider\TrackRepository;
|
||||
use App\Provider\ZtmGdansk\{ZtmGdanskDepartureRepository, ZtmGdanskMessageRepository};
|
||||
use App\Service\Proxy\ReferenceFactory;
|
||||
use Carbon\Carbon;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class ZtmGdanskProvider implements Provider
|
||||
@ -25,6 +26,9 @@ class ZtmGdanskProvider implements Provider
|
||||
private $tracks;
|
||||
private $messages;
|
||||
|
||||
/** @var ProviderEntity */
|
||||
private $entity;
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'MZKZG - Trójmiasto';
|
||||
@ -64,6 +68,7 @@ class ZtmGdanskProvider implements Provider
|
||||
$this->stops = $stops;
|
||||
$this->messages = $messages;
|
||||
$this->tracks = $tracks;
|
||||
$this->entity = $provider;
|
||||
}
|
||||
|
||||
public function getDepartureRepository(): DepartureRepository
|
||||
@ -90,4 +95,9 @@ class ZtmGdanskProvider implements Provider
|
||||
{
|
||||
return $this->tracks;
|
||||
}
|
||||
|
||||
public function getLastUpdate(): ?Carbon
|
||||
{
|
||||
return $this->entity->getUpdateDate();
|
||||
}
|
||||
}
|
@ -30,11 +30,21 @@ class DataUpdater
|
||||
|
||||
public function update()
|
||||
{
|
||||
$schema = $this->em->getConnection()->getSchemaManager();
|
||||
collect($schema->listTables())->reject(function (Table $schema) {
|
||||
return $schema->getName() === 'migration_versions';
|
||||
})->each([$schema, 'dropAndCreateTable']);
|
||||
$connection = $this->em->getConnection();
|
||||
$schema = $connection->getSchemaManager();
|
||||
|
||||
$this->dispatcher->dispatch(self::UPDATE_EVENT, new DataUpdateEvent());
|
||||
try {
|
||||
$connection->beginTransaction();
|
||||
|
||||
collect($schema->listTables())->reject(function (Table $schema) {
|
||||
return $schema->getName() === 'migration_versions';
|
||||
})->each([$schema, 'dropAndCreateTable']);
|
||||
|
||||
$this->dispatcher->dispatch(self::UPDATE_EVENT, new DataUpdateEvent());
|
||||
$connection->commit();
|
||||
} catch (\Throwable $exception) {
|
||||
$connection->rollBack();
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,13 @@
|
||||
<fa :icon="['fal', 'info-circle']"></fa>
|
||||
Wybierz źródło danych
|
||||
</div>
|
||||
{% for provider in providers %}
|
||||
<a href="{{ path('app', { provider: provider.identifier }) }}">{{ provider.name }}</a>
|
||||
{% endfor %}
|
||||
<ul class="list-underlined">
|
||||
{% for provider in providers %}
|
||||
<li title="Aktualizacja: {{ provider.lastUpdate ? provider.lastUpdate.format('Y.m.d H:i') : 'live' }}">
|
||||
<a href="{{ path('app', { provider: provider.identifier }) }}" class="btn btn-block btn-action text-left">
|
||||
{{ provider.name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user