Beispiel #1
0
 /**
  * @param array $classMap [class_name => entity_config_id, ...]
  *
  * @return array [entity_config_id => [field_name => is_configurable, ...], ...]
  */
 protected function loadConfigurableFields(array $classMap)
 {
     $connection = $this->configManager->getEntityManager()->getConnection();
     $fieldRows = $connection->executeQuery('SELECT id, entity_id, field_name, type, mode, data FROM oro_entity_config_field');
     $configurable = [];
     $fields = [];
     foreach ($fieldRows as $row) {
         $fieldId = (int) $row['id'];
         $entityId = (int) $row['entity_id'];
         if (!isset($classMap[$entityId])) {
             continue;
         }
         $className = $classMap[$entityId];
         $fieldName = $row['field_name'];
         $fieldType = $row['type'];
         $isHidden = $row['mode'] === ConfigModel::MODE_HIDDEN;
         $data = array_merge($this->getEmptyData(), $connection->convertToPHPValue($row['data'], 'array'));
         $configurable[$entityId][$fieldName] = true;
         $fields[$className][$fieldName] = ['i' => $fieldId, 'h' => $isHidden, 't' => $fieldType];
         $this->cache->saveFieldConfigValues($data, $className, $fieldName, $fieldType);
     }
     foreach ($fields as $className => $values) {
         $this->cache->saveFields($className, $values);
     }
     return $configurable;
 }
Beispiel #2
0
 public function testSaveFieldConfigValues()
 {
     $config1 = new Config(new FieldConfigId('scope1', self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE), ['key1' => 'val1']);
     $config2 = new Config(new FieldConfigId('scope2', self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE), ['key2' => 'val2']);
     $this->cache->expects($this->once())->method('save')->willReturnCallback(function ($key, $data) {
         $this->cache->expects($this->once())->method('fetch')->with($key)->willReturn($data);
         return true;
     });
     $this->assertTrue($this->configCache->saveFieldConfigValues([$config1->getId()->getScope() => $config1->getValues(), $config2->getId()->getScope() => $config2->getValues()], self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE));
     // test that configs saved right
     $this->assertEquals($config1, $this->configCache->getFieldConfig($config1->getId()->getScope(), self::ENTITY_CLASS, self::FIELD_NAME));
     $this->assertEquals($config2, $this->configCache->getFieldConfig($config2->getId()->getScope(), self::ENTITY_CLASS, self::FIELD_NAME));
 }