Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've modified the drush function that handles the downloading of defined libraries so that they are actually downloaded. It is based on the drush functionality for downloading projects. The patch I've included contains all code to get it working. But aware that it only provides the base for getting the download functionality in the module. If there is anything I can do to help, let me know!
Comment | File | Size | Author |
---|---|---|---|
#29 | 1884246-29.patch | 8.59 KB | tstoeckler |
|
Comments
Comment #1
MKorostoff CreditAttribution: MKorostoff commentedComment #2
MKorostoff CreditAttribution: MKorostoff commentedGreat patch! I had to make one small bug fix to get it working.
When I applied the patch, and ran it, I got this error:
.
Basically, the problem was that
drush_tarball_extract()
returned an array whose first key was 1, not 0 (weird right?). I just threw in a$file_list = array_values($file_list);
and it worked!Thanks again :-)
Comment #3
BR0kENHi guys.
At first I've created a sandbox in which implemented the Drush command for downloading non-existent libraries. I did not publish a project and used the command by downloading it via Composer. Now, when I've upgrade it, think it's ready for the Libraries module.
Abilities and use cases:
drush ld
to do that.sites/all/libraries
if they are exist there) libraries toprofiles/<PROFILE>/libraries
. Usedrush ld --profile
to do that.drush ld twitteroauth parsedown
to do that.drush help ld
.7.x-2.x
and7.x-3.x
branches.I hope for attention for this patch.
Comment #4
BR0kENThis patch differs from previous only by using human-readable names for libraries instead of machine names in dialog for re-downloading.
Comment #5
m1r1k CreditAttribution: m1r1k at Propeople (now part of FFW) for Propeople (now part of FFW) commentedLook at drush pm-download command:
- use --destination instead of profile name
- add optional --package-handler=wget|curl
- add --use-site-dir
Comment #6
tstoecklerFine by me.
Mhh will have to sleep over this, but don't see why not ATM.
Not sure why you removed this? Mmhh I guess because it just duplicates the command description at the moment?
We should look at drush dl and maybe mirror that behavior of where stuff is placed?
Sure
The rename is fine with me.
Not sure why you included a bunch of changes to the function though?
Mhh, does Drush not provide a cooler way to do this? I would have thought some func_get_args() fu?
I think that should be a separate --all flag or something, seems counter-intuitive otherwise I would think? Also inconsistent with Drush dl.
As mentioned, we should look at how drush dl does this, but it would be cool, to make this even more configurable. (e.g. sites/example.com, etc.)
Again, this is something I would copy drush dl for. I don't think drush dl views does anything, if I already have Views module downloaded, does it?
Never seen that before. Cool, learned something new today! :-)
So this is the heart of the patch and I think it's also the most problematic part. We cannot just assume that $library['download url'] is the *actual* downloadable file. So far we have always assumed that to be a URL where the library can be downloaded. It was included in the API for a future UI that helps people download the library themselves. We cannot easily make it the filename unconditionally, because not all libraries have a static download link because they often include the library version. I.e. if the URL is http://code.jquery.com/jquery-2.1.4.min.js, how would you specify that in hook_libraries_info()? You don't want to update your module everytime a new jQuery comes out!?
That is also the reason why this has not been implemented so far, it's a non-trivial problem.
I think that's problematic, we should not be messing with people's file system in that way. Instead we should use the system /tmp dir.
I don't know how failsafe drush_tarball_extract() is, but how can you be sure that what you're donwloading is a tarball? As mentioned in the previous comment, it might just as well be a single JS file or something.
Comment #7
tstoecklerWill commit some of the more general fixes, to get that out of the way for the next patch reviews.
Comment #8
BR0kEN1. Ok.
2. I guess you are right with this. Changed for
libl
andliblist
.3. Yes.
drush help <COMMAND>
is informative, as for me.4. Added support of Drush
--uri (-l)
parameter and didn't touch the--profile
parameter. I think that we don't need to copy the workflow of--destination
parameter frompm-download
because typing all time something like--destination=sites/default/libraries
is not useful.5. Ok.
6. Just refactoring.
7. Unfortunately I don't know a better way.
8. Added
--all
parameter and error message if command run without names of libraries.9. See item #4.
10.
drush dl
asking about re-downloading. Also, using this patch, you can move libraries between directories (from "sites/all" to "sites/example.com", for example).11. Ok.
12. Added possibility to download single files (not archives). What about unique URLs? I guess this is not a problem of patch. Every code can be found on GitHub or somewhere else.
13. System
/tmp
directory could not be used properly every time.14. See item #12.
Also, added support of
--root (-r)
Drush parameter.I guess we should start from this one, at least. Because otherwise we will be at the start point all time.
P.S. Thanks for review.
Comment #9
BR0kENlibraries-list
command).Comment #10
BR0kENWas added manager for downloading/removing libraries on enabling/disabling the module. To use these opportunities, use the following keys in definition of library.
'auto remove' => TRUE
'auto download' => TRUE
Also, SimpleTest test suite was added for testing
drush libget
command.Comment #12
BR0kENComment #14
BR0kENComment #15
BR0kENComment #16
BR0kENI'll try to explain what's going on.
- created the command that helps to download libraries defined by "hook_libraries_info()";
- URL for downloading should point to single file (js/css/gz/zip/tar);
- improved the command for list libraries: refactored code, added column with name of module that defined that library;
- added SimpleTest test suite for testing libraries downloading by Drush;
- added test module that defines library with a correct URL for downloading;
- added an object that manages downloading/removing the libraries;
- added support of "auto download" and "auto remove" properties to definition of library;
- added "hook_modules_enabled()" and "hook_modules_disabled()" which download/remove defined libraries depending on properties described above;
Some notes:
- Test cannot be run by Drupal.org or on your local site from UI. It requires Drush availability in environment and checks this by looking for existance of some part of Drush API that is available when tests run by Drush (drush test-run LibrariesDrushTestCase -y).
- This commands are not designed to work without Drupal.
- Changed work of "-l" or "--uri" Drush option: it takes "all", "default" or any subsite name as an argument (if missed, "all" will be used).
- "--profile" option will ignore "-l" and download libraries to current Drupal profile.
- "--all" option download all libraries which can be downloaded.
Comment #17
bobojo CreditAttribution: bobojo commentedI'm not sure what needs to happen for this patch to be committed, but I can at least say that I applied the patch from #14 and was able to download all of my libraries just fine! I'm also more than happy to try my hand at fixing any outstanding issues if this patch isn't enough to get it committed to the module.
Comment #18
bobojo CreditAttribution: bobojo commentedOkay, update to my last comment: I did have trouble downloading a few libraries because their 'download url' was not actually a direct URL to a file that could be downloaded. I don't know if hook_libraries_info() has just been implemented incorrectly, or if it's the intended behavior of modules implementing this hook to define the download URL as a page with a link to the file or archive for the library rather than a direct url to the file that needs to be downloaded. If there's no direct reference to the file to be downloaded in hook_libraries_info(), I don't know how we could possibly automate downloading a library, since it requires human knowledge to click on a "Download" button or choose a release version on the linked page.
I think the best solution is to update hook_libraries_info() to let module developers know to include a full URL to the file to be downloaded or provide their own callback for downloading the library, which we could then hook into.
Comment #19
joelpittetThis looks great thanks @BR0kEN. There is some minor things, the only thing I think we need to change is the zip location to a file on your github account @BR0kEN
nit: this change is not needed and all of core has that space.
This looks sketchy @BR0kEN. Could you point it to a common d.o resource?
Comment #20
joelpittetActually this works well, I still think we need to change the test file download but leave that up to committers.
Comment #21
joelpittetThere's nothing really automatic about this, just title change and it's a task not really a feature request because the code replaces an @todo/commented out feature in the existing code.
Comment #22
joelpittetThese two lines changed and now if it is installed it will show a - even if it does have a version. Just need to change back to
&& !empty()
May be a good opportunity to tackle feedback in #19. LMK if you don't have time and I'll roll that in.
Comment #24
tstoecklerCommitted some of the unrelated changes, to make this patch a bit smaller. Proper review coming up.
Comment #25
tstoecklerSo this took me a bit longer than expected, but I did actually spend a significant amount of time looking into how
drush pm-download
works and trying to adapt that for our use-case here. I did come up with something reasonable to my mind, that mostly follows the same logic. This supports downloading archives and single files. I did start from scratch as the previous suffered from sever scope screep from my point of view.The whole LibrariesManager etc. is something for another issue along the lines of "Allow modules to have dependencies on libraries" (although I'm not sure I'm fond of adding a class for that, though). I thought there was an issue for that already but can't find it ATM.
This allows a library to specify a
download file url
(still needs to be documented) and thendrush libraries-download foo
will download thefoo
library if it did that. I kept out a bunch of more advanced features but left @todo's all around. I will also try to get some improvements into Drush upstream to make our lives a little bit easier here.If someone gives this a whirl and sees whether it works for them, I would be fine committing this (with added docs) and then refining further with that as a starting point.
Comment #26
BR0kENEhhh, rhetoric: why everything should be so difficult every time?
Comment #27
tstoeckler@BR0kEN: I realize that the course this issue has taken must be incredibly demotivating for you. You have spent a lot of time on it and yet this has seen little progress largely because of my lack of involvement. I sincerely apologize for the not being more active here, but I'm always trying to balance Libraries API with a bunch of other commitments. We are now actually a team of 3 maintainers so maybe things will improve in the future.
That said, I did not find your patch in a state where I felt I could commit it. And you did not incorporate a lot of my feedback into your patch. So instead of arguing back and forth I now proposed something along the lines I was thinking. It surely is not perfect and I look forward to your constructive criticism so maybe we can get something we're both happy with. But I honestly did not know what to do otherwise because I did not feel like I could commit your patch as is. Hope to still see you around and would really appreciate your input on this, although as I noted I can totally understand if you're not motivated to work on this anymore. Again, sincere apologies. I will try to be more responsive in the future but looking at the Libraries API issue queue right now I already know that I will break that promise :-/ it's just what it is...
Added some docs to the patch and fixed a bug that I forgot to commit in my local branch so was not part of the last patch. So now with the added docs this is now something that I feel is "ready"(-ish), but would really like some reviews before going any further.
Comment #28
tstoeckler@joelpittet reported that https://www.drupal.org/project/commerce_yotpo and https://www.drupal.org/project/mailchimp are not working with this. Will try it out myself...
Comment #29
tstoecklerDuh, I included a really dumb error in the latest patch where we would detect an error properly but then continue to try to download the file anyway....
Updated patch.
Adapting/adding the following to Mailchimp's
hook_libraries_info()
actually allows me to download mailchimp withdrush dl mailchimp
:Comment #30
joelpittetGreat thank you, that works. I'll add that to any module I co-maintain and a patch to mailchimp.
Comment #31
tstoecklerfrom dawehner ... works for me. The code seems logical.
Comment #33
tstoecklerAlright, thanks everyone!!! Committed to 7.x-2.x