|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DoctrineMigrations; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
11
|
|
|
use App\Service\GpxService; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
15
|
|
|
*/ |
|
16
|
|
|
final class Version20211213220450 extends AbstractMigration implements ContainerAwareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var ContainerInterface */ |
|
19
|
|
|
private $container; |
|
20
|
|
|
|
|
21
|
|
|
public function getDescription(): string |
|
22
|
|
|
{ |
|
23
|
|
|
return ''; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function setContainer(?ContainerInterface $container = null): void |
|
27
|
|
|
{ |
|
28
|
|
|
if ($container === null) { |
|
29
|
|
|
throw new \Exception("Wasn't given a container in this container-aware migration"); |
|
30
|
|
|
} |
|
31
|
|
|
$this->container = $container; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function up(Schema $schema): void |
|
35
|
|
|
{ |
|
36
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
37
|
|
|
$this->addSql('ALTER TABLE wander ADD google_polyline LONGTEXT DEFAULT NULL'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function down(Schema $schema): void |
|
41
|
|
|
{ |
|
42
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
43
|
|
|
$this->addSql('ALTER TABLE wander DROP google_polyline'); |
|
44
|
|
|
} |
|
45
|
|
|
public function postUp(Schema $schema): void |
|
46
|
|
|
{ |
|
47
|
|
|
if ($this->container == null) { |
|
48
|
|
|
throw new \Exception('No container available in container-aware migration'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** @var GpxService */ |
|
52
|
|
|
$gpxService = $this->container->get('App\Service\GpxService'); |
|
53
|
|
|
|
|
54
|
|
|
$updateGeoJsonStatement = $this->connection->prepare('UPDATE wander SET google_polyline = (:google_polyline) WHERE id = :id'); |
|
55
|
|
|
|
|
56
|
|
|
$wanders = $this->connection->fetchAllAssociative('SELECT id, gpx_filename FROM wander WHERE gpx_filename IS NOT NULL'); |
|
57
|
|
|
foreach ($wanders as $wander) { |
|
58
|
|
|
$googlePolyline = $gpxService->gpxToGooglePolyline($gpxService->getGpxStringFromFilename($wander['gpx_filename'])); |
|
59
|
|
|
$updateGeoJsonStatement->bindValue('id', $wander['id']); |
|
60
|
|
|
$updateGeoJsonStatement->bindValue('google_polyline', $googlePolyline); |
|
61
|
|
|
$updateGeoJsonStatement->executeStatement(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|