Skip to content

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 24d7f16 commit 74c052f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
6 changes: 4 additions & 2 deletions classes/plugins/PKPPlugin.inc.php
Expand Up @@ -722,8 +722,10 @@ function smartyPluginUrl($params, &$smarty) {
*/
function getCurrentVersion() {
$versionDao =& DAORegistry::getDAO('VersionDAO');
$product = basename($this->getPluginPath());
$installedPlugin = $versionDao->getCurrentVersion($product, true);
$pluginPath = $this->getPluginPath();
$product = basename($pluginPath);
$category = basename(dirname($pluginPath));
$installedPlugin = $versionDao->getCurrentVersion('plugins.'.$category, $product, true);

if ($installedPlugin) {
return $installedPlugin;
Expand Down
37 changes: 21 additions & 16 deletions classes/site/VersionDAO.inc.php
Expand Up @@ -19,13 +19,15 @@
class VersionDAO extends DAO {
/**
* Retrieve the current version.
* @param $productType string
* @param $product string
* @param $isPlugin boolean
* @return Version
*/
function &getCurrentVersion($product = null, $isPlugin = false) {
if(!$product) {
function &getCurrentVersion($productType = null, $product = null, $isPlugin = false) {
if(!$productType || !$product) {
$application = PKPApplication::getApplication();
$productType = 'core';
$product = $application->getName();
}

Expand All @@ -47,17 +49,17 @@ function &getCurrentVersion($product = null, $isPlugin = false) {
}

if (!$returner) {
// From here on we can assume that we have the product
// column available in the versions table.
// From here on we can assume that we have the product type
// and product columns available in the versions table.
$result =& $this->retrieve(
'SELECT * FROM versions WHERE current = 1 AND product = ?',
array($product)
'SELECT * FROM versions WHERE current = 1 AND product_type = ? AND product = ?',
array($productType, $product)
);
$versionCount = $result->RecordCount();
if ($versionCount == 1) {
$returner =& $this->_returnVersionFromRow($result->GetRowAssoc(false));
} elseif ($versionCount >1) {
fatalError('More than one current version defined for the product "'.$product.'"!');
fatalError('More than one current version defined for the product type "'.$productType.'" and product "'.$product.'"!');
}
}

Expand All @@ -69,20 +71,22 @@ function &getCurrentVersion($product = null, $isPlugin = false) {

/**
* Retrieve the complete version history, ordered by date (most recent first).
* @param $productType string
* @param $product string
* @return array Versions
*/
function &getVersionHistory($product = null) {
function &getVersionHistory($productType = null, $product = null) {
$versions = array();

if(!$product) {
if(!$productType || !$product) {
$application = PKPApplication::getApplication();
$productType = 'core';
$product = $application->getName();
}

$result =& $this->retrieve(
'SELECT * FROM versions WHERE product = ? ORDER BY date_installed DESC',
array($product)
'SELECT * FROM versions WHERE product_type = ? AND product = ? ORDER BY date_installed DESC',
array($productType, $product)
);

while (!$result->EOF) {
Expand Down Expand Up @@ -124,14 +128,15 @@ function &_returnVersionFromRow(&$row) {
/**
* Insert a new version.
* @param $version Version
* @param $isPlugin boolean
*/
function insertVersion(&$version, $isPlugin = false) {
$isNewVersion = true;

if ($version->getCurrent()) {
// Find out whether the current version is the same as the
// one to be inserted.
$oldVersion =& $this->getCurrentVersion($version->getProduct(), $isPlugin);
$oldVersion =& $this->getCurrentVersion($version->getProductType(), $version->getProduct(), $isPlugin);
if ($oldVersion) {
if ($version->compare($oldVersion) == 0) {
// The old and the new current versions are the same so we need
Expand All @@ -140,7 +145,7 @@ function insertVersion(&$version, $isPlugin = false) {
} elseif ($version->compare($oldVersion) == 1) {
// Version to insert is newer than the existing version entry.
// We reset existing entry.
$this->update('UPDATE versions SET current = 0 WHERE current = 1 AND product = ?', $version->getProduct());
$this->update('UPDATE versions SET current = 0 WHERE current = 1 AND product_type = ? AND product = ?', array($version->getProductType(), $version->getProduct()));
} else {
// We do not support downgrades.
fatalError('You are trying to downgrade the product "'.$version->getProduct().'" from version ['.$oldVersion->getVersionString().'] to version ['.$version->getVersionString().']. Downgrades are not supported.');
Expand Down Expand Up @@ -178,14 +183,14 @@ function insertVersion(&$version, $isPlugin = false) {
} else {
// Update existing version entry
return $this->update(
'UPDATE versions SET current = ?, product_type = ?, product_class_name = ?, lazy_load = ?, sitewide = ?
WHERE product = ? AND major = ? AND minor = ? AND revision = ? AND build = ?',
'UPDATE versions SET current = ?, product_class_name = ?, lazy_load = ?, sitewide = ?
WHERE product_type = ? AND product = ? AND major = ? AND minor = ? AND revision = ? AND build = ?',
array(
(int) $version->getCurrent(),
$version->getProductType(),
$version->getProductClassName(),
($version->getLazyLoad()?1:0),
($version->getSitewide()?1:0),
$version->getProductType(),
$version->getProduct(),
(int) $version->getMajor(),
(int) $version->getMinor(),
Expand Down
1 change: 1 addition & 0 deletions xml/schema/common.xml
Expand Up @@ -55,6 +55,7 @@
</field>
<descr>Installation and upgrade version history.</descr>
<index name="versions_pkey">
<col>product_type</col>
<col>product</col>
<col>major</col>
<col>minor</col>
Expand Down

0 comments on commit 74c052f

Please sign in to comment.