|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SWP\Migrations; |
|
6
|
|
|
|
|
7
|
|
|
use Behat\Transliterator\Transliterator; |
|
8
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
|
9
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
10
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleAuthor; |
|
11
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleAuthorInterface; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
17
|
|
|
*/ |
|
18
|
|
|
final class Version20180605111249 extends AbstractMigration implements ContainerAwareInterface |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ContainerInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $container; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param ContainerInterface|null $container |
|
27
|
|
|
*/ |
|
28
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->container = $container; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function up(Schema $schema): void |
|
34
|
|
|
{ |
|
35
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
36
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param Schema $schema |
|
41
|
|
|
*/ |
|
42
|
|
View Code Duplication |
public function postUp(Schema $schema) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$entityManager = $this->container->get('doctrine.orm.default_entity_manager'); |
|
45
|
|
|
$query = $entityManager |
|
46
|
|
|
->createQuery('SELECT au.id, au.name FROM SWP\Bundle\ContentBundle\Model\ArticleAuthor AS au WHERE au.slug IS NULL'); |
|
47
|
|
|
$articleAuthors = $query->getArrayResult(); |
|
48
|
|
|
|
|
49
|
|
|
/** @var ArticleAuthorInterface $articleAuthor */ |
|
50
|
|
|
foreach ((array) $articleAuthors as $articleAuthor) { |
|
51
|
|
|
$qb = $entityManager->createQueryBuilder(); |
|
52
|
|
|
$query = $qb->update(ArticleAuthor::class, 'au') |
|
53
|
|
|
->set('au.slug', '?1') |
|
54
|
|
|
->where('au.id = ?2') |
|
55
|
|
|
->setParameter(1, Transliterator::transliterate($articleAuthor['name'])) |
|
56
|
|
|
->setParameter(2, $articleAuthor['id']) |
|
57
|
|
|
->getQuery(); |
|
58
|
|
|
|
|
59
|
|
|
$query->execute(); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function down(Schema $schema): void |
|
64
|
|
|
{ |
|
65
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
66
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.