Merge pull request #11568 from joseplluis/patch-7

FIX: move doActions hook before standard actions
This commit is contained in:
Laurent Destailleur 2019-07-30 21:08:12 +02:00 committed by GitHub
commit 4bda18fd4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,47 +81,71 @@ if ($socid > 0) // Special for thirdparty
* Actions
*/
if ($action == 'add_element_resource' && ! $cancel)
{
$res = 0;
if (! ($resource_id > 0))
{
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
$action='';
}
else
{
$objstat = fetchObjectByElement($element_id, $element, $element_ref);
$objstat->element = $element; // For externals module, we need to keep @xx
$res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
}
if (! $error && $res > 0)
{
setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
exit;
}
elseif ($objstat)
{
setEventMessages($objstat->error, $objstat->errors, 'errors');
}
}
$parameters = array('resource_id' => $resource_id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') )
if (empty($reshook))
{
$res = $object->fetch_element_resource($lineid);
if($res)
if ($action == 'add_element_resource' && ! $cancel)
{
$object->busy = $busy;
$object->mandatory = $mandatory;
$res = 0;
if (! ($resource_id > 0))
{
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
$action='';
}
else
{
$objstat = fetchObjectByElement($element_id, $element, $element_ref);
$objstat->element = $element; // For externals module, we need to keep @xx
$res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
}
if (! $error && $res > 0)
{
setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
exit;
}
elseif ($objstat)
{
setEventMessages($objstat->error, $objstat->errors, 'errors');
}
}
$result = $object->update_element_resource($user);
// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') )
{
$res = $object->fetch_element_resource($lineid);
if($res)
{
$object->busy = $busy;
$object->mandatory = $mandatory;
$result = $object->update_element_resource($user);
if ($result >= 0)
{
setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
// Delete a resource linked to an element
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && $confirm === 'yes')
{
$result = $object->delete_resource($lineid, $element);
if ($result >= 0)
{
setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
exit;
}
@ -132,28 +156,6 @@ if ($action == 'update_linked_resource' && $user->rights->resource->write && !GE
}
}
// Delete a resource linked to an element
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && $confirm === 'yes')
{
$result = $object->delete_resource($lineid, $element);
if ($result >= 0)
{
setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
}
$parameters=array('resource_id'=>$resource_id);
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
$parameters=array('resource_id'=>$resource_id);
$reshook=$hookmanager->executeHooks('getElementResources', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');