2 namespace wcf\acp\form
;
3 use wcf\data\cronjob\CronjobAction
;
4 use wcf\data\cronjob\CronjobEditor
;
5 use wcf\form\AbstractForm
;
6 use wcf\system\exception\SystemException
;
7 use wcf\system\exception\UserInputException
;
8 use wcf\system\language\I18nHandler
;
10 use wcf\util\CronjobUtil
;
11 use wcf\util\StringUtil
;
14 * Shows the cronjob add form.
16 * @author Alexander Ebert
17 * @copyright 2001-2014 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package com.woltlab.wcf
20 * @subpackage acp.form
21 * @category Community Framework
23 class CronjobAddForm
extends AbstractForm
{
25 * @see \wcf\page\AbstractPage::$activeMenuItem
27 public $activeMenuItem = 'wcf.acp.menu.link.cronjob.add';
30 * @see \wcf\page\AbstractPage::$neededPermissions
32 public $neededPermissions = array('admin.system.canManageCronjob');
38 public $className = '';
44 public $packageID = PACKAGE_ID
;
50 public $description = '';
53 * execution time (min)
56 public $startMinute = '*';
59 * execution time (hour)
62 public $startHour = '*';
65 * execution time (day of month)
68 public $startDom = '*';
71 * execution time (month)
74 public $startMonth = '*';
77 * execution time (day of week)
80 public $startDow = '*';
83 * @see \wcf\page\IPage::readParameters()
85 public function readParameters() {
86 parent
::readParameters();
88 I18nHandler
::getInstance()->register('description');
92 * @see \wcf\form\IForm::readFormParameters()
94 public function readFormParameters() {
95 parent
::readFormParameters();
97 I18nHandler
::getInstance()->readValues();
99 if (isset($_POST['className'])) $this->className
= StringUtil
::trim($_POST['className']);
100 if (isset($_POST['description'])) $this->description
= StringUtil
::trim($_POST['description']);
101 if (isset($_POST['startMinute'])) $this->startMinute
= str_replace(' ', '', $_POST['startMinute']);
102 if (isset($_POST['startHour'])) $this->startHour
= str_replace(' ', '', $_POST['startHour']);
103 if (isset($_POST['startDom'])) $this->startDom
= str_replace(' ', '', $_POST['startDom']);
104 if (isset($_POST['startMonth'])) $this->startMonth
= str_replace(' ', '', $_POST['startMonth']);
105 if (isset($_POST['startDow'])) $this->startDow
= str_replace(' ', '', $_POST['startDow']);
109 * @see \wcf\form\IForm::validate()
111 public function validate() {
114 // validate class name
115 if (empty($this->className
)) {
116 throw new UserInputException('className');
119 if (!class_exists($this->className
)) {
120 throw new UserInputException('className', 'doesNotExist');
123 // validate description
124 if (!I18nHandler
::getInstance()->validateValue('description')) {
125 if (I18nHandler
::getInstance()->isPlainValue('description')) {
126 throw new UserInputException('description');
129 throw new UserInputException('description', 'multilingual');
134 CronjobUtil
::validate($this->startMinute
, $this->startHour
, $this->startDom
, $this->startMonth
, $this->startDow
);
136 catch (SystemException
$e) {
137 // extract field name
139 if (preg_match("/cronjob attribute '(.*)'/", $e->getMessage(), $match)) {
140 $fieldName = $match[1];
143 throw new UserInputException($fieldName, 'notValid');
148 * @see \wcf\form\IForm::save()
150 public function save() {
154 $data = array_merge($this->additionalFields
, array(
155 'className' => $this->className
,
156 'packageID' => $this->packageID
,
157 'description' => $this->description
,
158 'startMinute' => $this->startMinute
,
159 'startHour' => $this->startHour
,
160 'startDom' => $this->startDom
,
161 'startMonth' => $this->startMonth
,
162 'startDow' => $this->startDow
165 $this->objectAction
= new CronjobAction(array(), 'create', array('data' => $data));
166 $this->objectAction
->executeAction();
168 if (!I18nHandler
::getInstance()->isPlainValue('description')) {
169 $returnValues = $this->objectAction
->getReturnValues();
170 $cronjobID = $returnValues['returnValues']->cronjobID
;
171 I18nHandler
::getInstance()->save('description', 'wcf.acp.cronjob.description.cronjob'.$cronjobID, 'wcf.acp.cronjob', $this->packageID
);
174 $cronjobEditor = new CronjobEditor($returnValues['returnValues']);
175 $cronjobEditor->update(array(
176 'description' => 'wcf.acp.cronjob.description.cronjob'.$cronjobID
183 $this->className
= $this->description
= '';
184 $this->startMinute
= $this->startHour
= $this->startDom
= $this->startMonth
= $this->startDow
= '*';
185 I18nHandler
::getInstance()->reset();
188 WCF
::getTPL()->assign(array(
194 * @see \wcf\page\IPage::assignVariables()
196 public function assignVariables() {
197 parent
::assignVariables();
199 I18nHandler
::getInstance()->assignVariables();
201 WCF
::getTPL()->assign(array(
202 'className' => $this->className
,
203 'description' => $this->description
,
204 'startMinute' => $this->startMinute
,
205 'startHour' => $this->startHour
,
206 'startDom' => $this->startDom
,
207 'startMonth' => $this->startMonth
,
208 'startDow' => $this->startDow
,