Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
*6071* Duplicate "crossref" plugins create conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrandel committed Oct 30, 2010
1 parent b951f67 commit f5c9070
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 192 deletions.
2 changes: 2 additions & 0 deletions locale/en_US/manager.xml
Expand Up @@ -98,6 +98,8 @@
<message key="manager.plugins.installFailed">Installation failed</message>
<message key="manager.plugins.installSuccessful">Successfully installed version</message>
<message key="manager.plugins.invalidPluginArchive">The uploaded plugin archive does not contain a folder that corresponds to the plugin name.</message>
<message key="manager.plugins.wrongCategory">The uploaded plugin does not fit the category of the upgraded plugin.</message>
<message key="manager.plugins.wrongName">The version.xml in the uploaded plugin contains a plugin name that does not fit the name of the upgraded plugin.</message>
<message key="manager.plugins.pleaseInstall">Plugin does not exist. Please Install instead</message>
<message key="manager.plugins.pleaseUpgrade">Plugin already exists, but is newer than installed version. Please upgrade instead</message>
<message key="manager.plugins.tarCommandNotFound">The tar command is not available. Please correctly configure it in your "config.inc.php".</message>
Expand Down
11 changes: 5 additions & 6 deletions pages/manager/PluginHandler.inc.php
Expand Up @@ -12,7 +12,6 @@
* @brief Handle requests for plugin management functions.
*/

//$Id$

import('pages.manager.ManagerHandler');

Expand All @@ -38,7 +37,7 @@ function plugins($args) {
// get the plugins in that category only.
$mainPage = false;
$plugins =& PluginRegistry::loadCategory($category);

$this->setupTemplate(false);
$templateMgr->assign('pageTitle', 'plugins.categories.' . $category);
$templateMgr->assign('pageHierarchy', PluginHandler::setBreadcrumbs(true));
Expand All @@ -52,14 +51,14 @@ function plugins($args) {
$plugins = array_merge($plugins, PluginRegistry::loadCategory($category));
}
}

$this->setupTemplate(true);
$templateMgr->assign('pageTitle', 'manager.plugins.pluginManagement');
$templateMgr->assign('pageHierarchy', PluginHandler::setBreadcrumbs(false));
}



$templateMgr->assign_by_ref('plugins', $plugins);
$templateMgr->assign_by_ref('categories', $categories);
$templateMgr->assign('mainPage', $mainPage);
Expand Down Expand Up @@ -93,7 +92,7 @@ function plugin($args, &$request) {
$request->redirect(null, null, null, 'plugins', array($category));
}
}

/**
* Set the page's breadcrumbs
* @param $subclass boolean
Expand All @@ -112,7 +111,7 @@ function setBreadcrumbs($subclass = false) {
false
)
);

if ($subclass) {
$pageCrumbs[] = array(
Request::url(null, null, 'manager', 'plugins'),
Expand Down
91 changes: 46 additions & 45 deletions pages/manager/PluginManagementHandler.inc.php
Expand Up @@ -37,7 +37,8 @@ function PluginManagementHandler() {
function managePlugins($args) {
$this->validate();
$path = isset($args[0])?$args[0]:null;
$plugin = isset($args[1])?$args[1]:null;
$category = isset($args[1])?$args[1]:null;
$plugin = isset($args[2])?$args[2]:null;

switch($path) {
case 'install':
Expand All @@ -47,16 +48,16 @@ function managePlugins($args) {
$this->uploadPlugin('install');
break;
case 'upgrade':
$this->showUpgradeForm($plugin);
$this->showUpgradeForm($category, $plugin);
break;
case 'upgradePlugin':
$this->uploadPlugin('upgrade');
$this->uploadPlugin('upgrade', $category, $plugin);
break;
case 'delete':
$this->showDeleteForm($plugin);
$this->showDeleteForm($category, $plugin);
break;
case 'deletePlugin':
$this->deletePlugin($plugin);
$this->deletePlugin($category, $plugin);
break;
default:
Request::redirect(null, 'manager', 'plugins');
Expand Down Expand Up @@ -84,38 +85,38 @@ function showInstallForm() {

/**
* Show form to select plugin for upgrade.
* @param plugin string
* @param $category string
* @param $plugin string
*/
function showUpgradeForm($plugin) {
function showUpgradeForm($category, $plugin) {
$this->validate();
$templateMgr =& TemplateManager::getManager();
$this->setupTemplate(true);

$templateMgr->assign('path', 'upgrade');
$templateMgr->assign('category', $category);
$templateMgr->assign('plugin', $plugin);
$templateMgr->assign('uploaded', false);

$category = $this->_getPluginCategory($plugin);
$templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true, $category));

$templateMgr->display('manager/plugins/managePlugins.tpl');
}

/**
* Confirm deletion of plugin.
* @param plugin string
* @param $category string
* @param $plugin string
*/
function showDeleteForm($plugin) {
function showDeleteForm($category, $plugin) {
$this->validate();
$templateMgr =& TemplateManager::getManager();
$this->setupTemplate(true);

$templateMgr->assign('path', 'delete');
$templateMgr->assign('category', $category);
$templateMgr->assign('plugin', $plugin);
$templateMgr->assign('deleted', false);
$templateMgr->assign('error', false);

$category = $this->_getPluginCategory($plugin);
$templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true, $category));

