7c7beabb5188a8dc3ae0363ddbaa3fb6120cbdce
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\data\package\installation\plugin;
3 use wcf\data\AbstractDatabaseObjectAction;
4 use wcf\data\devtools\project\DevtoolsProject;
5 use wcf\system\cache\CacheHandler;
6 use wcf\system\devtools\pip\DevtoolsPackageInstallationDispatcher;
7 use wcf\system\devtools\pip\DevtoolsPip;
8 use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin;
9 use wcf\system\exception\PermissionDeniedException;
10 use wcf\system\exception\UserInputException;
11 use wcf\system\package\plugin\IPackageInstallationPlugin;
12 use wcf\system\package\SplitNodeException;
13 use wcf\system\search\SearchIndexManager;
14 use wcf\system\version\VersionTracker;
15 use wcf\system\WCF;
16
17 /**
18 * Executes package installation plugin-related actions.
19 *
20 * @author Alexander Ebert
21 * @copyright 2001-2017 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @package WoltLabSuite\Core\Data\Package\Installation\Plugin
24 *
25 * @method PackageInstallationPlugin create()
26 * @method PackageInstallationPluginEditor[] getObjects()
27 * @method PackageInstallationPluginEditor getSingleObject()
28 */
29 class PackageInstallationPluginAction extends AbstractDatabaseObjectAction {
30 /**
31 * @inheritDoc
32 */
33 protected $className = PackageInstallationPluginEditor::class;
34
35 /**
36 * @inheritDoc
37 */
38 protected $requireACP = ['invoke'];
39
40 /**
41 * @var DevtoolsPip
42 */
43 public $devtoolsPip;
44
45 /**
46 * @var PackageInstallationPlugin
47 */
48 public $packageInstallationPlugin;
49
50 /**
51 * @var DevtoolsProject
52 */
53 public $project;
54
55 public function validateInvoke() {
56 if (!ENABLE_DEVELOPER_TOOLS || !WCF::getSession()->getPermission('admin.configuration.package.canInstallPackage')) {
57 throw new PermissionDeniedException();
58 }
59
60 $this->readString('pluginName');
61 $this->readInteger('projectID');
62 $this->readString('target');
63
64 $this->project = new DevtoolsProject($this->parameters['projectID']);
65 if (!$this->project->projectID || $this->project->validate() !== '') {
66 throw new UserInputException('projectID');
67 }
68
69 $this->packageInstallationPlugin = new PackageInstallationPlugin($this->parameters['pluginName']);
70 if (!$this->packageInstallationPlugin->pluginName) {
71 throw new UserInputException('pluginName');
72 }
73
74 $this->devtoolsPip = new DevtoolsPip($this->packageInstallationPlugin);
75 $targets = $this->devtoolsPip->getTargets($this->project);
76 if (!in_array($this->parameters['target'], $targets)) {
77 throw new UserInputException('target');
78 }
79 }
80
81 public function invoke() {
82 $dispatcher = new DevtoolsPackageInstallationDispatcher($this->project);
83 /** @var IIdempotentPackageInstallationPlugin $pip */
84 $pip = new $this->packageInstallationPlugin->className($dispatcher, [
85 'value' => $this->devtoolsPip->getInstructionValue($this->project, $this->parameters['target'])
86 ]);
87
88 try {
89 $pip->update();
90 }
91 catch (SplitNodeException $e) {
92 throw new \RuntimeException("PIP '{$this->packageInstallationPlugin->pluginName}' is not allowed to throw a 'SplitNodeException'.");
93 }
94
95 // clear cache
96
97 // TODO: use a central method instead!
98
99 // create search index tables
100 SearchIndexManager::getInstance()->createSearchIndices();
101
102 VersionTracker::getInstance()->createStorageTables();
103
104 CacheHandler::getInstance()->flushAll();
105 }
106 }