Completed
Push — feature/test-php-7-2-in-travis ( 027341...a56bae )
by
unknown
05:31
created

Version20180131150800   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
A up() 0 10 1
A down() 0 10 1
A getGatewaySchema() 0 4 1
1
<?php
2
3
namespace Surfnet\StepupMiddleware\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
/**
11
 * Update the Gateway `second_factor` table setting the primary key on the `id` and `identity_id` fields.
12
 */
13
class Version20180131150800 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
25
    /**
26
     * @param Schema $schema
27
     */
28
    public function up(Schema $schema)
29
    {
30
        // this up() migration is auto-generated, please modify it to your needs
31
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
32
33
        $gatewaySchema = $this->getGatewaySchema();
34
35
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema));
36
        $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (id, identity_id)', $gatewaySchema));
37
    }
38
39
    /**
40
     * @param Schema $schema
41
     */
42
    public function down(Schema $schema)
43
    {
44
        // this down() migration is auto-generated, please modify it to your needs
45
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
46
47
        $gatewaySchema = $this->getGatewaySchema();
48
49
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema));
50
        $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (id)', $gatewaySchema));
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    private function getGatewaySchema()
57
    {
58
        return $this->container->getParameter('database_gateway_name');
59
    }
60
}
61