Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #126 from atrocore/i-c65411a5c91366d3a
Browse files Browse the repository at this point in the history
Fix: Duplicate asset type does not duplicate validations
  • Loading branch information
rratsun committed Nov 23, 2023
2 parents 7dcbb36 + bb4cdb7 commit b1894c8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/Services/AssetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

use Espo\Core\EventManager\Event;
use Espo\Core\Templates\Services\Base;
use Espo\Core\Utils\Util;
use Espo\ORM\Entity;

class AssetType extends Base
{
Expand Down Expand Up @@ -65,4 +67,29 @@ public function massRemove(array $params)

return $this->dispatchEvent('afterMassRemove', new Event(['result' => ['count' => count($ids), 'ids' => $ids]]))->getArgument('result');
}

public function duplicateValidationRules(Entity $assetType, Entity $duplicatingAssetType): void
{
$validationRules = $duplicatingAssetType->get('validationRules');

if (empty($validationRules) || count($validationRules) === 0) {
return;
}

/** @var \Dam\Repositories\ValidationRule $repository */
$repository = $this->getEntityManager()->getRepository('ValidationRule');

foreach ($validationRules as $rule) {
$entity = $repository->get();
$entity->set($rule->toArray());
$entity->id = Util::generateId();
$entity->set('assetTypeId', $assetType->get('id'));

try {
$repository->save($entity);
} catch (\Throwable $e) {
$GLOBALS['log']->error('ValidationRule duplicating failed: ' . $e->getMessage());
}
}
}
}

0 comments on commit b1894c8

Please sign in to comment.