diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-15 13:42:13 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-08-23 16:49:21 +0200 |
commit | a7e2218e253138ed53e18b4775dce291c78246c5 (patch) | |
tree | b42d5a26987149f8372c49ef7f78a63ed81867e3 /app/DoctrineMigrations | |
parent | 222e09f140099f3b1b8f6db1846d35e6810d43a3 (diff) | |
download | wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.tar.gz wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.tar.zst wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.zip |
Add test and fix migration
Diffstat (limited to 'app/DoctrineMigrations')
-rw-r--r-- | app/DoctrineMigrations/Version20160410190541.php | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index b30a898c..775dd680 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php | |||
@@ -4,16 +4,43 @@ namespace Application\Migrations; | |||
4 | 4 | ||
5 | use Doctrine\DBAL\Migrations\AbstractMigration; | 5 | use Doctrine\DBAL\Migrations\AbstractMigration; |
6 | use Doctrine\DBAL\Schema\Schema; | 6 | use Doctrine\DBAL\Schema\Schema; |
7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
8 | use Symfony\Component\DependencyInjection\ContainerInterface; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | 10 | ||
8 | class Version20160410190541 extends AbstractMigration | 11 | class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface |
9 | { | 12 | { |
10 | /** | 13 | /** |
14 | * @var ContainerInterface | ||
15 | */ | ||
16 | private $container; | ||
17 | |||
18 | public function setContainer(ContainerInterface $container = null) | ||
19 | { | ||
20 | $this->container = $container; | ||
21 | } | ||
22 | |||
23 | /** | ||
11 | * @param Schema $schema | 24 | * @param Schema $schema |
12 | */ | 25 | */ |
13 | public function up(Schema $schema) | 26 | public function up(Schema $schema) |
14 | { | 27 | { |
15 | $this->addSql('ALTER TABLE wallabag_entry ADD uuid LONGTEXT DEFAULT NULL'); | 28 | $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); |
16 | $this->addSql('UPDATE wallabag_entry SET uuid = uuid()'); | 29 | |
30 | $em = $this->container->get('doctrine.orm.entity_manager'); | ||
31 | $queryBuilder = $this->connection->createQueryBuilder(); | ||
32 | $queryBuilder | ||
33 | ->select('e.uuid') | ||
34 | ->andWhere('e.uuid IS NULL'); | ||
35 | $entries = $queryBuilder->execute(); | ||
36 | |||
37 | /** @var Entry $entry */ | ||
38 | foreach ($entries as $entry) { | ||
39 | $entry->generateUuid(); | ||
40 | $em->persist($entry); | ||
41 | $em->clear(); | ||
42 | } | ||
43 | $em->flush(); | ||
17 | } | 44 | } |
18 | 45 | ||
19 | /** | 46 | /** |
@@ -21,6 +48,6 @@ class Version20160410190541 extends AbstractMigration | |||
21 | */ | 48 | */ |
22 | public function down(Schema $schema) | 49 | public function down(Schema $schema) |
23 | { | 50 | { |
24 | $this->addSql('ALTER TABLE `wallabag_entry` DROP uuid'); | 51 | $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); |
25 | } | 52 | } |
26 | } | 53 | } |