1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ActivityContactBundle\Migrations\Schema\v1_0; |
4
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Types\Type; |
8
|
|
|
|
9
|
|
|
use Oro\Bundle\MigrationBundle\Migration\ArrayLogger; |
10
|
|
|
use Oro\Bundle\MigrationBundle\Migration\ParametrizedMigrationQuery; |
11
|
|
|
|
12
|
|
|
use OroCRM\Bundle\ActivityContactBundle\EntityConfig\ActivityScope; |
13
|
|
|
|
14
|
|
|
class UpdateConfigQuery extends ParametrizedMigrationQuery |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritDoc} |
18
|
|
|
*/ |
19
|
|
|
public function getDescription() |
20
|
|
|
{ |
21
|
|
|
$logger = new ArrayLogger(); |
22
|
|
|
$this->doExecute($logger, true); |
23
|
|
|
|
24
|
|
|
return $logger->getMessages(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
*/ |
30
|
|
|
public function execute(LoggerInterface $logger) |
31
|
|
|
{ |
32
|
|
|
$this->doExecute($logger); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param LoggerInterface $logger |
37
|
|
|
* @param bool $dryRun |
38
|
|
|
* |
39
|
|
|
* @throws \Doctrine\DBAL\DBALException |
40
|
|
|
*/ |
41
|
|
|
protected function doExecute(LoggerInterface $logger, $dryRun = false) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$className = 'Oro\Bundle\UserBundle\Entity\User'; |
44
|
|
|
if ($className) { |
45
|
|
|
$sql = 'SELECT e.data FROM oro_entity_config as e WHERE e.class_name = ? LIMIT 1'; |
46
|
|
|
$entityRow = $this->connection->fetchAssoc($sql, [$className]); |
47
|
|
|
if ($entityRow) { |
|
|
|
|
48
|
|
|
$this->updateEntityData($className, $entityRow['data'], $logger); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $className |
55
|
|
|
* @param string $data |
56
|
|
|
* @param LoggerInterface $logger |
57
|
|
|
*/ |
58
|
|
|
protected function updateEntityData($className, $data, $logger) |
59
|
|
|
{ |
60
|
|
|
$data = $data ? $this->connection->convertToPHPValue($data, Type::TARRAY) : []; |
61
|
|
|
|
62
|
|
|
foreach (array_keys(ActivityScope::$fieldsConfiguration) as $fieldName) { |
63
|
|
|
if (isset($data['extend']['schema']['property'][$fieldName])) { |
64
|
|
|
unset($data['extend']['schema']['property'][$fieldName]); |
65
|
|
|
} |
66
|
|
|
$entityName = $data['extend']['schema']['entity']; |
67
|
|
|
if (isset($data['extend']['schema']['doctrine'][$entityName]['fields'][$fieldName])) { |
68
|
|
|
unset($data['extend']['schema']['doctrine'][$entityName]['fields'][$fieldName]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$data = $this->connection->convertToDatabaseValue($data, Type::TARRAY); |
73
|
|
|
|
74
|
|
|
$this->executeQuery( |
75
|
|
|
$logger, |
76
|
|
|
'UPDATE oro_entity_config SET data = ? WHERE class_name = ?', |
77
|
|
|
[$data, $className] |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param LoggerInterface $logger |
83
|
|
|
* @param $sql |
84
|
|
|
* @param array $parameters |
85
|
|
|
* @throws \Doctrine\DBAL\DBALException |
86
|
|
|
*/ |
87
|
|
|
protected function executeQuery(LoggerInterface $logger, $sql, array $parameters = []) |
88
|
|
|
{ |
89
|
|
|
$statement = $this->connection->prepare($sql); |
90
|
|
|
$statement->execute($parameters); |
91
|
|
|
$this->logQuery($logger, $sql, $parameters); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.