NEW Can clone a cron job.

This commit is contained in:
Laurent Destailleur 2021-05-04 10:56:21 +02:00
parent 36c6a41b1b
commit b14de0bff7
3 changed files with 51 additions and 17 deletions

View File

@ -36,10 +36,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'cron', 'members'));
if (!$user->rights->cron->create) {
accessforbidden();
}
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
@ -49,6 +45,12 @@ $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
$securitykey = GETPOST('securitykey', 'alpha');
$permissiontoadd = $user->rights->cron->create;
if (!$user->rights->cron->create) {
accessforbidden();
}
/*
* Actions
@ -219,6 +221,30 @@ if ($action == 'inactive') {
}
}
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) {
if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
} else {
$objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid.
$result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
if (is_object($result) || $result > 0) {
$newid = 0;
if (is_object($result)) {
$newid = $result->id;
} else {
$newid = $result;
}
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object
exit;
} else {
setEventMessages($objectutil->error, $objectutil->errors, 'errors');
$action = '';
}
}
}
/*
@ -230,9 +256,9 @@ $formCron = new FormCron($db);
llxHeader('', $langs->trans("CronTask"));
if ($action == 'edit' || empty($action) || $action == 'delete' || $action == 'execute') {
$head = cron_prepare_head($object);
} elseif ($action == 'create') {
$head = cron_prepare_head($object);
if ($action == 'create') {
print load_fiche_titre($langs->trans("CronTask"), '', 'title_setup');
}
@ -259,17 +285,26 @@ if ($conf->use_javascript_ajax) {
}
if ($action == 'delete') {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
$action = '';
}
if ($action == 'execute') {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id.'&securitykey='.$securitykey, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id.'&securitykey='.$securitykey, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
$action = '';
}
// Clone confirmation
if ($action == 'clone') {
// Create an array for form
$formquestion = array();
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
}
// Print form confirm
print $formconfirm;
/*
@ -727,6 +762,8 @@ if (($action == "create") || ($action == "edit")) {
if (!$user->rights->cron->create) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronStatusActiveBtn").'/'.$langs->trans("CronStatusInactiveBtn").'</a>';
} else {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Clone").'</a>';
if (empty($object->status)) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=activate&token='.newToken().'&id='.$object->id.'">'.$langs->trans("CronStatusActiveBtn").'</a>';
} else {

View File

@ -859,6 +859,8 @@ class Cronjob extends CommonObject
*/
public function createFromClone(User $user, $fromid)
{
global $langs;
$error = 0;
$object = new Cronjob($this->db);
@ -868,10 +870,10 @@ class Cronjob extends CommonObject
// Load source object
$object->fetch($fromid);
$object->id = 0;
$object->statut = 0;
// Clear fields
// ...
$object->status = self::STATUS_DISABLED;
$object->label = $langs->trans("CopyOf").' '.$object->label;
// Create clone
$object->context['createfromclone'] = 'createfromclone';
@ -883,11 +885,6 @@ class Cronjob extends CommonObject
$error++;
}
//if (! $error)
//{
//}
unset($object->context['createfromclone']);
// End

View File

@ -60,7 +60,7 @@ CronErrEndDateStartDt=End date cannot be before start date
StatusAtInstall=Status at module installation
CronStatusActiveBtn=Schedule
CronStatusInactiveBtn=Disable
CronTaskInactive=This job is disabled
CronTaskInactive=This job is disabled (not scheduled)
CronId=Id
CronClassFile=Filename with class
CronModuleHelp=Name of Dolibarr module directory (also work with external Dolibarr module). <BR> For example to call the fetch method of Dolibarr Product object /htdocs/<u>product</u>/class/product.class.php, the value for module is<br><i>product</i>