/** * @see Form::save() */ public function save() { ACPForm::save(); // update cronjob $this->cronjob->update($this->classPath, $this->packageID, $this->description, $this->execMultiple, $this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow); $this->saved(); // show success WCF::getTPL()->assign(array('success' => true)); }
/** * @see Action::execute() */ public function execute() { parent::execute(); // check permission WCF::getUser()->checkPermission('admin.system.cronjobs.canDeleteCronjob'); // enable/disbale cronjob CronjobEditor::clearLog(); $this->executed(); // forward HeaderUtil::redirect('index.php?page=CronjobsShowLog&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED); exit; }
/** * @see Form::save() */ public function save() { ACPForm::save(); // save cronjob CronjobEditor::create($this->classPath, $this->packageID, $this->description, $this->execMultiple, $this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow); $sql = "SELECT cronjobs.cronjobID, package.packageDir FROM wcf" . WCF_N . "_cronjobs cronjobs\n\t\t\t\tLEFT JOIN wcf" . WCF_N . "_package package\n\t\t\t\tON (package.packageID = cronjobs.packageID)\n\t\t\t\t WHERE cronjobs.classPath = '" . $this->classPath . "'\t\t\t\t \n\t\t\t\t AND cronjobs.packageID = " . $this->packageID; $row = WCF::getDB()->getFirstRow($sql); $cronjobID = $row['cronjobID']; $cronjob = new CronjobEditor($cronjobID); $cronjob->update($row['packageDir'] . 'lib/system/cronjob/AdminToolsCronjob' . $cronjobID . '.class.php', $this->packageID, $this->description, $this->execMultiple, $this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow); $inserts = ''; foreach ($this->activeFunctions as $functionID) { if (!empty($inserts)) { $inserts .= ','; } $inserts .= '(' . $functionID . ', ' . $cronjobID . ')'; } $sql = "INSERT IGNORE INTO wcf" . WCF_N . "_admin_tools_function_to_cronjob\n\t\t\t\t\t(functionID, cronjobID)\n\t\t\t\t\tVALUES " . $inserts; WCF::getDB()->sendQuery($sql); $path = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); $fileName = $path . 'lib/system/cronjob/AdminToolsCronjob' . $cronjobID . '.class.php'; $this->writeCronjob($cronjobID, $fileName); $this->saved(); // reset values $this->classPath = $this->description = ''; $this->execMultiple = 0; $this->startMinute = $this->startHour = $this->startDom = $this->startMonth = $this->startDow = '*'; // show success. WCF::getTPL()->assign(array('success' => true)); $this->activeFunctions = array(); $this->wcfCronjob = 0; }
/** * Actually execute the cronjob. * * @param array $cronjobsCache * @return boolean success */ protected function execPendingCronjobs($cronjobsCache = array()) { // include class file if (!file_exists(WCF_DIR . $cronjobsCache['classPath'])) { throw new SystemException("unable to find class file '" . WCF_DIR . $cronjobsCache['classPath'] . "'", 11000); } require_once WCF_DIR . $cronjobsCache['classPath']; $i = 0; while ($i < $this->countMultipleExecs) { // omit 1970-01-01T01:00:00. if ($this->execMultiple == 1) { $cronjobsCache['nextExec'] = $this->timebase; } if (isset($this->plannedExecs) && count($this->plannedExecs)) { $cronjobsCache['nextExec'] = $this->plannedExecs[$i]; } // create instance. $className = StringUtil::getClassName($cronjobsCache['classPath']); if (!class_exists($className)) { throw new SystemException("unable to find class '" . $className . "'", 11001); } // execute cronjob. $cronjobExec = new $className(); if (method_exists($cronjobExec, 'execute')) { $cronjobExec->execute($cronjobsCache); } // log success. CronjobEditor::logSuccess($cronjobsCache['newLogID'], true); $i++; } }
/** * @see PackageInstallationPlugin::install() */ public function install() { parent::install(); if (!($xml = $this->getXML())) { return; } // Create an array with the data blocks (import or delete) from the xml file. $xml = $xml->getElementTree('data'); require_once WCF_DIR . 'lib/data/cronjobs/CronjobEditor.class.php'; // Loop through the array and install or uninstall cronjobs. foreach ($xml['children'] as $key => $block) { if (count($block['children'])) { // TODO: handle delete block first // Handle the import instructions if ($block['name'] == 'import') { // Loop through items and create or update them. foreach ($block['children'] as $cronjobInfo) { // Extract item properties. foreach ($cronjobInfo['children'] as $child) { if (!isset($child['cdata'])) { continue; } $cronjobInfo[$child['name']] = $child['cdata']; } // default values. $classPath = $description = $startMinute = $startHour = $startDom = $startMonth = $startDow = ''; $execMultiple = $canBeEdited = $canBeDisabled = 0; $active = 1; // make xml tags-names (keys in array) to lower case $this->keysToLowerCase($cronjobInfo); // get values. if (isset($cronjobInfo['classpath'])) { $classPath = $cronjobInfo['classpath']; } if (isset($cronjobInfo['description'])) { $description = $cronjobInfo['description']; } if (isset($cronjobInfo['startminute'])) { $startMinute = $cronjobInfo['startminute']; } if (isset($cronjobInfo['starthour'])) { $startHour = $cronjobInfo['starthour']; } if (isset($cronjobInfo['startdom'])) { $startDom = $cronjobInfo['startdom']; } if (isset($cronjobInfo['startmonth'])) { $startMonth = $cronjobInfo['startmonth']; } if (isset($cronjobInfo['startdow'])) { $startDow = $cronjobInfo['startdow']; } if (isset($cronjobInfo['execmultiple'])) { $execMultiple = intval($cronjobInfo['execmultiple']); } if (isset($cronjobInfo['active'])) { $active = intval($cronjobInfo['active']); } if (isset($cronjobInfo['canbeedited'])) { $canBeEdited = intval($cronjobInfo['canbeedited']); } if (isset($cronjobInfo['canbedisabled'])) { $canBeDisabled = intval($cronjobInfo['canbedisabled']); } // validate values CronjobEditor::validate($startMinute, $startHour, $startDom, $startMonth, $startDow); // save cronjob $sql = "INSERT INTO\twcf" . WCF_N . "_cronjobs \n\t\t\t\t\t\t\t\t\t(classPath, packageID, description, \n\t\t\t\t\t\t\t\t\tstartMinute, startHour, startDom, \n\t\t\t\t\t\t\t\t\tstartMonth, startDow, nextExec, execMultiple, \n\t\t\t\t\t\t\t\t\tactive, canBeEdited, canBeDisabled) \n\t\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t\t\t\t('" . escapeString($classPath) . "', \n\t\t\t\t\t\t\t\t\t" . $this->installation->getPackageID() . ", \n\t\t\t\t\t\t\t\t\t'" . escapeString($description) . "', \n\t\t\t\t\t\t\t\t\t'" . escapeString($startMinute) . "', \n\t\t\t\t\t\t\t\t\t'" . escapeString($startHour) . "', \n\t\t\t\t\t\t\t\t\t'" . escapeString($startDom) . "', \n\t\t\t\t\t\t\t\t\t'" . escapeString($startMonth) . "', \n\t\t\t\t\t\t\t\t\t'" . escapeString($startDow) . "', \n\t\t\t\t\t\t\t\t\t" . TIME_NOW . ", \n\t\t\t\t\t\t\t\t\t" . escapeString($execMultiple) . ",\n\t\t\t\t\t\t\t\t\t" . escapeString($active) . ",\n\t\t\t\t\t\t\t\t\t" . escapeString($canBeEdited) . ", \n\t\t\t\t\t\t\t\t\t" . escapeString($canBeDisabled) . ")"; WCF::getDB()->sendQuery($sql); } } else { if ($block['name'] == 'delete') { if ($this->installation->getAction() == 'update') { // Loop through items and delete them. $cronjobNames = ''; foreach ($block['children'] as $cronjobInfo) { // check required attributes if (!isset($cronjobInfo['attrs']['name'])) { throw new SystemException("Required 'name' attribute for 'cronjob'-tag is missing.", 13023); } // Create a string with all item names which should be deleted (comma separated). if (!empty($cronjobNames)) { $cronjobNames .= ','; } $cronjobNames .= "'" . escapeString($cronjobInfo['attrs']['name']) . "'"; } // Delete items. if (!empty($cronjobNames)) { $sql = "DELETE FROM\twcf" . WCF_N . "_cronjobs\n\t\t\t\t\t\t\t\tWHERE\t\tclassPath IN (" . $cronjobNames . ")\n\t\t\t\t\t\t\t\t\t\tAND packageID = " . $this->installation->getPackageID(); WCF::getDB()->sendQuery($sql); } } } } } } }
/** * @see Form::save() */ public function save() { parent::save(); // save cronjob CronjobEditor::create($this->classPath, $this->packageID, $this->description, $this->execMultiple, $this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow); $this->saved(); // reset values $this->classPath = $this->description = ''; $this->execMultiple = 0; $this->startMinute = $this->startHour = $this->startDom = $this->startMonth = $this->startDow = '*'; // show success. WCF::getTPL()->assign(array('success' => true)); }
/** * Executes this cronjob. */ public function execute() { // create log entry $logID = CronjobEditor::logExec(); // include class file $classPath = FileUtil::getRealPath(WCF_DIR . $this->packageDir . $this->classPath); if (!file_exists($classPath)) { throw new SystemException("unable to find class file '" . $classPath . "'", 11000); } require_once $classPath; // create instance. $className = StringUtil::getClassName($this->classPath); if (!class_exists($className)) { throw new SystemException("unable to find class '" . $className . "'", 11001); } // execute cronjob. $cronjobExec = new $className(); if (method_exists($cronjobExec, 'execute')) { $cronjobExec->execute($this->data); } // log success. CronjobEditor::logSuccess($logID, true); }