Skip to content

Commit

Permalink
Merge pull request #11568 from joseplluis/patch-7
Browse files Browse the repository at this point in the history
FIX: move doActions hook before standard actions
  • Loading branch information
eldy committed Jul 30, 2019
2 parents dca7759 + a412a99 commit 4bda18f
Showing 1 changed file with 55 additions and 53 deletions.
108 changes: 55 additions & 53 deletions htdocs/resource/element_resource.php
Expand Up @@ -81,47 +81,71 @@
* Actions
*/

if ($action == 'add_element_resource' && ! $cancel)
$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');

if (empty($reshook))
{
$res = 0;
if (! ($resource_id > 0))
if ($action == 'add_element_resource' && ! $cancel)
{
$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);
$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');
}
}
if (! $error && $res > 0)

// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') )
{
setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
exit;
$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');
}
}
}
elseif ($objstat)
{
setEventMessages($objstat->error, $objstat->errors, 'errors');
}
}

// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel', 'alpha') )
{
$res = $object->fetch_element_resource($lineid);
if($res)
// Delete a resource linked to an element
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && $confirm === 'yes')
{
$object->busy = $busy;
$object->mandatory = $mandatory;

$result = $object->update_element_resource($user);
$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;
}
Expand All @@ -132,28 +156,6 @@
}
}

// 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');
Expand Down

0 comments on commit 4bda18f

Please sign in to comment.