Completed
Pull Request — master (#1912)
by chihiro
35:08
created

Version20161108095350::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
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
10
/**
11
 * Auto-generated Migration: Please modify to your needs!
12
 */
13
class Version20161108095350 extends AbstractMigration
14
{
15
    /**
16
     * @param Schema $schema
17
     */
18
    public function up(Schema $schema)
19
    {
20
        $app = Application::getInstance();
21
        $repository = $app['orm.em']->getRepository('Eccube\Entity\Master\ProductListOrderBy');
22
23
        // 価格が高い順ソートの追加
24
        $ProductListOrderBy = $repository->find(3);
25
        if (is_null($ProductListOrderBy)) {
26
            $rank = $repository->createQueryBuilder('pl')
27
                ->select('MAX(pl.rank)')
28
                ->getQuery()
29
                ->getSingleScalarResult();
30
            $ProductListOrderBy = new ProductListOrderBy();
31
            $ProductListOrderBy->setId(3);
32
            $ProductListOrderBy->setName('価格が高い順');
33
            $ProductListOrderBy->setRank($rank + 1);
34
            $app['orm.em']->persist($ProductListOrderBy);
35
            $app['orm.em']->flush($ProductListOrderBy);
36
        }
37
38
        // "価格順"の名称を"価格が低い順"へ変更
39
        $ProductListOrderBy = $repository->find(1);
40
        if (!is_null($ProductListOrderBy) && $ProductListOrderBy->getName() === '価格順') {
41
            $ProductListOrderBy->setName('価格が低い順');
42
            $app['orm.em']->persist($ProductListOrderBy);
43
            $app['orm.em']->flush($ProductListOrderBy);
44
        }
45
    }
46
47
    /**
48
     * @param Schema $schema
49
     */
50
    public function down(Schema $schema)
51
    {
52
        // this down() migration is auto-generated, please modify it to your needs
53
54
    }
55
}
56