]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20160911214952.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20160911214952.php
CommitLineData
e01a3c98
JB
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
b87f1712 10/**
01736b5a 11 * Added settings for RabbitMQ and Redis imports.
b87f1712 12 */
e01a3c98
JB
13class Version20160911214952 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
e01a3c98
JB
25 /**
26 * @param Schema $schema
27 */
28 public function up(Schema $schema)
29 {
31fec5f3
JB
30 $redis = $this->container
31 ->get('doctrine.orm.default_entity_manager')
32 ->getConnection()
f808b016 33 ->fetchArray('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis'");
31fec5f3
JB
34
35 if (false === $redis) {
f808b016 36 $this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_redis', 0, 'import')");
31fec5f3
JB
37 }
38
39 $rabbitmq = $this->container
40 ->get('doctrine.orm.default_entity_manager')
41 ->getConnection()
f808b016 42 ->fetchArray('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq'");
31fec5f3
JB
43
44 if (false === $rabbitmq) {
f808b016 45 $this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_rabbitmq', 0, 'import')");
31fec5f3
JB
46 }
47
48 $this->skipIf(false !== $rabbitmq && false !== $redis, 'It seems that you already played this migration.');
e01a3c98
JB
49 }
50
51 /**
52 * @param Schema $schema
53 */
54 public function down(Schema $schema)
55 {
f808b016
JB
56 $this->addSql('DELETE FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis';");
57 $this->addSql('DELETE FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq';");
58 }
59
60 private function getTable($tableName)
61 {
62 return $this->container->getParameter('database_table_prefix') . $tableName;
e01a3c98
JB
63 }
64}