aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20160410190541.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/DoctrineMigrations/Version20160410190541.php')
-rw-r--r--app/DoctrineMigrations/Version20160410190541.php35
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
5use Doctrine\DBAL\Migrations\AbstractMigration; 5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema; 6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9use Wallabag\CoreBundle\Entity\Entry;
7 10
8class Version20160410190541 extends AbstractMigration 11class 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}