Piwik\Plugin\Dependency::hasDependencyToDisabledPlugin PHP Method

hasDependencyToDisabledPlugin() public method

public hasDependencyToDisabledPlugin ( $requires )
    public function hasDependencyToDisabledPlugin($requires)
    {
        if (empty($requires)) {
            return false;
        }
        foreach ($requires as $name => $requiredVersion) {
            $nameLower = strtolower($name);
            $isPluginRequire = !in_array($nameLower, array('piwik', 'php'));
            if ($isPluginRequire) {
                // we do not check version, only whether it's activated. Everything that is not piwik or php is assumed
                // a plugin so far.
                if (!PluginManager::getInstance()->isPluginActivated($name)) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Example #1
0
 public function installAllPaidPlugins()
 {
     Piwik::checkUserHasSuperUserAccess();
     $this->dieIfPluginsAdminIsDisabled();
     Plugin\ControllerAdmin::displayWarningIfConfigFileNotWritable();
     Nonce::checkNonce(static::INSTALL_NONCE);
     $paidPlugins = $this->plugins->getAllPaidPlugins();
     $hasErrors = false;
     foreach ($paidPlugins as $paidPlugin) {
         if (!$this->canPluginBeInstalled($paidPlugin)) {
             continue;
         }
         $pluginName = $paidPlugin['name'];
         try {
             $this->pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName);
         } catch (\Exception $e) {
             $notification = new Notification($e->getMessage());
             $notification->context = Notification::CONTEXT_ERROR;
             Notification\Manager::notify('Marketplace_Install' . $pluginName, $notification);
             $hasErrors = true;
         }
     }
     if ($hasErrors) {
         Url::redirectToReferrer();
         return;
     }
     $dependency = new Plugin\Dependency();
     for ($i = 0; $i <= 10; $i++) {
         foreach ($paidPlugins as $index => $paidPlugin) {
             $pluginName = $paidPlugin['name'];
             if ($this->pluginManager->isPluginActivated($pluginName)) {
                 unset($paidPlugins[$index]);
                 continue;
             }
             if (empty($paidPlugin['require']) || !$dependency->hasDependencyToDisabledPlugin($paidPlugin['require'])) {
                 unset($paidPlugins[$index]);
                 try {
                     $this->pluginManager->activatePlugin($pluginName);
                 } catch (Exception $e) {
                     $hasErrors = true;
                     $notification = new Notification($e->getMessage());
                     $notification->context = Notification::CONTEXT_ERROR;
                     Notification\Manager::notify('Marketplace_Install' . $pluginName, $notification);
                 }
             }
         }
     }
     if ($hasErrors) {
         $notification = new Notification(Piwik::translate('Marketplace_OnlySomePaidPluginsInstalledAndActivated'));
         $notification->context = Notification::CONTEXT_INFO;
     } else {
         $notification = new Notification(Piwik::translate('Marketplace_AllPaidPluginsInstalledAndActivated'));
         $notification->context = Notification::CONTEXT_SUCCESS;
     }
     Notification\Manager::notify('Marketplace_InstallAll', $notification);
     Url::redirectToReferrer();
 }