|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoctrineMigrations; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
|
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
7
|
|
|
use Eccube\Application; |
|
8
|
|
|
use Eccube\Entity\Master\ProductListOrderBy; |
|
9
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
10
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
14
|
|
|
*/ |
|
15
|
|
|
class Version20161108095350 extends AbstractMigration |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param Schema $schema |
|
19
|
|
|
*/ |
|
20
|
|
|
public function up(Schema $schema) |
|
21
|
|
|
{ |
|
22
|
|
|
$app = Application::getInstance(); |
|
23
|
|
|
$repository = $app['orm.em']->getRepository('Eccube\Entity\Master\ProductListOrderBy'); |
|
24
|
|
|
|
|
25
|
|
|
// mtb_product_list_orderbyが初期状態から変更がある場合は、マイグレーションを適用しない |
|
26
|
|
|
$default = array( |
|
27
|
|
|
array( |
|
28
|
|
|
'id' => 1, |
|
29
|
|
|
'name' => '価格順', |
|
30
|
|
|
'rank' => 0, |
|
31
|
|
|
), |
|
32
|
|
|
array( |
|
33
|
|
|
'id' => 2, |
|
34
|
|
|
'name' => '新着順', |
|
35
|
|
|
'rank' => 1, |
|
36
|
|
|
), |
|
37
|
|
|
); |
|
38
|
|
|
$entities = $repository->createQueryBuilder('pl') |
|
39
|
|
|
->orderBy('pl.id', 'ASC') |
|
40
|
|
|
->getQuery() |
|
41
|
|
|
->getArrayResult(); |
|
42
|
|
|
|
|
43
|
|
|
if ($entities !== $default) { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// 価格が高い順を追加 |
|
48
|
|
|
$ProductListOrderBy = new ProductListOrderBy(); |
|
49
|
|
|
$ProductListOrderBy->setId(3); |
|
50
|
|
|
$ProductListOrderBy->setName('価格が高い順'); |
|
51
|
|
|
$ProductListOrderBy->setRank(2); |
|
52
|
|
|
$app['orm.em']->persist($ProductListOrderBy); |
|
53
|
|
|
$app['orm.em']->flush($ProductListOrderBy); |
|
54
|
|
|
|
|
55
|
|
|
// "価格順"の名称を"価格が低い順"へ変更 |
|
56
|
|
|
$ProductListOrderBy = $repository->find(1); |
|
57
|
|
|
if (!is_null($ProductListOrderBy) && $ProductListOrderBy->getName() === '価格順') { |
|
58
|
|
|
$ProductListOrderBy->setName('価格が低い順'); |
|
59
|
|
|
$app['orm.em']->persist($ProductListOrderBy); |
|
60
|
|
|
$app['orm.em']->flush($ProductListOrderBy); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// 価格が低い順->価格が高い順->新着順の順にrankを振り直す |
|
64
|
|
|
// 価格が低い順 |
|
65
|
|
|
$entity = $repository->find(1); |
|
66
|
|
|
$entity->setRank(0); |
|
67
|
|
|
$app['orm.em']->flush($entity); |
|
68
|
|
|
|
|
69
|
|
|
// 価格が高い順 |
|
70
|
|
|
$entity = $repository->find(3); |
|
71
|
|
|
$entity->setRank(1); |
|
72
|
|
|
$app['orm.em']->flush($entity); |
|
73
|
|
|
|
|
74
|
|
|
// 新着順 |
|
75
|
|
|
$entity = $repository->find(2); |
|
76
|
|
|
$entity->setRank(2); |
|
77
|
|
|
$app['orm.em']->flush($entity); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param Schema $schema |
|
82
|
|
|
*/ |
|
83
|
|
|
public function down(Schema $schema) |
|
84
|
|
|
{ |
|
85
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|