/** * @see \wcf\data\IEditableObject::create() */ public static function create(array $parameters = array()) { $descriptions = array(); if (isset($parameters['description']) && is_array($parameters['description'])) { if (count($parameters['description']) > 1) { $descriptions = $parameters['description']; $parameters['description'] = ''; } else { $parameters['description'] = reset($parameters['description']); } } $cronjob = parent::create($parameters); // save cronjob description if (!empty($descriptions)) { // set default value if (isset($descriptions[''])) { $defaultValue = $descriptions['']; } else { if (isset($descriptions['en'])) { // fallback to English $defaultValue = $descriptions['en']; } else { if (isset($descriptions[WCF::getLanguage()->getFixedLanguageCode()])) { // fallback to the language of the current user $defaultValue = $descriptions[WCF::getLanguage()->getFixedLanguageCode()]; } else { // fallback to first description $defaultValue = reset($descriptions); } } } // fetch data directly from database during framework installation if (!PACKAGE_ID) { $sql = "SELECT\t*\n\t\t\t\t\tFROM\twcf" . WCF_N . "_language_category\n\t\t\t\t\tWHERE\tlanguageCategory = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array('wcf.acp.cronjob')); $languageCategory = $statement->fetchObject('wcf\\data\\language\\category\\LanguageCategory'); $languages = new LanguageList(); $languages->readObjects(); } else { $languages = LanguageFactory::getInstance()->getLanguages(); $languageCategory = LanguageFactory::getInstance()->getCategory('wcf.acp.cronjob'); } $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageCategoryID, packageID)\n\t\t\t\tVALUES\t\t(?, ?, ?, ?, ?)\n\t\t\t\tON DUPLICATE KEY UPDATE languageItemValue = VALUES(languageItemValue)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($languages as $language) { $value = $defaultValue; if (isset($descriptions[$language->languageCode])) { $value = $descriptions[$language->languageCode]; } $statement->execute(array($language->languageID, 'wcf.acp.cronjob.description.cronjob' . $cronjob->cronjobID, $value, $languageCategory->languageCategoryID, $cronjob->packageID)); } // update cronjob $cronjobEditor = new CronjobEditor($cronjob); $cronjobEditor->update(array('description' => 'wcf.acp.cronjob.description.cronjob' . $cronjob->cronjobID)); } return $cronjob; }
/** * Executes a cronjob. * * @param wcf\data\cronjob\CronjobEditor $cronjobEditor * @param wcf\data\cronjob\log\CronjobLogEditor $logEditor */ protected function executeCronjob(CronjobEditor $cronjobEditor, CronjobLogEditor $logEditor) { $className = $cronjobEditor->className; if (!class_exists($className)) { throw new SystemException("unable to find class '" . $className . "'"); } // verify class signature if (!ClassUtil::isInstanceOf($className, 'wcf\\system\\cronjob\\ICronjob')) { throw new SystemException("class '" . $className . "' does not implement the interface 'wcf\\system\\cronjob\\ICronjob'"); } // execute cronjob $cronjob = new $className(); $cronjob->execute($cronjobEditor->getDecoratedObject()); $this->logResult($logEditor); }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); // save cronjob $data = array_merge($this->additionalFields, array('className' => $this->className, 'packageID' => $this->packageID, 'description' => $this->description, 'startMinute' => $this->startMinute, 'startHour' => $this->startHour, 'startDom' => $this->startDom, 'startMonth' => $this->startMonth, 'startDow' => $this->startDow)); $this->objectAction = new CronjobAction(array(), 'create', array('data' => $data)); $this->objectAction->executeAction(); if (!I18nHandler::getInstance()->isPlainValue('description')) { $returnValues = $this->objectAction->getReturnValues(); $cronjobID = $returnValues['returnValues']->cronjobID; I18nHandler::getInstance()->save('description', 'wcf.acp.cronjob.description.cronjob' . $cronjobID, 'wcf.acp.cronjob', $this->packageID); // update group name $cronjobEditor = new CronjobEditor($returnValues['returnValues']); $cronjobEditor->update(array('description' => 'wcf.acp.cronjob.description.cronjob' . $cronjobID)); } $this->saved(); // reset values $this->className = $this->description = ''; $this->startMinute = $this->startHour = $this->startDom = $this->startMonth = $this->startDow = '*'; I18nHandler::getInstance()->reset(); // show success. WCF::getTPL()->assign(array('success' => true)); }