Piwik\Plugins\CorePluginsAdmin\PluginInstaller::installOrUpdatePluginFromFile PHP Method

installOrUpdatePluginFromFile() public method

public installOrUpdatePluginFromFile ( $pathToZip )
    public function installOrUpdatePluginFromFile($pathToZip)
    {
        $tmpPluginName = 'uploaded' . Common::generateUniqId();
        $tmpPluginFolder = StaticContainer::get('path.tmp') . self::PATH_TO_DOWNLOAD . $tmpPluginName;
        try {
            $this->makeSureFoldersAreWritable();
            $this->extractPluginFiles($pathToZip, $tmpPluginFolder);
            $this->makeSurePluginJsonExists($tmpPluginFolder);
            $metadata = $this->getPluginMetadataIfValid($tmpPluginFolder);
            $this->makeSureThereAreNoMissingRequirements($metadata);
            $this->pluginName = $metadata->name;
            $this->fixPluginFolderIfNeeded($tmpPluginFolder);
            $this->copyPluginToDestination($tmpPluginFolder);
            Filesystem::deleteAllCacheOnUpdate($this->pluginName);
        } catch (\Exception $e) {
            $this->removeFileIfExists($pathToZip);
            $this->removeFolderIfExists($tmpPluginFolder);
            throw $e;
        }
        $this->removeFileIfExists($pathToZip);
        $this->removeFolderIfExists($tmpPluginFolder);
        return $metadata;
    }

Usage Example

Exemplo 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();
 }