FIX: move doActions hook before standard actions

Move doActions hook before standard actions in element resources
This commit is contained in:
Josep Lluís 2019-07-26 17:51:54 +02:00 committed by GitHub
parent a46bfc7a29
commit a412a99263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2013-2018 Jean-François Ferry <hello+jf@librethic.io>
* Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
* Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -80,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;
}
@ -131,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');