Completed
Push — feature/EVO-8576-translatable-... ( 0b6c3e )
by
unknown
10:40
created

Version20161122111410::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 1
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Index migration
4
 */
5
6
namespace Graviton\I18nBundle\Migrations\MongoDB;
7
8
use AntiMattr\MongoDB\Migrations\AbstractMigration;
9
use Doctrine\MongoDB\Database;
10
use Graviton\I18nBundle\Document\Translatable;
11
use MongoDB;
12
use MongoCollection;
13
14
/**
15
 * Migrate domain_1_locale_1_original_1 index
16
 *
17
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
18
 * @license  http://opensource.org/licenses/MIT MIT License
19
 * @link     http://swisscom.ch
20
 */
21
class Version20161122111410 extends AbstractMigration
22
{
23
    /**
24
     * @var string
25
     */
26
    private $collection = 'Translatable';
27
28
    /**
29
     * @return string
30
     */
31
    public function getDescription()
32
    {
33
        return 'Build id for the new sha1 implementation';
34
    }
35
36
    /**
37
     * recreate index without unique flag
38
     *
39
     * @param Database $db database to migrate
40
     *
41
     * @return void
42
     */
43
    public function up(Database $db)
44
    {
45
        $collection = $db->createCollection($this->collection);
46
        $qb = $collection->createQueryBuilder();
47
        /** @var Translatable $translatable */
48
        foreach ($qb->find() as $translatable) {
49
            $id = $translatable->getId();
50
            $collection->update(
51
                ['id' => $id],
52
                ['id' => sha1($id)]
53
            );
54
        }
55
    }
56
57
    /**
58
     * re-add unique flag to index
59
     *
60
     * @param Database $db database to migrate
61
     *
62
     * @return void
63
     */
64
    public function down(Database $db)
65
    {
66
    }
67
}
68