$templateMgr->display('manager/plugins/managePlugins.tpl');
Expand All @@ -124,17 +125,18 @@ function showDeleteForm($plugin) {

/**
* Decompress uploaded plugin and install in the correct plugin directory.
* $param function string type of operation to perform after upload ('upgrade' or 'install')
* @param $function string type of operation to perform after upload ('upgrade' or 'install')
* @param $category string the category of the uploaded plugin (upgrade only)
* @param $plugin string the name of the uploaded plugin (upgrade only)
*/
function uploadPlugin($function) {
function uploadPlugin($function, $category = null, $plugin = null) {
$this->validate();
$templateMgr =& TemplateManager::getManager();
$this->setupTemplate(true);

$templateMgr->assign('error', false);
$templateMgr->assign('uploaded', false);
$templateMgr->assign('path', $function);
$templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true));

$errorMsg = '';
if (Request::getUserVar('uploadPlugin')) {
Expand Down Expand Up @@ -178,7 +180,7 @@ function uploadPlugin($function) {
if ($function == 'install') {
$this->installPlugin($pluginDir, $templateMgr);
} else if ($function == 'upgrade') {
$this->upgradePlugin($pluginDir, $templateMgr);
$this->upgradePlugin($pluginDir, $templateMgr, $category, $plugin);
}
} else {
$errorMsg = 'manager.plugins.invalidPluginArchive';
Expand All @@ -203,14 +205,14 @@ function installPlugin($path, &$templateMgr) {
$this->validate();
$versionFile = $path . VERSION_FILE;
$templateMgr->assign('error', true);
$templateMgr->assign('path', 'install');
$templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true));

$pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
if (is_null($pluginVersion)) return false;
assert(is_a($pluginVersion, 'Version'));

$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProduct(), true);
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);

if(!$installedPlugin) {
$pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . strtr($pluginVersion->getProductType(), '.', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pluginVersion->getProduct();
Expand Down Expand Up @@ -243,7 +245,7 @@ function installPlugin($path, &$templateMgr) {
$versionDao->insertVersion($pluginVersion, true);
return true;
} else {
if ($this->_checkIfNewer($pluginVersion->getProduct(), $pluginVersion)) {
if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
$templateMgr->assign('message', 'manager.plugins.pleaseUpgrade');
return false;
} else {
Expand All @@ -257,26 +259,38 @@ function installPlugin($path, &$templateMgr) {
* Upgrade a plugin to a newer version from the user's filesystem
* @param $path string path to plugin Directory
* @param $templateMgr reference to template manager
* @param $category string
* @param $plugin string
* @return boolean
*/
function upgradePlugin($path, &$templateMgr) {
function upgradePlugin($path, &$templateMgr, $category, $plugin) {
$this->validate();
$versionFile = $path . VERSION_FILE;
$templateMgr->assign('error', true);
$templateMgr->assign('path', 'upgrade');
$templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true, $category));

$pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
if (is_null($pluginVersion)) return false;
assert(is_a($pluginVersion, 'Version'));

// Check whether the uploaded plug-in fits the original plug-in.
if ('plugins.'.$category != $pluginVersion->getProductType()) {
$templateMgr->assign('message', 'manager.plugins.wrongCategory');
return false;
}
if ($plugin != $pluginVersion->getProduct()) {
$templateMgr->assign('message', 'manager.plugins.wrongName');
return false;
}

$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProduct(), true);
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
if(!$installedPlugin) {
$templateMgr->assign('message', 'manager.plugins.pleaseInstall');
return false;
}

if ($this->_checkIfNewer($pluginVersion->getProduct(), $pluginVersion)) {
if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
$templateMgr->assign('message', 'manager.plugins.installedVersionNewer');
return false;
} else {
Expand Down Expand Up @@ -317,9 +331,10 @@ function upgradePlugin($path, &$templateMgr) {

/**
* Delete a plugin from the system
* @param plugin string
* @param $category string
* @param $plugin string
*/
function deletePlugin($plugin) {
function deletePlugin($category, $plugin) {
$this->validate();
$templateMgr =& TemplateManager::getManager();
$this->setupTemplate(true);
Expand All @@ -329,8 +344,7 @@ function deletePlugin($plugin) {
$templateMgr->assign('error', false);

$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($plugin, true);
$category = $this->_getPluginCategory($plugin);
$installedPlugin = $versionDao->getCurrentVersion('plugins.'.$category, $plugin, true);

if ($installedPlugin) {
$pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $plugin;
Expand Down Expand Up @@ -359,13 +373,14 @@ function deletePlugin($plugin) {

/**
* Checks to see if local version of plugin is newer than installed version
* @param $pluginName string Product name of plugin
* @param $productType string Product type of plugin
* @param $productName string Product name of plugin
* @param $newVersion Version Version object of plugin to check against database
* @return boolean
*/
function _checkIfNewer($pluginName, $newVersion) {
function _checkIfNewer($productType, $productName, $newVersion) {
$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginName, true);
$installedPlugin = $versionDao->getCurrentVersion($productType, $productName, true);

if (!$installedPlugin) return false;
if ($installedPlugin->compare($newVersion) > 0) return true;
Expand Down Expand Up @@ -411,20 +426,6 @@ function setBreadcrumbs($subclass = false, $category = null) {
return $pageCrumbs;
}

/**
* Get the plugin category from the version.
* @param string
* @return string
*/
function _getPluginCategory($plugin) {
$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($plugin, true);
if ($installedPlugin) {
$productType = explode(".", $installedPlugin->getProductType());
return $productType[1];
} else return false;
}

/**
* Load database connection parameters into an array (needed for upgrade).
* @return array
Expand Down

0 comments on commit f5c9070

Please sign in to comment.