NEW Can clone a cron job.
This commit is contained in:
parent
36c6a41b1b
commit
b14de0bff7
@ -36,10 +36,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
|
|||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$langs->loadLangs(array('admin', 'cron', 'members'));
|
$langs->loadLangs(array('admin', 'cron', 'members'));
|
||||||
|
|
||||||
if (!$user->rights->cron->create) {
|
|
||||||
accessforbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = GETPOST('id', 'int');
|
$id = GETPOST('id', 'int');
|
||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
$confirm = GETPOST('confirm', 'alpha');
|
$confirm = GETPOST('confirm', 'alpha');
|
||||||
@ -49,6 +45,12 @@ $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
|
|||||||
|
|
||||||
$securitykey = GETPOST('securitykey', 'alpha');
|
$securitykey = GETPOST('securitykey', 'alpha');
|
||||||
|
|
||||||
|
$permissiontoadd = $user->rights->cron->create;
|
||||||
|
|
||||||
|
if (!$user->rights->cron->create) {
|
||||||
|
accessforbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Actions
|
* 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"));
|
llxHeader('', $langs->trans("CronTask"));
|
||||||
|
|
||||||
if ($action == 'edit' || empty($action) || $action == 'delete' || $action == 'execute') {
|
|
||||||
$head = cron_prepare_head($object);
|
$head = cron_prepare_head($object);
|
||||||
} elseif ($action == 'create') {
|
|
||||||
|
if ($action == 'create') {
|
||||||
print load_fiche_titre($langs->trans("CronTask"), '', 'title_setup');
|
print load_fiche_titre($langs->trans("CronTask"), '', 'title_setup');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,17 +285,26 @@ if ($conf->use_javascript_ajax) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'delete') {
|
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 = '';
|
$action = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'execute') {
|
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 = '';
|
$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) {
|
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>';
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronStatusActiveBtn").'/'.$langs->trans("CronStatusInactiveBtn").'</a>';
|
||||||
} else {
|
} else {
|
||||||
|
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Clone").'</a>';
|
||||||
|
|
||||||
if (empty($object->status)) {
|
if (empty($object->status)) {
|
||||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=activate&token='.newToken().'&id='.$object->id.'">'.$langs->trans("CronStatusActiveBtn").'</a>';
|
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=activate&token='.newToken().'&id='.$object->id.'">'.$langs->trans("CronStatusActiveBtn").'</a>';
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -859,6 +859,8 @@ class Cronjob extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function createFromClone(User $user, $fromid)
|
public function createFromClone(User $user, $fromid)
|
||||||
{
|
{
|
||||||
|
global $langs;
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
$object = new Cronjob($this->db);
|
$object = new Cronjob($this->db);
|
||||||
@ -868,10 +870,10 @@ class Cronjob extends CommonObject
|
|||||||
// Load source object
|
// Load source object
|
||||||
$object->fetch($fromid);
|
$object->fetch($fromid);
|
||||||
$object->id = 0;
|
$object->id = 0;
|
||||||
$object->statut = 0;
|
|
||||||
|
|
||||||
// Clear fields
|
// Clear fields
|
||||||
// ...
|
$object->status = self::STATUS_DISABLED;
|
||||||
|
$object->label = $langs->trans("CopyOf").' '.$object->label;
|
||||||
|
|
||||||
// Create clone
|
// Create clone
|
||||||
$object->context['createfromclone'] = 'createfromclone';
|
$object->context['createfromclone'] = 'createfromclone';
|
||||||
@ -883,11 +885,6 @@ class Cronjob extends CommonObject
|
|||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (! $error)
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
unset($object->context['createfromclone']);
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
|
|||||||
@ -60,7 +60,7 @@ CronErrEndDateStartDt=End date cannot be before start date
|
|||||||
StatusAtInstall=Status at module installation
|
StatusAtInstall=Status at module installation
|
||||||
CronStatusActiveBtn=Schedule
|
CronStatusActiveBtn=Schedule
|
||||||
CronStatusInactiveBtn=Disable
|
CronStatusInactiveBtn=Disable
|
||||||
CronTaskInactive=This job is disabled
|
CronTaskInactive=This job is disabled (not scheduled)
|
||||||
CronId=Id
|
CronId=Id
|
||||||
CronClassFile=Filename with class
|
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>
|
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>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user