3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
8 use Symfony\Component\DependencyInjection\ContainerInterface
;
11 * Changed tags to lowercase
13 class Version20170719231144
extends AbstractMigration
implements ContainerAwareInterface
16 * @var ContainerInterface
20 public function setContainer(ContainerInterface
$container = null)
22 $this->container
= $container;
25 private function getTable($tableName)
27 return $this->container
->getParameter('database_table_prefix').$tableName;
31 * @param Schema $schema
33 public function up(Schema
$schema)
35 $this->skipIf($this->connection
->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
37 // Find tags which need to be merged
38 $dupTags = $this->connection
->query("
40 FROM ".$this->getTable('tag')."
46 foreach ($dupTags->fetchAll() as $duplicates) {
47 $label = $duplicates['LOWER(label)'];
49 // Retrieve all duplicate tags for a given tag
50 $tags = $this->connection
->query("
52 FROM ".$this->getTable('tag')."
53 WHERE LOWER(label) = '".$label."'
62 foreach ($tags->fetchAll() as $tag) {
63 // Ignore the first tag as we use it as the new reference tag
73 if (count($ids) > 0) {
76 UPDATE ".$this->getTable('entry_tag')."
77 SET tag_id = ".$newId."
78 WHERE tag_id IN (".implode(',', $ids).")"
83 DELETE FROM ".$this->getTable('tag')."
84 WHERE id IN (".implode(',', $ids).")"
89 // Iterate over all tags to lowercase them
91 UPDATE ".$this->getTable('tag')."
92 SET label = LOWER(label)"
97 * @param Schema $schema
99 public function down(Schema
$schema)
101 throw new SkipMigrationException('Too complex ...');