Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / CronjobEditForm.class.php
1 <?php
2 namespace wcf\acp\form;
3 use wcf\data\cronjob\Cronjob;
4 use wcf\data\cronjob\CronjobAction;
5 use wcf\form\AbstractForm;
6 use wcf\system\exception\IllegalLinkException;
7 use wcf\system\language\I18nHandler;
8 use wcf\system\WCF;
9
10 /**
11 * Shows the cronjob edit form.
12 *
13 * @author Alexander Ebert
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\Acp\Form
17 */
18 class CronjobEditForm extends CronjobAddForm {
19 /**
20 * @inheritDoc
21 */
22 public $activeMenuItem = 'wcf.acp.menu.link.maintenance';
23
24 /**
25 * cronjob id
26 * @var integer
27 */
28 public $cronjobID = 0;
29
30 /**
31 * cronjob object
32 * @var Cronjob
33 */
34 public $cronjob = null;
35
36 /**
37 * @inheritDoc
38 */
39 public function readParameters() {
40 parent::readParameters();
41
42 if (isset($_REQUEST['id'])) $this->cronjobID = intval($_REQUEST['id']);
43 $this->cronjob = new Cronjob($this->cronjobID);
44 if (!$this->cronjob->cronjobID) {
45 throw new IllegalLinkException();
46 }
47
48 $this->packageID = $this->cronjob->packageID;
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function save() {
55 AbstractForm::save();
56
57 $this->description = 'wcf.acp.cronjob.description.cronjob'.$this->cronjob->cronjobID;
58 if (I18nHandler::getInstance()->isPlainValue('description')) {
59 I18nHandler::getInstance()->remove($this->description);
60 $this->description = I18nHandler::getInstance()->getValue('description');
61 }
62 else {
63 I18nHandler::getInstance()->save('description', $this->description, 'wcf.acp.cronjob', $this->cronjob->packageID);
64 }
65
66 // update cronjob
67 $data = array_merge($this->additionalFields, [
68 'className' => $this->className,
69 'description' => $this->description,
70 'startMinute' => $this->startMinute,
71 'startHour' => $this->startHour,
72 'startDom' => $this->startDom,
73 'startMonth' => $this->startMonth,
74 'startDow' => $this->startDow
75 ]);
76
77 $this->objectAction = new CronjobAction([$this->cronjobID], 'update', ['data' => $data]);
78 $this->objectAction->executeAction();
79
80 $this->saved();
81
82 // show success message
83 WCF::getTPL()->assign('success', true);
84 }
85
86 /**
87 * @inheritDoc
88 */
89 public function readData() {
90 parent::readData();
91
92 if (empty($_POST)) {
93 I18nHandler::getInstance()->setOptions('description', $this->cronjob->packageID, $this->cronjob->description, 'wcf.acp.cronjob.description.cronjob\d+');
94
95 $this->className = $this->cronjob->className;
96 $this->description = $this->cronjob->description;
97 $this->startMinute = $this->cronjob->startMinute;
98 $this->startHour = $this->cronjob->startHour;
99 $this->startDom = $this->cronjob->startDom;
100 $this->startMonth = $this->cronjob->startMonth;
101 $this->startDow = $this->cronjob->startDow;
102 }
103 }
104
105 /**
106 * @inheritDoc
107 */
108 public function assignVariables() {
109 parent::assignVariables();
110
111 I18nHandler::getInstance()->assignVariables(!empty($_POST));
112
113 WCF::getTPL()->assign([
114 'cronjobID' => $this->cronjobID,
115 'action' => 'edit'
116 ]);
117 }
118 }