1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* http://www.lockon.co.jp/ |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DoctrineMigrations; |
13
|
|
|
|
14
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
15
|
|
|
use Doctrine\DBAL\Schema\Schema; |
16
|
|
|
use Doctrine\ORM\EntityManager; |
17
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
18
|
|
|
use Eccube\Common\Constant; |
19
|
|
|
|
20
|
|
|
class Version[datetime] extends AbstractMigration |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
protected $entities = array( |
|
|
|
|
23
|
|
|
[entityList] |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
public function up(Schema $schema) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
if (version_compare(Constant::VERSION, '3.0.9', '>=')) { |
29
|
|
|
// 3,0,9 以降の場合, dcm.ymlの定義からテーブル生成を行う. |
|
|
|
|
30
|
|
|
$app = \Eccube\Application::getInstance(); |
31
|
|
|
$meta = $this->getMetadata($app['orm.em']); |
32
|
|
|
$tool = new SchemaTool($app['orm.em']); |
33
|
|
|
$tool->createSchema($meta); |
34
|
|
|
} else { |
35
|
|
|
// 3.0.0 - 3.0.8 |
|
|
|
|
36
|
|
|
[createTable] |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function down(Schema $schema) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
if (version_compare(Constant::VERSION, '3.0.9', '>=')) { |
43
|
|
|
// 3,0,9 以降の場合, dcm.ymlの定義からテーブル/シーケンスの削除を行う |
|
|
|
|
44
|
|
|
$app = \Eccube\Application::getInstance(); |
45
|
|
|
$meta = $this->getMetadata($app['orm.em']); |
46
|
|
|
|
47
|
|
|
$tool = new SchemaTool($app['orm.em']); |
48
|
|
|
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta); |
49
|
|
|
|
50
|
|
|
// テーブル削除 |
51
|
|
|
foreach ($schemaFromMetadata->getTables() as $table) { |
52
|
|
|
if ($schema->hasTable($table->getName())) { |
53
|
|
|
$schema->dropTable($table->getName()); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// シーケンス削除 |
58
|
|
|
foreach ($schemaFromMetadata->getSequences() as $sequence) { |
59
|
|
|
if ($schema->hasSequence($sequence->getName())) { |
60
|
|
|
$schema->dropSequence($sequence->getName()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} else { |
64
|
|
|
// 3.0.0 - 3.0.8 |
|
|
|
|
65
|
|
|
[dropTable] |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function getMetadata(EntityManager $em) |
70
|
|
|
{ |
71
|
|
|
$meta = array(); |
72
|
|
|
foreach ($this->entities as $entity) { |
73
|
|
|
$meta[] = $em->getMetadataFactory()->getMetadataFor($entity); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $meta; |
77
|
|
|
} |
78
|
|
|
[createFunction] |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|