Passed
Push — master ( 3ad356...ec22f8 )
by Julito
34:02
created

Version20191208160020::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 1
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20191208160020 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'ExtraFieldSavedSearch changes';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $connection = $this->getEntityManager()->getConnection();
22
23
        // Delete empty values.
24
        $this->addSql(sprintf("UPDATE extra_field_saved_search SET value = NULL WHERE value = '%s'", 's:0:"";'));
25
26
        $sql = "SELECT id, value FROM extra_field_saved_search WHERE value LIKE 's:%'";
27
        $result = $connection->executeQuery($sql);
28
        $items = $result->fetchAllAssociative();
29
30
        foreach ($items as $item) {
31
            $id = $item['id'];
32
            $value = 'a:1:{'.$item['value'].'}';
33
            $sql = sprintf("UPDATE extra_field_saved_search SET value = '%s' WHERE id = %s", $value, $id);
34
            $connection->executeQuery($sql);
35
        }
36
    }
37
}
38