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

Version20141125173004::getGatewaySchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\Migrations;
20
21
use Doctrine\DBAL\Migrations\AbstractMigration;
22
use Doctrine\DBAL\Schema\Schema;
23
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
24
use Symfony\Component\DependencyInjection\ContainerInterface;
25
26
/**
27
 * Auto-generated Migration: Please modify to your needs!
28
 */
29 View Code Duplication
class Version20141125173004 extends AbstractMigration implements ContainerAwareInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
{
31
    /**
32
     * @var ContainerInterface
33
     */
34
    private $container;
35
36
    public function setContainer(ContainerInterface $container = null)
37
    {
38
        $this->container = $container;
39
    }
40
41
    public function up(Schema $schema)
42
    {
43
        $gatewaySchema = $this->getGatewaySchema();
44
        $middlewareUser = $this->getMiddlewareUser();
45
46
        // this up() migration is auto-generated, please modify it to your needs
47
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
48
49
        $this->addSql(sprintf('CREATE TABLE %s.saml_entity (entity_id VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, configuration LONGTEXT NOT NULL, PRIMARY KEY(entity_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', $gatewaySchema));
50
        $this->addSql(sprintf("GRANT DELETE,INSERT,SELECT,UPDATE ON %s.saml_entity TO %s", $gatewaySchema, $middlewareUser));
51
    }
52
53
    public function down(Schema $schema)
54
    {
55
        $gatewaySchema  = $this->getGatewaySchema();
56
        $middlewareUser = $this->getMiddlewareUser();
57
58
        // this down() migration is auto-generated, please modify it to your needs
59
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
60
61
        $this->addSql(sprintf("REVOKE DELETE,INSERT,SELECT,UPDATE ON %s.saml_entity FROM %s", $gatewaySchema, $middlewareUser));
62
        $this->addSql(sprintf('DROP TABLE %s.saml_entity', $gatewaySchema));
63
    }
64
65
    private function getGatewaySchema()
66
    {
67
        return $this->container->getParameter('database_gateway_name');
68
    }
69
70
    private function getMiddlewareUser()
71
    {
72
        return $this->container->getParameter('database_middleware_user');
73
    }
74
}
75