|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Surfnet\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
|
|
View Code Duplication |
class Version20141209150426 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
|
|
|
public function up(Schema $schema) |
|
26
|
|
|
{ |
|
27
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
|
28
|
|
|
$middlewareUser = $this->getMiddlewareUser(); |
|
29
|
|
|
|
|
30
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
|
31
|
|
|
|
|
32
|
|
|
$this->addSql(sprintf( |
|
33
|
|
|
'CREATE TABLE %s.second_factor (identity_id VARCHAR(36) NOT NULL, name_id VARCHAR(200) NOT NULL, institution VARCHAR(200) NOT NULL, second_factor_id VARCHAR(36) NOT NULL, second_factor_type VARCHAR(50) NOT NULL, second_factor_identifier VARCHAR(100) NOT NULL, INDEX idx_secondfactor_nameid (name_id), PRIMARY KEY(identity_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
|
34
|
|
|
$gatewaySchema |
|
35
|
|
|
)); |
|
36
|
|
|
$this->addSql(sprintf( |
|
37
|
|
|
'GRANT DELETE,INSERT,SELECT,UPDATE ON %s.second_factor TO %s', |
|
38
|
|
|
$gatewaySchema, |
|
39
|
|
|
$middlewareUser |
|
40
|
|
|
)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function down(Schema $schema) |
|
44
|
|
|
{ |
|
45
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
|
46
|
|
|
$middlewareUser = $this->getMiddlewareUser(); |
|
47
|
|
|
|
|
48
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
|
49
|
|
|
|
|
50
|
|
|
$this->addSql(sprintf( |
|
51
|
|
|
'REVOKE DELETE,INSERT,SELECT,UPDATE ON %s.second_factor FROM %s', |
|
52
|
|
|
$gatewaySchema, |
|
53
|
|
|
$middlewareUser |
|
54
|
|
|
)); |
|
55
|
|
|
$this->addSql('DROP TABLE second_factor'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function getGatewaySchema() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->container->getParameter('database_gateway_name'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function getMiddlewareUser() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->container->getParameter('database_middleware_user'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
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.