Bug #17861
closed
Extension Manager does not sort versions of an extension correctly
Added by Micha Barthel almost 17 years ago.
Updated about 6 years ago.
Category:
Extension Manager
Description
This list not sorted!
$versions = array_keys($this->xmlhandler->extensionsXML[$extKey]['versions']);
$latestVersion = end($versions);
On line: 1610,1735,1382......
User this sort Function from Elmar Hinz:
Own
------------------------------------------------
------------------------------------------------
Sort:
------------------------------------------------
usort($versions, array('SC_mod_tools_em_index', 'compare'));
------------------------------------------------
------------------------------------------------
Function:
------------------------------------------------
function compare($aIn, $bIn) {
$aParts = explode('.', $aIn, 2);
$bParts = explode('.', $bIn, 2);
$a = (int) $aParts0;
$b = (int) $bParts0;
if($a > $b){
return 1;
}elseif($a < $b){
return 1;
} else {
if(is_string($aParts1)) {
return SC_mod_tools_em_index::compare($aParts1, $bParts1);
} else {
return 0;
}
}
}
-----------------------------------------------
------------------------------------------------
regards Micha Barthel
(issue imported from #M6854)
Files
can you give some examples what exactly the error is and why it is sorted?
There is a BUG when you like to get the current Ext Version ( see Ext: lab_newsfolders ),
but this is not by every Ext!
I had this problem with my t3s Extensions.....
To say it in my words:
01. $versions = array_keys($this->xmlhandler->extensionsXML[$extKey]['versions']);
02. $latestVersion = end($versions);
The function array_keys() does not garantee, that the array $versions is sorted in a proper way by versions. So it's a bug to simply call the end() function upon $versions. As a result $latestVersion does not always contain the latest version as expected.
Solution:
01. $versions = array_keys($this->xmlhandler->extensionsXML[$extKey]['versions']);
02. $this->sortVersions($versions);
03. $latestVersion = end($versions);
Micha has given an example how sortVersions() could look like:
usort($versions, array('SC_mod_tools_em_index', 'compare'));
etc.
I can confirm this. The current "sorting" is just the order of the entries of the xml file (http://typo3.org/fileadmin/ter/extensions.xml.gz). And this list isn't sorted correctly in all cases.
Elmar, your sort function looks good to me, just one annotation:
"if(is_string($aParts1)) {" should be "if (isset($aParts1) && isset($bParts1)) {"
Remark:
The above sorting algorithm assumes that the latest version equals the highest version. That sounds natural on the first glance. But is it true?
Someone could have two branches for his extension: 2.x.x and 3.x.x.
While 3.3.3 would be the highest version 2.2.2 could still be the latest upload.
It depends on the context, what is really wanted.
I can confirm that this bug is still present in 4.2.9. It took hours of my time to find out that the things in the manual didn't work because DAM 1.0.5 was installed as the latest DAM, although 1.1 is the latest version now.
Please integrate the solution as above. I think it is more useful to get the latest version below than the latest upload. In Elmar's example, where is the usefulness of the order 2.2.2, 3.3.3, 2.2.3, 3.3.4, 2.2.4 and later + 3.3.5 instead of 2.2.2, 2.2.3, 2.2.4, 3.3.4, 3.3.5 ? If you want to stay on 2.x, you can't use the latest upload anyway (because it could be a 3.x)
The erroneous code has partly been fixed with the related bugs.
But there is still two occurences left:
One in installExtension() and one in importExtFromRep().
I am working on a patch.
Christopher will you be able to test? I don't have a test case currently.
Patch uploaded, and RFC posted to the core list. Now waiting for reviews, unless it is accepted as no-brainer.
@Christopher: If you (or others) have testcases, please either post them in the thread in the core list or email me them directly. Notice the BT mailer doesn't work atm, so I am unlikely to see a note here with a testcase.
This issue can be closed.
- Status changed from Accepted to Resolved
- Target version deleted (
0)
- Status changed from Resolved to Closed
Also available in: Atom
PDF