2 declare(strict_types=1);
3 namespace wcf\data\package\installation\plugin;
4 use wcf\data\devtools\project\DevtoolsProject;
5 use wcf\data\option\OptionEditor;
6 use wcf\data\AbstractDatabaseObjectAction;
7 use wcf\system\cache\CacheHandler;
8 use wcf\system\devtools\pip\DevtoolsPackageInstallationDispatcher;
9 use wcf\system\devtools\pip\DevtoolsPip;
10 use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin;
11 use wcf\system\exception\PermissionDeniedException;
12 use wcf\system\exception\UserInputException;
13 use wcf\system\language\LanguageFactory;
14 use wcf\system\package\plugin\OptionPackageInstallationPlugin;
15 use wcf\system\package\SplitNodeException;
16 use wcf\system\search\SearchIndexManager;
17 use wcf\system\style\StyleHandler;
18 use wcf\system\version\VersionTracker;
22 * Executes package installation plugin-related actions.
24 * @author Alexander Ebert
25 * @copyright 2001-2018 WoltLab GmbH
26 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
27 * @package WoltLabSuite\Core\Data\Package\Installation\Plugin
29 * @method PackageInstallationPlugin create()
30 * @method PackageInstallationPluginEditor[] getObjects()
31 * @method PackageInstallationPluginEditor getSingleObject()
33 class PackageInstallationPluginAction extends AbstractDatabaseObjectAction {
37 protected $className = PackageInstallationPluginEditor::class;
42 protected $requireACP = ['invoke'];
50 * @var PackageInstallationPlugin
52 public $packageInstallationPlugin;
55 * @var DevtoolsProject
60 * Validates parameters to invoke a single PIP.
62 * @throws PermissionDeniedException
63 * @throws UserInputException
65 public function validateInvoke() {
66 if (!ENABLE_DEVELOPER_TOOLS || !WCF::getSession()->getPermission('admin.configuration.package.canInstallPackage')) {
67 throw new PermissionDeniedException();
70 $this->readString('pluginName');
71 $this->readInteger('projectID');
72 $this->readString('target');
74 $this->project = new DevtoolsProject($this->parameters['projectID']);
75 if (!$this->project->projectID || $this->project->validate() !== '') {
76 throw new UserInputException('projectID');
79 $this->packageInstallationPlugin = new PackageInstallationPlugin($this->parameters['pluginName']);
80 if (!$this->packageInstallationPlugin->pluginName) {
81 throw new UserInputException('pluginName');
84 $this->devtoolsPip = new DevtoolsPip($this->packageInstallationPlugin);
85 $targets = $this->devtoolsPip->getTargets($this->project);
86 if (!in_array($this->parameters['target'], $targets)) {
87 throw new UserInputException('target');
92 * Invokes a single PIP and returns the time needed to process it.
96 public function invoke() {
97 $dispatcher = new DevtoolsPackageInstallationDispatcher($this->project);
98 /** @var IIdempotentPackageInstallationPlugin $pip */
99 $pip = new $this->packageInstallationPlugin->className(
101 $this->devtoolsPip->getInstructions($this->project, $this->parameters['target'])
104 $start = microtime(true);
109 catch (SplitNodeException $e) {
110 throw new \RuntimeException("PIP '{$this->packageInstallationPlugin->pluginName}' is not allowed to throw a 'SplitNodeException'.");
115 // TODO: use a central method instead!
117 // create search index tables
118 SearchIndexManager::getInstance()->createSearchIndices();
120 VersionTracker::getInstance()->createStorageTables();
122 CacheHandler::getInstance()->flushAll();
124 if ($pip instanceof OptionPackageInstallationPlugin) {
125 OptionEditor::resetCache();
128 switch ($this->packageInstallationPlugin->pluginName) {
130 StyleHandler::resetStylesheets(false);
135 LanguageFactory::getInstance()->clearCache();
136 LanguageFactory::getInstance()->deleteLanguageCache();
141 case 'templateListener':
142 // resets the compiled templates
143 LanguageFactory::getInstance()->deleteLanguageCache();
148 'pluginName' => $this->packageInstallationPlugin->pluginName,
149 'target' => $this->parameters['target'],
150 'timeElapsed' => WCF::getLanguage()->getDynamicVariable('wcf.acp.devtools.sync.status.success', ['timeElapsed' => round(microtime(true) - $start, 3)])