aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/DoctrineMigrations/Version20160410190541.php16
1 files changed, 7 insertions, 9 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php
index 775dd680..f35f54ce 100644
--- a/app/DoctrineMigrations/Version20160410190541.php
+++ b/app/DoctrineMigrations/Version20160410190541.php
@@ -26,21 +26,18 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
26 public function up(Schema $schema) 26 public function up(Schema $schema)
27 { 27 {
28 $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); 28 $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL');
29 }
29 30
31 public function postUp(Schema $schema)
32 {
30 $em = $this->container->get('doctrine.orm.entity_manager'); 33 $em = $this->container->get('doctrine.orm.entity_manager');
31 $queryBuilder = $this->connection->createQueryBuilder(); 34 $repository = $em->getRepository('WallabagCoreBundle:Entry');
32 $queryBuilder 35 $entries = $repository->findAll();
33 ->select('e.uuid')
34 ->andWhere('e.uuid IS NULL');
35 $entries = $queryBuilder->execute();
36 36
37 /** @var Entry $entry */ 37 /** @var Entry $entry */
38 foreach ($entries as $entry) { 38 foreach ($entries as $entry) {
39 $entry->generateUuid(); 39 $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId());
40 $em->persist($entry);
41 $em->clear();
42 } 40 }
43 $em->flush();
44 } 41 }
45 42
46 /** 43 /**
@@ -48,6 +45,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
48 */ 45 */
49 public function down(Schema $schema) 46 public function down(Schema $schema)
50 { 47 {
48 $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
51 $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); 49 $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`');
52 } 50 }
53} 51}