mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
php-cs-fixer on DoctrineMigrations/Version20170719231144
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
parent
e437ad810b
commit
7b4f66881d
1 changed files with 24 additions and 24 deletions
|
@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changed tags to lowercase
|
* Changed tags to lowercase.
|
||||||
*/
|
*/
|
||||||
class Version20170719231144 extends AbstractMigration implements ContainerAwareInterface
|
class Version20170719231144 extends AbstractMigration implements ContainerAwareInterface
|
||||||
{
|
{
|
||||||
|
@ -22,24 +22,19 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTable($tableName)
|
|
||||||
{
|
|
||||||
return $this->container->getParameter('database_table_prefix').$tableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Schema $schema
|
* @param Schema $schema
|
||||||
*/
|
*/
|
||||||
public function up(Schema $schema)
|
public function up(Schema $schema)
|
||||||
{
|
{
|
||||||
$this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
|
$this->skipIf($this->connection->getDatabasePlatform()->getName() === 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
|
||||||
|
|
||||||
// Find tags which need to be merged
|
// Find tags which need to be merged
|
||||||
$dupTags = $this->connection->query("
|
$dupTags = $this->connection->query('
|
||||||
SELECT LOWER(label)
|
SELECT LOWER(label)
|
||||||
FROM ".$this->getTable('tag')."
|
FROM ' . $this->getTable('tag') . '
|
||||||
GROUP BY LOWER(label)
|
GROUP BY LOWER(label)
|
||||||
HAVING COUNT(*) > 1"
|
HAVING COUNT(*) > 1'
|
||||||
);
|
);
|
||||||
$dupTags->execute();
|
$dupTags->execute();
|
||||||
|
|
||||||
|
@ -47,10 +42,10 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
$label = $duplicates['LOWER(label)'];
|
$label = $duplicates['LOWER(label)'];
|
||||||
|
|
||||||
// Retrieve all duplicate tags for a given tag
|
// Retrieve all duplicate tags for a given tag
|
||||||
$tags = $this->connection->query("
|
$tags = $this->connection->query('
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM ".$this->getTable('tag')."
|
FROM ' . $this->getTable('tag') . "
|
||||||
WHERE LOWER(label) = '".$label."'
|
WHERE LOWER(label) = '" . $label . "'
|
||||||
ORDER BY id ASC"
|
ORDER BY id ASC"
|
||||||
);
|
);
|
||||||
$tags->execute();
|
$tags->execute();
|
||||||
|
@ -72,24 +67,24 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
// Just in case...
|
// Just in case...
|
||||||
if (count($ids) > 0) {
|
if (count($ids) > 0) {
|
||||||
// Merge tags
|
// Merge tags
|
||||||
$this->addSql("
|
$this->addSql('
|
||||||
UPDATE ".$this->getTable('entry_tag')."
|
UPDATE ' . $this->getTable('entry_tag') . '
|
||||||
SET tag_id = ".$newId."
|
SET tag_id = ' . $newId . '
|
||||||
WHERE tag_id IN (".implode(',', $ids).")"
|
WHERE tag_id IN (' . implode(',', $ids) . ')'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete unused tags
|
// Delete unused tags
|
||||||
$this->addSql("
|
$this->addSql('
|
||||||
DELETE FROM ".$this->getTable('tag')."
|
DELETE FROM ' . $this->getTable('tag') . '
|
||||||
WHERE id IN (".implode(',', $ids).")"
|
WHERE id IN (' . implode(',', $ids) . ')'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over all tags to lowercase them
|
// Iterate over all tags to lowercase them
|
||||||
$this->addSql("
|
$this->addSql('
|
||||||
UPDATE ".$this->getTable('tag')."
|
UPDATE ' . $this->getTable('tag') . '
|
||||||
SET label = LOWER(label)"
|
SET label = LOWER(label)'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,4 +95,9 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
{
|
{
|
||||||
throw new SkipMigrationException('Too complex ...');
|
throw new SkipMigrationException('Too complex ...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTable($tableName)
|
||||||
|
{
|
||||||
|
return $this->container->getParameter('database_table_prefix') . $tableName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue