-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathConfigManager.php
63 lines (56 loc) · 2.12 KB
/
ConfigManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Oro\Bundle\AkeneoBundle\Config;
use Oro\Bundle\EntityConfigBundle\Config\ConfigInterface;
use Oro\Bundle\EntityConfigBundle\Config\ConfigManager as BaseManager;
use Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId;
class ConfigManager extends BaseManager implements ChangesAwareInterface
{
public function hasChanges(): bool
{
$groupedConfigs = $this->getGroupedPersistConfigs();
/** @var ConfigInterface[] $configs */
foreach ($groupedConfigs as $modelKey => $configs) {
foreach ($configs as $scope => $config) {
$configId = $config->getId();
$className = $configId->getClassName();
if ($configId instanceof FieldConfigId) {
$fieldName = $configId->getFieldName();
$model = $this->getModelManager()->getFieldModel($className, $fieldName);
} else {
$model = $this->getModelManager()->getEntityModel($className);
}
$diffData = $this->getDiff($config->getValues(), $model->toArray($scope));
if (!empty($diffData)) {
return true;
}
}
}
return false;
}
protected function getDiff($values, $originalValues)
{
$diff = [];
if (empty($originalValues)) {
foreach ($values as $code => $value) {
$diff[$code] = [null, $value];
}
} else {
foreach ($originalValues as $code => $originalValue) {
if (array_key_exists($code, $values)) {
$value = $values[$code];
if ($originalValue != $value) {
$diff[$code] = [$originalValue, $value];
}
} else {
$diff[$code] = [$originalValue, null];
}
}
foreach ($values as $code => $value) {
if (!array_key_exists($code, $originalValues)) {
$diff[$code] = [null, $value];
}
}
}
return $diff;
}
}