2 namespace wcf\data\package\installation\plugin;
3 use wcf\data\devtools\project\DevtoolsProject;
4 use wcf\data\option\OptionEditor;
5 use wcf\data\AbstractDatabaseObjectAction;
6 use wcf\system\cache\CacheHandler;
7 use wcf\system\devtools\pip\DevtoolsPackageInstallationDispatcher;
8 use wcf\system\devtools\pip\DevtoolsPip;
9 use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin;
10 use wcf\system\exception\PermissionDeniedException;
11 use wcf\system\exception\UserInputException;
12 use wcf\system\language\LanguageFactory;
13 use wcf\system\package\plugin\OptionPackageInstallationPlugin;
14 use wcf\system\package\SplitNodeException;
15 use wcf\system\search\SearchIndexManager;
16 use wcf\system\version\VersionTracker;
20 * Executes package installation plugin-related actions.
22 * @author Alexander Ebert
23 * @copyright 2001-2017 WoltLab GmbH
24 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 * @package WoltLabSuite\Core\Data\Package\Installation\Plugin
27 * @method PackageInstallationPlugin create()
28 * @method PackageInstallationPluginEditor[] getObjects()
29 * @method PackageInstallationPluginEditor getSingleObject()
31 class PackageInstallationPluginAction extends AbstractDatabaseObjectAction {
35 protected $className = PackageInstallationPluginEditor::class;
40 protected $requireACP = ['invoke'];
48 * @var PackageInstallationPlugin
50 public $packageInstallationPlugin;
53 * @var DevtoolsProject
58 * Validates parameters to invoke a single PIP.
60 * @throws PermissionDeniedException
61 * @throws UserInputException
63 public function validateInvoke() {
64 if (!ENABLE_DEVELOPER_TOOLS || !WCF::getSession()->getPermission('admin.configuration.package.canInstallPackage')) {
65 throw new PermissionDeniedException();
68 $this->readString('pluginName');
69 $this->readInteger('projectID');
70 $this->readString('target');
72 $this->project = new DevtoolsProject($this->parameters['projectID']);
73 if (!$this->project->projectID || $this->project->validate() !== '') {
74 throw new UserInputException('projectID');
77 $this->packageInstallationPlugin = new PackageInstallationPlugin($this->parameters['pluginName']);
78 if (!$this->packageInstallationPlugin->pluginName) {
79 throw new UserInputException('pluginName');
82 $this->devtoolsPip = new DevtoolsPip($this->packageInstallationPlugin);
83 $targets = $this->devtoolsPip->getTargets($this->project);
84 if (!in_array($this->parameters['target'], $targets)) {
85 throw new UserInputException('target');
90 * Invokes a single PIP and returns the time needed to process it.
94 public function invoke() {
95 $dispatcher = new DevtoolsPackageInstallationDispatcher($this->project);
96 /** @var IIdempotentPackageInstallationPlugin $pip */
97 $pip = new $this->packageInstallationPlugin->className(
99 $this->devtoolsPip->getInstructions($this->project, $this->parameters['target'])
102 $start = microtime(true);
107 catch (SplitNodeException $e) {
108 throw new \RuntimeException("PIP '{$this->packageInstallationPlugin->pluginName}' is not allowed to throw a 'SplitNodeException'.");
113 // TODO: use a central method instead!
115 // create search index tables
116 SearchIndexManager::getInstance()->createSearchIndices();
118 VersionTracker::getInstance()->createStorageTables();
120 CacheHandler::getInstance()->flushAll();
122 if ($pip instanceof OptionPackageInstallationPlugin) {
123 OptionEditor::resetCache();
126 if ($this->packageInstallationPlugin->pluginName === 'language') {
127 LanguageFactory::getInstance()->clearCache();
128 LanguageFactory::getInstance()->deleteLanguageCache();
132 'pluginName' => $this->packageInstallationPlugin->pluginName,
133 'target' => $this->parameters['target'],
134 'timeElapsed' => WCF::getLanguage()->getDynamicVariable('wcf.acp.devtools.sync.status.success', ['timeElapsed' => round(microtime(true) - $start, 3)])