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
|
|
|
* Auto-generated Migration: Please modify to your needs! |
12
|
|
|
*/ |
13
|
|
|
class Version20150615114646 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
|
|
View Code Duplication |
public function up(Schema $schema) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
28
|
|
|
$middlewareSchema = $this->getMiddlewareSchema(); |
29
|
|
|
$middlewareUser = $this->getMiddlewareUser(); |
30
|
|
|
|
31
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
32
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
33
|
|
|
|
34
|
|
|
$this->addSql(sprintf( |
35
|
|
|
'CREATE TABLE %s.whitelist_entry (institution VARCHAR(255) NOT NULL, PRIMARY KEY(institution)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
36
|
|
|
$middlewareSchema |
37
|
|
|
)); |
38
|
|
|
$this->addSql(sprintf( |
39
|
|
|
'CREATE TABLE %s.whitelist_entry (institution VARCHAR(255) NOT NULL, PRIMARY KEY(institution)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
40
|
|
|
$gatewaySchema |
41
|
|
|
)); |
42
|
|
|
$this->addSql(sprintf( |
43
|
|
|
'GRANT DELETE,INSERT,SELECT,UPDATE ON %s.whitelist_entry TO %s', |
44
|
|
|
$gatewaySchema, |
45
|
|
|
$middlewareUser |
46
|
|
|
)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function down(Schema $schema) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
52
|
|
|
$middlewareSchema = $this->getMiddlewareSchema(); |
53
|
|
|
$middlewareUser = $this->getMiddlewareUser(); |
54
|
|
|
|
55
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
56
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
57
|
|
|
|
58
|
|
|
$this->addSql(sprintf( |
59
|
|
|
'REVOKE DELETE,INSERT,SELECT,UPDATE ON %s.whitelist_entry FROM %s', |
60
|
|
|
$gatewaySchema, |
61
|
|
|
$middlewareUser |
62
|
|
|
)); |
63
|
|
|
$this->addSql(sprintf('DROP TABLE %s.saml_entity', $middlewareSchema)); |
64
|
|
|
$this->addSql(sprintf('DROP TABLE %s.saml_entity', $gatewaySchema)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function getGatewaySchema() |
68
|
|
|
{ |
69
|
|
|
return $this->container->getParameter('database_gateway_name'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function getMiddlewareUser() |
73
|
|
|
{ |
74
|
|
|
return $this->container->getParameter('database_middleware_user'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function getMiddlewareSchema() |
78
|
|
|
{ |
79
|
|
|
return $this->container->getParameter('database_middleware_name'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.