Completed
Push — master ( ab5f90...88258b )
by
unknown
41:27
created

UpdateEntityConfigEntityValueQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 5
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_23;
4
5
use Psr\Log\LoggerInterface;
6
7
use Doctrine\DBAL\Types\Type;
8
9
use Oro\Bundle\EntityConfigBundle\Migration\UpdateEntityConfigEntityValueQuery as BaseQuery;
10
11
class UpdateEntityConfigEntityValueQuery extends BaseQuery
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $oldValue;
17
18
    /**
19
     * {@inheritdoc}
20
     * @param string $oldValue
21
     */
22
    public function __construct($entityName, $scope, $code, $value, $oldValue)
23
    {
24
        parent::__construct($entityName, $scope, $code, $value);
25
26
        $this->oldValue = $oldValue;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function execute(LoggerInterface $logger)
33
    {
34
        if ($this->isEqualOldValue($logger)) {
35
            parent::execute($logger);
36
        }
37
    }
38
39
    /**
40
     * Checks if need to update workflow configuration
41
     *
42
     * @param LoggerInterface $logger
43
     *
44
     * @return bool
45
     */
46
    public function isEqualOldValue(LoggerInterface $logger)
47
    {
48
        $sql        = 'SELECT data FROM oro_entity_config WHERE class_name = ? LIMIT 1';
49
        $parameters = [$this->entityName];
50
        $data       = $this->connection->fetchColumn($sql, $parameters);
51
        $this->logQuery($logger, $sql, $parameters);
52
53
        $data = $data ? $this->connection->convertToPHPValue($data, Type::TARRAY) : [];
54
        if (isset($data[$this->scope][$this->code]) && $data[$this->scope][$this->code] === $this->oldValue) {
55
            return true;
56
        }
57
58
        return false;
59
    }
60
}
61