Exemplo n.º 1
0
     }
     $aPackageInfo['package'] = true;
     $oTpl->assign('aPackage', $aPackageInfo);
     $oTpl->assign('aPlugins', $aComponents);
     $oTpl->assign('uninstallReadme', $uninstallReadme);
     $oTpl->assign('backURL', MAX::constructURL(MAX_URL_ADMIN, "plugin-index.php?selection=packages"));
 } else {
     if (array_key_exists('uninstallConfirmed', $_POST)) {
         $oPluginManager->uninstallPackage($plugin);
         if (!($oPluginManager->countErrors() || $oPluginManager->countWarnings())) {
             OX_Admin_Redirect::redirect('plugin-index.php');
         }
     } else {
         if ('enable' == $action) {
             if ($plugin) {
                 $oPluginManager->enablePackage($plugin);
             }
             if (!($oPluginManager->countErrors() || $oPluginManager->countWarnings())) {
                 OX_Admin_Redirect::redirect('plugin-index.php');
             }
         } else {
             if ('disable' == $action) {
                 if ($plugin) {
                     $oPluginManager->disablePackage($plugin);
                 } else {
                     if ($group) {
                         $oComponentGroupManager->disableComponentGroup($group);
                     }
                 }
                 if (!($oPluginManager->countErrors() || $oPluginManager->countWarnings())) {
                     require_once LIB_PATH . '/Admin/Redirect.php';
Exemplo n.º 2
0
function checkPlugin($pluginName)
{
    $aErrors = array();
    $aResult = array('name' => $pluginName, 'status' => '', 'errors' => &$aErrors);
    require_once LIB_PATH . '/Plugin/PluginManager.php';
    $oPluginManager = new OX_PluginManager();
    // if plugin definition is not found in situ
    // try to import plugin code from the previous installation
    if (!file_exists(MAX_PATH . $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] . $pluginName . '.xml')) {
        if (isset($GLOBALS['_MAX']['CONF']['pluginPaths']['export'])) {
            $file = $GLOBALS['_MAX']['CONF']['pluginPaths']['export'] . $pluginName . '.zip';
            if (file_exists($file)) {
                $aFile['name'] = $file;
                $aFile['tmp_name'] = $file;
                $aErrors[] = 'Exported plugin file found, attempting to import from ' . $file;
                if (!$oPluginManager->installPackageCodeOnly($aFile)) {
                    if ($oPluginManager->countErrors()) {
                        $aResult['status'] = 'Failed';
                        foreach ($oPluginManager->aErrors as $errmsg) {
                            $aErrors[] = $errmsg;
                        }
                    }
                } else {
                    $aResult['status'] = 'OK';
                }
            }
        }
    }
    // Try to upgrade bundled plugins
    include_once MAX_PATH . '/etc/default_plugins.php';
    if ($aDefaultPlugins) {
        foreach ($aDefaultPlugins as $idx => $aPlugin) {
            if ($aPlugin['name'] == $pluginName) {
                $upgraded = false;
                $oPluginManager = new OX_PluginManager();
                $aFileName['name'] = $aPlugin['name'] . '.' . $aPlugin['ext'];
                $aFileName['tmp_name'] = $aPlugin['path'] . $aPlugin['name'] . '.' . $aPlugin['ext'];
                $aFileName['type'] = 'application/zip';
                $upgraded = $oPluginManager->upgradePackage($aFileName, $pluginName);
                if (!empty($oPluginManager->aErrors) && !empty($oPluginManager->previousVersionInstalled) && $oPluginManager->previousVersionInstalled != OX_PLUGIN_SAME_VERSION_INSTALLED) {
                    foreach ($oPluginManager->aErrors as $i => $msg) {
                        $aErrors[] = $msg;
                    }
                }
            }
        }
    }
    // now diagnose problems
    $aDiag = $oPluginManager->getPackageDiagnostics($pluginName);
    if ($aDiag['plugin']['error']) {
        $aErrors[] = 'Problems found with plugin ' . $pluginName . '.  The plugin has been disabled.  Go to the Configuration Plugins page for details ';
        foreach ($aDiag['plugin']['errors'] as $i => $msg) {
            $aErrors[] = $msg;
        }
    }
    foreach ($aDiag['groups'] as $idx => &$aGroup) {
        if ($aGroup['error']) {
            $aDiag['plugin']['error'] = true;
            $aErrors[] = 'Problems found with components in group ' . $aGroup['name'] . '.  The ' . $pluginName . ' plugin has been disabled.  Go to the Configuration->Plugins page for details ';
            foreach ($aGroup['errors'] as $i => $msg) {
                $aErrors[] = $msg;
            }
        }
    }
    $enabled = wasPluginEnabled($pluginName);
    // original setting
    if (!$aDiag['plugin']['error']) {
        if ($upgraded) {
            $aResult['status'] .= 'OK, Upgraded';
        } elseif ($oPluginManager->previousVersionInstalled == OX_PLUGIN_NEWER_VERSION_INSTALLED) {
            $aResult['status'] .= 'OK. Notice: You have a newer plugin version installed than the one that comes with this upgrade package.';
        } elseif ($oPluginManager->previousVersionInstalled == OX_PLUGIN_SAME_VERSION_INSTALLED) {
            $aResult['status'] .= 'OK, Up to date';
        } else {
            $aResult['status'] .= 'OK';
        }
        if ($enabled) {
            if ($oPluginManager->enablePackage($pluginName)) {
                $aResult['status'] .= ', Enabled';
            } else {
                $aResult['status'] .= ', failed to enable, check plugin configuration';
            }
        } else {
            $aResult['status'] .= ', Disabled';
        }
    } else {
        $aResult['status'] = 'Errors, disabled';
    }
    return $aResult;
}