]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/DoctrineMigrations/Version20160410190541.php
Add test and fix migration
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20160410190541.php
1 <?php
2
3 namespace Application\Migrations;
4
5 use Doctrine\DBAL\Migrations\AbstractMigration;
6 use Doctrine\DBAL\Schema\Schema;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9 use Wallabag\CoreBundle\Entity\Entry;
10
11 class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface
12 {
13 /**
14 * @var ContainerInterface
15 */
16 private $container;
17
18 public function setContainer(ContainerInterface $container = null)
19 {
20 $this->container = $container;
21 }
22
23 /**
24 * @param Schema $schema
25 */
26 public function up(Schema $schema)
27 {
28 $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL');
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();
44 }
45
46 /**
47 * @param Schema $schema
48 */
49 public function down(Schema $schema)
50 {
51 $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`');
52 }
53 }