1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SWP\Migrations; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
7
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Auto-generated Migration: Please modify to your needs! |
13
|
|
|
*/ |
14
|
|
|
class Version20170221140709 extends AbstractMigration implements ContainerAwareInterface |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var ContainerInterface |
18
|
|
|
*/ |
19
|
|
|
private $container; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param ContainerInterface|null $container |
23
|
|
|
*/ |
24
|
|
|
public function setContainer(ContainerInterface $container = null) |
25
|
|
|
{ |
26
|
|
|
$this->container = $container; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Schema $schema |
31
|
|
|
*/ |
32
|
|
|
public function up(Schema $schema) |
33
|
|
|
{ |
34
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
35
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
36
|
|
|
|
37
|
|
|
$query = $this->container->get('doctrine.orm.default_entity_manager') |
38
|
|
|
->createQuery('SELECT t FROM SWP\Bundle\CoreBundle\Model\Tenant t'); |
39
|
|
|
$tenants = $query->getResult(); |
40
|
|
|
$containerRepository = $this->container->get('swp.repository.container'); |
41
|
|
|
$revisionRepository = $this->container->get('swp.repository.revision'); |
42
|
|
|
foreach ($tenants as $tenant) { |
43
|
|
|
$criteria = new Criteria(); |
44
|
|
|
$criteria->set('revision', null); |
45
|
|
|
$criteria->set('tenantCode', $tenant->getCode()); |
46
|
|
|
$containersWithoutRevision = $containerRepository->getQueryByCriteria($criteria, [], 'c') |
47
|
|
|
->getQuery() |
48
|
|
|
->getResult(); |
49
|
|
|
|
50
|
|
|
$tenantPublishedRevision = $revisionRepository->getPublishedRevision() |
51
|
|
|
->andWhere('r.tenantCode = :tenantCode') |
52
|
|
|
->setParameter('tenantCode', $tenant->getCode()) |
53
|
|
|
->getQuery() |
54
|
|
|
->getOneOrNullResult(); |
55
|
|
|
|
56
|
|
|
if (null === $tenantPublishedRevision) { |
57
|
|
|
continue; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
foreach ($containersWithoutRevision as $container) { |
61
|
|
|
$container->setRevision($tenantPublishedRevision); |
62
|
|
|
} |
63
|
|
|
$this->container->get('doctrine')->getManager()->flush(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Schema $schema |
69
|
|
|
*/ |
70
|
|
|
public function down(Schema $schema) |
71
|
|
|
{ |
72
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
73
|
|
|
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.