afterMassRelate, afterUnlinkAll hooks

This commit is contained in:
yuri
2017-04-10 12:49:24 +03:00
parent 0e9373cf5e
commit 7afecc4cdd
3 changed files with 31 additions and 5 deletions
@@ -189,6 +189,13 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
$this->getEntityManager()->getHookManager()->process($this->entityType, 'afterRemove', $entity, $options);
}
protected function afterMassRelate(Entity $entity, $relationName, array $params = array(), array $options = array())
{
$options['params'] = $params;
$this->getEntityManager()->getHookManager()->process($this->entityType, 'afterMassRelate', $entity, $options);
}
public function remove(Entity $entity, array $options = array())
{
$result = parent::remove($entity, $options);
@@ -48,6 +48,14 @@ class TargetList extends \Espo\Services\Record
'User' => 'users'
);
protected function init()
{
parent::init();
$this->addDependencyList([
'hookManager'
]);
}
public function loadAdditionalFields(Entity $entity)
{
parent::loadAdditionalFields($entity);
@@ -178,6 +186,7 @@ class TargetList extends \Espo\Services\Record
}
if ($sql) {
if ($pdo->query($sql)) {
$this->getInjection('hookManager')->process('TargetList', 'afterUnlinkAll', $entity, array('link' => $link));
return true;
}
}
+15 -5
View File
@@ -354,22 +354,26 @@ class RDB extends \Espo\ORM\Repository
protected function beforeRelate(Entity $entity, $relationName, $foreign, $data = null, array $options = array())
{
}
protected function afterRelate(Entity $entity, $relationName, $foreign, $data = null, array $options = array())
{
}
protected function beforeUnrelate(Entity $entity, $relationName, $foreign, array $options = array())
{
}
protected function afterUnrelate(Entity $entity, $relationName, $foreign, array $options = array())
{
}
protected function beforeMassRelate(Entity $entity, $relationName, array $params = array(), array $options = array())
{
}
protected function afterMassRelate(Entity $entity, $relationName, array $params = array(), array $options = array())
{
}
public function updateRelation(Entity $entity, $relationName, $foreign, $data)
@@ -391,12 +395,18 @@ class RDB extends \Espo\ORM\Repository
return null;
}
public function massRelate(Entity $entity, $relationName, array $params = array())
public function massRelate(Entity $entity, $relationName, array $params = array(), array $options = array())
{
if (!$entity->id) {
return;
}
return $this->getMapper()->massRelate($entity, $relationName, $params);
$this->beforeMassRelate($entity, $relationName, $params, $options);
$result = $this->getMapper()->massRelate($entity, $relationName, $params);
if ($result) {
$this->afterMassRelate($entity, $relationName, $params, $options);
}
return $result;
}
public function getAll()