array value cleanup

This commit is contained in:
yuri
2018-08-14 10:25:10 +03:00
parent 81ff01e9be
commit 0b7743419e
12 changed files with 55 additions and 0 deletions
@@ -41,6 +41,8 @@ class ArrayValue extends \Espo\Core\ORM\Repositories\RDB
protected $processFieldsBeforeSaveDisabled = true;
protected $processFieldsAfterRemoveDisabled = true;
public function storeEntityAttribute(Entity $entity, $attribute, $populateMode = false)
{
if (!$entity->getAttributeType($attribute) === Entity::JSON_ARRAY) {
@@ -92,4 +94,20 @@ class ArrayValue extends \Espo\Core\ORM\Repositories\RDB
$this->save($arrayValue);
}
}
public function deleteEntityAttribute(Entity $entity, $attribute)
{
if (!$entity->id) {
throw new Error("ArrayValue: Can't delete {$attribute} w/o id given.");
}
$list = $this->select(['id'])->where([
'entityType' => $entity->getEntityType(),
'entityId' => $entity->id,
'attribute' => $attribute
])->find();
foreach ($list as $arrayValue) {
$this->deleteFromDb($arrayValue->id);
}
}
}