installOrUpdatePluginFromFile() public method

public installOrUpdatePluginFromFile ( $pathToZip )
Esempio n. 1
0
 public function uploadPlugin()
 {
     static::dieIfPluginsAdminIsDisabled();
     Piwik::checkUserHasSuperUserAccess();
     $nonce = Common::getRequestVar('nonce', null, 'string');
     if (!Nonce::verifyNonce(MarketplaceController::INSTALL_NONCE, $nonce)) {
         throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch'));
     }
     Nonce::discardNonce(MarketplaceController::INSTALL_NONCE);
     if (empty($_FILES['pluginZip'])) {
         throw new \Exception('You did not specify a ZIP file.');
     }
     if (!empty($_FILES['pluginZip']['error'])) {
         throw new \Exception('Something went wrong during the plugin file upload. Please try again.');
     }
     $file = $_FILES['pluginZip']['tmp_name'];
     if (!file_exists($file)) {
         throw new \Exception('Something went wrong during the plugin file upload. Please try again.');
     }
     $view = $this->configureView('@CorePluginsAdmin/uploadPlugin');
     $pluginMetadata = $this->pluginInstaller->installOrUpdatePluginFromFile($file);
     $view->nonce = Nonce::getNonce(static::ACTIVATE_NONCE);
     $view->plugin = array('name' => $pluginMetadata->name, 'version' => $pluginMetadata->version, 'isTheme' => !empty($pluginMetadata->theme), 'isActivated' => $this->pluginManager->isPluginActivated($pluginMetadata->name));
     return $view->render();
 }