/** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * @return int New id of clone */ function createFromClone($fromid) { global $user, $langs; $error = 0; $object = new Cronjob($this->db); $object->context['createfromclone'] = 'createfromclone'; $this->db->begin(); // Load source object $object->fetch($fromid); $object->id = 0; $object->statut = 0; // Clear fields // ... // Create clone $result = $object->create($user); // Other options if ($result < 0) { $this->error = $object->error; $error++; } if (!$error) { } unset($this->context['createfromclone']); // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
$object->label = GETPOST('label', 'alpha'); $object->command = GETPOST('command', 'alpha'); $object->priority = GETPOST('priority', 'int'); $object->classesname = GETPOST('classesname', 'alpha'); $object->objectname = GETPOST('objectname', 'alpha'); $object->methodename = GETPOST('methodename', 'alpha'); $object->params = GETPOST('params'); $object->md5params = GETPOST('md5params'); $object->module_name = GETPOST('module_name', 'alpha'); $object->note = GETPOST('note'); $object->datestart = dol_mktime(GETPOST('datestarthour', 'int'), GETPOST('datestartmin', 'int'), 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int')); $object->dateend = dol_mktime(GETPOST('dateendhour', 'int'), GETPOST('dateendmin', 'int'), 0, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int')); $object->unitfrequency = GETPOST('unitfrequency', 'int'); $object->frequency = $object->unitfrequency * GETPOST('nbfrequency', 'int'); // Add cron task $result = $object->create($user); // test du Resultat de la requete if ($result < 0) { setEventMessage($object->error, 'errors'); $action = 'create'; } else { setEventMessage($langs->trans('CronSaveSucess'), 'mesgs'); $action = ''; } } // Save parameters if ($action == 'update') { $object->id = $id; $object->jobtype = GETPOST('jobtype'); $object->label = GETPOST('label'); $object->command = GETPOST('command');
/** * Function called when module is enabled. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. * It also creates data directories * * @param string $options Options when enabling module ('', 'noboxes') * @return int 1 if OK, 0 if KO */ function init($options = '') { global $user; $sql = array(); define('INC_FROM_DOLIBARR', true); dol_include_once('/recurrence/config.php'); dol_include_once('/recurrence/script/create-maj-base.php'); $TValues = array('label' => 'Mise à jour récurrence', 'jobtype' => 'method', 'frequency' => 86400, 'unitfrequency' => 86400, 'status' => 1, 'module_name' => 'recurrence', 'classesname' => 'cronrecurrence.class.php', 'objectname' => 'TCronRecurrence', 'methodename' => 'run', 'params' => '', 'datestart' => time()); $req = "\n\t\t\tSELECT rowid\n\t\t\tFROM " . MAIN_DB_PREFIX . "cronjob\n\t\t\tWHERE classesname = '" . $TValues['classesname'] . "'\n\t\t\tAND module_name = '" . $TValues['module_name'] . "'\n\t\t\tAND objectname = '" . $TValues['objectname'] . "'\n\t\t\tAND methodename = '" . $TValues['methodename'] . "'\n\t\t"; $res = $this->db->query($req); $job = $this->db->fetch_object($res); if (empty($job->rowid)) { $cronTask = new Cronjob($this->db); foreach ($TValues as $key => $value) { $cronTask->{$key} = $value; } $cronTask->create($user); } return $this->_init($sql, $options); }