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;
18 * Executes package installation plugin-related actions.
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
25 * @method PackageInstallationPlugin create()
26 * @method PackageInstallationPluginEditor[] getObjects()
27 * @method PackageInstallationPluginEditor getSingleObject()
29 class PackageInstallationPluginAction extends AbstractDatabaseObjectAction {
33 protected $className = PackageInstallationPluginEditor::class;
38 protected $requireACP = ['invoke'];
46 * @var PackageInstallationPlugin
48 public $packageInstallationPlugin;
51 * @var DevtoolsProject
55 public function validateInvoke() {
56 if (!ENABLE_DEVELOPER_TOOLS || !WCF::getSession()->getPermission('admin.configuration.package.canInstallPackage')) {
57 throw new PermissionDeniedException();
60 $this->readString('pluginName');
61 $this->readInteger('projectID');
62 $this->readString('target');
64 $this->project = new DevtoolsProject($this->parameters['projectID']);
65 if (!$this->project->projectID || $this->project->validate() !== '') {
66 throw new UserInputException('projectID');
69 $this->packageInstallationPlugin = new PackageInstallationPlugin($this->parameters['pluginName']);
70 if (!$this->packageInstallationPlugin->pluginName) {
71 throw new UserInputException('pluginName');
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');
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'])
91 catch (SplitNodeException $e) {
92 throw new \RuntimeException("PIP '{$this->packageInstallationPlugin->pluginName}' is not allowed to throw a 'SplitNodeException'.");
97 // TODO: use a central method instead!
99 // create search index tables
100 SearchIndexManager::getInstance()->createSearchIndices();
102 VersionTracker::getInstance()->createStorageTables();
104 CacheHandler::getInstance()->flushAll();