3 namespace wcf\acp\form
;
5 use wcf\data\package\update\server\PackageUpdateServer
;
6 use wcf\data\package\update\server\PackageUpdateServerAction
;
7 use wcf\data\package\update\server\PackageUpdateServerList
;
8 use wcf\form\AbstractForm
;
9 use wcf\system\exception\UserInputException
;
10 use wcf\system\request\LinkHandler
;
12 use wcf\system\WCFACP
;
13 use wcf\util\StringUtil
;
17 * Shows the server add form.
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package WoltLabSuite\Core\Acp\Form
24 class PackageUpdateServerAddForm
extends AbstractForm
29 public $activeMenuItem = 'wcf.acp.menu.link.package.server.add';
34 public $neededPermissions = ['admin.configuration.package.canEditServer'];
40 public $serverURL = '';
43 * server login username
46 public $loginUsername = '';
49 * server login password
52 public $loginPassword = '';
57 public function readFormParameters()
59 parent
::readFormParameters();
61 if (isset($_POST['serverURL'])) {
62 $this->serverURL
= StringUtil
::trim($_POST['serverURL']);
64 if (isset($_POST['loginUsername'])) {
65 $this->loginUsername
= $_POST['loginUsername'];
67 if (isset($_POST['loginPassword'])) {
68 $this->loginPassword
= $_POST['loginPassword'];
75 public function validate()
79 $this->validateServerURL();
83 * Validates the server URL.
87 protected function validateServerURL()
89 if (empty($this->serverURL
)) {
90 throw new UserInputException('serverURL');
93 if (!PackageUpdateServer
::isValidServerURL($this->serverURL
)) {
94 throw new UserInputException('serverURL', 'invalid');
97 if (StringUtil
::endsWith(Url
::parse($this->serverURL
)['host'], '.woltlab.com', true)) {
98 throw new UserInputException('serverURL', 'woltlab');
101 if (($duplicate = $this->findDuplicateServer())) {
102 throw new UserInputException('serverURL', [
103 'duplicate' => $duplicate,
109 * Returns the first package update server with a matching serverURL.
113 protected function findDuplicateServer()
115 $packageServerList = new PackageUpdateServerList();
116 $packageServerList->readObjects();
117 foreach ($packageServerList as $packageServer) {
118 if ($packageServer->serverURL
== $this->serverURL
) {
119 return $packageServer;
127 public function save()
132 $this->objectAction
= new PackageUpdateServerAction([], 'create', [
133 'data' => \array_merge
($this->additionalFields
, [
134 'serverURL' => $this->serverURL
,
135 'loginUsername' => $this->loginUsername
,
136 'loginPassword' => $this->loginPassword
,
139 $returnValues = $this->objectAction
->executeAction();
143 $this->serverURL
= $this->loginUsername
= $this->loginPassword
= '';
145 // show success message
146 WCF
::getTPL()->assign([
148 'objectEditLink' => LinkHandler
::getInstance()->getControllerLink(
149 PackageUpdateServerEditForm
::class,
150 ['id' => $returnValues['returnValues']->packageUpdateServerID
]
158 public function assignVariables()
160 parent
::assignVariables();
162 WCF
::getTPL()->assign([
163 'serverURL' => $this->serverURL
,
164 'loginUsername' => $this->loginUsername
,
165 'loginPassword' => $this->loginPassword
,
173 public function show()
175 // check master password
176 WCFACP
::checkMasterPassword();