Merge branch 'master' into next
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / PackageUpdateServerAddForm.class.php
1 <?php
2 namespace wcf\acp\form;
3 use wcf\data\package\update\server\PackageUpdateServer;
4 use wcf\data\package\update\server\PackageUpdateServerAction;
5 use wcf\form\AbstractForm;
6 use wcf\system\exception\UserInputException;
7 use wcf\system\WCF;
8 use wcf\system\WCFACP;
9 use wcf\util\StringUtil;
10
11 /**
12 * Shows the server add form.
13 *
14 * @author Marcel Werk
15 * @copyright 2001-2016 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Acp\Form
18 */
19 class PackageUpdateServerAddForm extends AbstractForm {
20 /**
21 * @inheritDoc
22 */
23 public $activeMenuItem = 'wcf.acp.menu.link.package';
24
25 /**
26 * @inheritDoc
27 */
28 public $neededPermissions = ['admin.configuration.package.canEditServer'];
29
30 /**
31 * server url
32 * @var string
33 */
34 public $serverURL = '';
35
36 /**
37 * server login username
38 * @var string
39 */
40 public $loginUsername = '';
41
42 /**
43 * server login password
44 * @var string
45 */
46 public $loginPassword = '';
47
48 /**
49 * @inheritDoc
50 */
51 public function readFormParameters() {
52 parent::readFormParameters();
53
54 if (isset($_POST['serverURL'])) $this->serverURL = StringUtil::trim($_POST['serverURL']);
55 if (isset($_POST['loginUsername'])) $this->loginUsername = $_POST['loginUsername'];
56 if (isset($_POST['loginPassword'])) $this->loginPassword = $_POST['loginPassword'];
57 }
58
59 /**
60 * @inheritDoc
61 */
62 public function validate() {
63 parent::validate();
64
65 if (empty($this->serverURL)) {
66 throw new UserInputException('serverURL');
67 }
68
69 if (!PackageUpdateServer::isValidServerURL($this->serverURL)) {
70 throw new UserInputException('serverURL', 'invalid');
71 }
72 }
73
74 /**
75 * @inheritDoc
76 */
77 public function save() {
78 parent::save();
79
80 // save server
81 $this->objectAction = new PackageUpdateServerAction([], 'create', ['data' => array_merge($this->additionalFields, [
82 'serverURL' => $this->serverURL,
83 'loginUsername' => $this->loginUsername,
84 'loginPassword' => $this->loginPassword
85 ])]);
86 $this->objectAction->executeAction();
87 $this->saved();
88
89 // reset values
90 $this->serverURL = $this->loginUsername = $this->loginPassword = '';
91
92 // show success message
93 WCF::getTPL()->assign('success', true);
94 }
95
96 /**
97 * @inheritDoc
98 */
99 public function assignVariables() {
100 parent::assignVariables();
101
102 WCF::getTPL()->assign([
103 'serverURL' => $this->serverURL,
104 'loginUsername' => $this->loginUsername,
105 'loginPassword' => $this->loginPassword,
106 'action' => 'add'
107 ]);
108 }
109
110 /**
111 * @inheritDoc
112 */
113 public function show() {
114 // check master password
115 WCFACP::checkMasterPassword();
116
117 parent::show();
118 }
119 }