-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to package downloads #327
Conversation
Very interesting 😃 I'll test that soon 👍 |
This cannot be guaranteed. I recall there being an issue way back where a search for "formit" would return "formitfastpack" before formit itself, so I'm worried about reintroducing that.
The modmore provider does limit what versions can be downloaded as well, so specifying an arbitrary version probably wont work. Only versions that are marked as downloadable on my end (which typically is the last patch version of each minor release up to a year ago, e.g. 2.4.0 and 3.0.1) can be downloaded. |
This one is confusing, also for me. But I think I see now what's going on. I'll try to add comments: |
'signature' => (string) $foundPkg->signature | ||
); | ||
|
||
if ($foundPkg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically the same fix as in #353, so I can take this out.
This is the first request that looks for the exact signature, including version number.
foreach ($foundPackages as $foundPkg) { | ||
$packages[strtolower((string)$foundPkg->name)] = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking at the package name, not the signature. It uses that name to create a key in the packages array.
The problem I had with Redactor, is that there are several versions available through the ModMore package provider, but they all have the same name! Result: on every foreach loop, the Redactor key is overwritten by the next hit. And in this case, that's the oldest package version.
Here are the results without this fix:
Searching modmore.com for redactor...
Array
(
[redactor] => Array
(
[name] => Redactor
[version] => 2.4.0
[location] => https://rest.modmore.com/package/download?api_key=123&database=mysql&revolution_version=Revolution-2.8.3-pl&http_host=localhost&package=1&version=redactor-2.4.0-pl
[signature] => redactor-2.4.0-pl
)
)
foreach ($foundPackages as $foundPkg) { | ||
$packages[strtolower((string)$foundPkg->name)] = array( | ||
$packageVersions[] = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And when you put them all in an array first:
Searching modmore.com for redactor...
Array
(
[0] => Array
(
[name] => Redactor
[version] => 3.1.0
[location] => https://rest.modmore.com/package/download?api_key=123&database=mysql&revolution_version=Revolution-2.8.3-pl&http_host=localhost&package=1&version=redactor-3.1.0-pl
[signature] => redactor-3.1.0-pl
)
[1] => Array
(
[name] => Redactor
[version] => 3.0.2
[location] => https://rest.modmore.com/package/download?api_key=123&database=mysql&revolution_version=Revolution-2.8.3-pl&http_host=localhost&package=1&version=redactor-3.0.2-pl
[signature] => redactor-3.0.2-pl
)
[2] => Array
(
[name] => Redactor
[version] => 2.4.0
[location] => https://rest.modmore.com/package/download?api_key=123&database=mysql&revolution_version=Revolution-2.8.3-pl&http_host=localhost&package=1&version=redactor-2.4.0-pl
[signature] => redactor-2.4.0-pl
)
)
6a30e45
to
0b64464
Compare
Didn't realize this was merged already. Thanks! :)
0b64464
to
d68ec94
Compare
Ok, I think I managed to sort it out. Roughly, from top to bottom: Phase 1: exact match
Phase 2: query for nameThis is where things got shaky before, because the response also contains other packages with a partial match on name. The full match was usually on top of the list, but not always... So:
Phase 3: processingThis is still intact, except for the check to make sure the exact match is always first. There either is only 1 exact match at this point, or a list of partial matches.
So it seems any previous version of a MODX package can be accessed this way. Unfortunately, that trick doesn't work for the ModMore provider, if it's not available as previous version (under the same name ;)). I also don't think it should install a different package when an exact match could not be found (in the case of Hits), but return a warning or error instead. That's for another time though. So long story short: this is ready for testing. I didn't remove the debugging lines in the output yet, so you can see what's going on inside the different arrays involved. |
Hey @hugopeek , I've tested this and it works beautifully. 🚀 |
Thanks @muzzwood! Glad this is sorted now :) |
What does it do ?
This ensures the latest package version is always downloaded if multiple versions are available. As far as I could test, the correct package is always on top of the list in the response, so I think using the first result is reliable.
I don't really know how that list is being sorted though, so just to be sure it also checks if the package name is present in the signature. This means it always returns 1 package, so I disabled the "(x) packages found" message in the console output.
I also noticed an incorrect variable name on line 195. Well.. PhpStorm did ;) That suggests that the direct match was never working in the first place and it always fell back on the query straightaway.
Fixing that seems to make it possible (again?) to define the exact package version in .gitify and prevent updating to a newer version when re-running package:install --all.
Why is it needed ?
My initial issue was that Redactor now offers 2 versions through the ModMore package provider and it always installs the last one in the array (which is the lower version). Now it installs Redactor 3 when using 'redactor' in config. Ideally, you could specify an older version in the config file if you don't want to upgrade to v3, but somehow for the ModMore provider I can't get this to work..
In addition, Gitify often starts installing incorrect and unrelated packages when the package could not be found. This is annoying and shouldn't be the case. It should look for 1 package only and return either the latest version (formit) or a specific version (formit-4.2.0-pl). Otherwise an error that no match was found.
Related issue(s)/PR(s)
#262
And for anyone also unable to install colorpicker with Gitify, that should work now too. There seems to be a glitch in that package with minor version not set.