Piwik\Plugin\Manager::uninstallPlugin PHP Method

uninstallPlugin() public method

Uninstalls a Plugin (deletes plugin files from the disk) Only deactivated plugins can be uninstalled
public uninstallPlugin ( $pluginName ) : boolean
$pluginName
return boolean
    public function uninstallPlugin($pluginName)
    {
        if ($this->isPluginLoaded($pluginName)) {
            throw new \Exception("To uninstall the plugin {$pluginName}, first disable it in Piwik > Settings > Plugins");
        }
        $this->loadAllPluginsAndGetTheirInfo();
        SettingsStorage\Backend\PluginSettingsTable::removeAllSettingsForPlugin($pluginName);
        SettingsStorage\Backend\MeasurableSettingsTable::removeAllSettingsForPlugin($pluginName);
        $this->executePluginDeactivate($pluginName);
        $this->executePluginUninstall($pluginName);
        $this->removePluginFromPluginsInstalledConfig($pluginName);
        $this->unloadPluginFromMemory($pluginName);
        $this->removePluginFromConfig($pluginName);
        $this->removeInstalledVersionFromOptionTable($pluginName);
        $this->clearCache($pluginName);
        self::deletePluginFromFilesystem($pluginName);
        if ($this->isPluginInFilesystem($pluginName)) {
            return false;
        }
        /**
         * Event triggered after a plugin has been uninstalled.
         *
         * @param string $pluginName The plugin that has been uninstalled.
         */
        Piwik::postEvent('PluginManager.pluginUninstalled', array($pluginName));
        return true;
    }

Usage Example

Example #1
0
 public function uninstall($redirectAfter = true)
 {
     $pluginName = $this->initPluginModification(static::UNINSTALL_NONCE);
     $this->dieIfPluginsAdminIsDisabled();
     $uninstalled = $this->pluginManager->uninstallPlugin($pluginName);
     if (!$uninstalled) {
         $path = Filesystem::getPathToPiwikRoot() . '/plugins/' . $pluginName . '/';
         $messagePermissions = Filechecks::getErrorMessageMissingPermissions($path);
         $messageIntro = $this->translator->translate("Warning: \"%s\" could not be uninstalled. Piwik did not have enough permission to delete the files in {$path}. ", $pluginName);
         $exitMessage = $messageIntro . "<br/><br/>" . $messagePermissions;
         $exitMessage .= "<br> Or manually delete this directory (using FTP or SSH access)";
         $ex = new MissingFilePermissionException($exitMessage);
         $ex->setIsHtmlMessage();
         throw $ex;
     }
     $this->redirectAfterModification($redirectAfter);
 }
Manager