Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grimreaper created an issue. See original summary.

Grimreaper’s picture

Issue summary: View changes
Grimreaper’s picture

Assigned: Unassigned » Grimreaper

Trying to make a first patch.

Grimreaper’s picture

Assigned: Grimreaper » Unassigned
Status: Active » Needs work
FileSize
22.69 KB

Here is a first patch for the webform:composer:update command.

Currently the only one I used.

It is a quick and dirty patch, but I need this command on projects.

Grimreaper’s picture

FileSize
15.33 KB

Sorry wrong patch.

jrockowitz’s picture

@Grimreaper The challenge is going to be supporting Drush 8.x and Drush 9.x. I might need to refactor all the existing drush commands and move as much of the business logic as possible into a reusable service.

Grimreaper’s picture

@jrockowitz: I totally agree. And also supporting Drupal Console as Config split does by the way. But I required the command webform:composer:update to be usable now. So I made this quick and dirty patch.

jrockowitz’s picture

Config Split is great an example. If anyone else has examples of modules that support Drush9 and DrupalConsole, please post them here.

NickDickinsonWilde’s picture

Assigned: Unassigned » NickDickinsonWilde
jrockowitz’s picture

@NickWilde Thanks. Ping me on Drupal Slack if you have any questions.

NickDickinsonWilde’s picture

Still, rough and needs more testing (haven't got to back-testing the changes on the old Drush code.
However, I'm probably not going to get more work on this done for a few days so here's my WIP.

jrockowitz’s picture

@Nick Wilde No problem. It is a good start.

I think we need to look at http://cgit.drupalcode.org/config_split/tree/src/ConfigSplitCliService.php and consider moving DrushHelper.php into WebformCliService.php service. The huge perk of a using a service is people can extend it.

NickDickinsonWilde’s picture

Status: Needs work » Needs review
FileSize
60.07 KB

Okay, this is now ready for a solid review/testing.
A few notes:
Drush make has been removed in Drush 9.x. Running `drush wfld` will print an error message to that affect.
webform-docs I didn't really test. I'll get tidy installed later and do so.
webform-generate I haven't done (haven't checked if the devel module has a Drush 9 option yet)
All other commands are converted with mostly equivalent functionality/interface.

NickDickinsonWilde’s picture

Assigned: NickDickinsonWilde » Unassigned
jrockowitz’s picture

My heart sank when I realized that drush make is no longer supported, partially cause I like the simplicity of Drush's YAML make file vs composers JSON files and secondly because my main client is on D8 but they are not yet ready to stop using Drush make.

Anyway, I need to setup my system to support Drush 8 and 9 concurrently. I am sure it is no problem. I am trying to take a much-needed break for the rest of the year. This will be one of my first major tasks of the New Year.

@NickWilde Thanks for helping push this forward and happy New Year.

jrockowitz’s picture

Assigned: Unassigned » jrockowitz

I am going to start reviewing this patch.

jrockowitz’s picture

I am seeing maintainability issues between the Drush 8 and 9 commands because there are too many changes being made when the Drush 8 commands are being converted to Drush 9.

For example...

Drush 8 uses `drush webform-export WEBFORM_ID` and Drush 9 is now using `drush webform-export --webform-id=WEBFORM_ID`
The `drush webform-purge` command now has dedicated drush 8 and 9 code.

There needs to be a solid bridge between Drush 8 and Drush 9.

I also think the Drupal community needs some code generation tools to help with the conversion. We should be able to use webform_drush_command() to generate a complete scaffold for the WebformCommands.

So far no one has come up with generic helper/bridge class that makes it easy to port and maintain Drush 8 and Drush 9 commands.

@NickWilde I really appreciate you starting to work on this. I might have to reapproach this problem and solution. I am absolutely going to use your code as a reference.

  • jrockowitz committed 702581e on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Move drush.inc hooks in...

  • jrockowitz committed a013c96 on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Move drush.inc hooks in...

  • jrockowitz committed 3ef1400 on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Wireframe commands.
    

  • jrockowitz committed eb35f51 on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Setup drush 9 service.
    

  • jrockowitz committed 8ae77d9 on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Get Drush 9.x command working.
    

  • jrockowitz committed b7cac4e on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. API cleanup.
    

  • jrockowitz committed 3bed80f on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Cleanup drush generate commands.
    
  • jrockowitz committed 6bcd97b on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Cleanup drush generate commands.
    

  • jrockowitz committed 85ecd57 on 2916800-drush-9-v2
    Issue #2916800: Drush 9 support. Setup test script.
    
jrockowitz’s picture

The attached patch uses some PHP magic to create the central CLI service that supports both Drush 8 and 9. There is now a Drush command to generate webform.drush.inc and WebformCommands. My goal is to get a working and maintainable MVP.

"First do it, then do it right, then do it better - this is my mantra for successfully getting things done. It's all about the iteration."
https://twitter.com/addyosmani/status/314785735171518464?lang=en


@NickWilde I am sorry that I did not scope out this work before letting you start working on it. The lesson I learned is to push everyone including myself to estimate before taking on any big issue/ticket.

I hope once you review the patch and change record you can see how my approach makes it easier for us to maintain support for Drush 8.x and 9.x. I also made very few changes to the original Drush commands to prevent any regressions.

Besides my apology, I owe you a beer.

jrockowitz’s picture

jrockowitz’s picture

Fixing drush webform-libraries-download.

jrockowitz’s picture

Grimreaper’s picture

Status: Needs review » Needs work

Hello,

I have tested the "drush webform:composer:update" command on the last commit of the branch 2916800-drush-9-v2 and I have the following error:

root@5a7cde3461a5:/project/www# drush webform:composer:update

 THIS IS AN EXPERIMENTAL DRUSH COMMAND.
PLEASE MAKE SURE TO BACKUP YOUR COMPOSER.JSON FILE.
Are you sure you want update your Drupal installation's composer.json file? (yes/no) [yes]:
 > yes

 [error]  The "composer_json" option does not exist. 

Also about the generated files for Drush 8 and Drush 9 commands, maybe adding a "// @codingStandardsIgnoreStart" at the beginning of the files would be good to avoid code sniffer warnings.

  • jrockowitz committed 2d34279 on 2916800-drush-9-v2
    Issue #2916800 by jrockowitz, Grimreaper, NickWilde: Drush 9 support....

  • jrockowitz committed 0a9e8cf on 2916800-drush-9-v2
    Issue #2916800 by jrockowitz, Grimreaper, NickWilde: Drush 9 support....
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
124.12 KB

@Grimreaper Thanks for the review and suggestions.

Here is a new patch. I also updated the branch.

Grimreaper’s picture

@jrockowitz, thanks.

I have tested the last version on the branch and the command "drush webform:composer:update" now works ok.

jrockowitz’s picture

@Grimreaper Are all the existing webform drush commands working as expected via Drush9.

Grimreaper’s picture

Hello,

@jrockowitz, I have tested all the commands in docs/DRUSH-COMMANDS.md for Drush 9.

Everything is ok except:

  • drush webform:docs : as I don't have the tidy php extension I obtained the error "The HTML tidy PHP addon is required to generate HTML documentation." which is ok.
  • drush webform:generate --entity-type=node --entity-id={ENTER_NID} contact : only works with the content type provided by the webform_node sub-module as the expected field machine name is "webform" and it is not an option so other entity reference fields targeting webform won't work. I don't know if it is also the case with Drush 8.
jrockowitz’s picture

Yep both those commands are working as expected.

jrockowitz’s picture

I forgot to port the drush webform_scheduled_email_cron command.

I tested it and I don't expect there to be a lot of people using it.

  • jrockowitz committed 15c9942 on 8.x-5.x authored by NickWilde
    Issue #2916800 by jrockowitz, Grimreaper, NickWilde: Drush 9 support
    
jrockowitz’s picture

Status: Needs review » Fixed

I committed that patch and we should make additional improvements as needed.

Grimreaper’s picture

Great \o/ !

Thanks @jrockowitz and @NickWilde.

dimmech’s picture

I'm getting the following error when trying to download the libraries.

drush webform:libraries:download
Downloading https://download.ckeditor.com/autogrow/releases/autogrow_4.7.2.zip
Extracting to /home/user/Work/Sites/d8.com/libraries/ckeditor.autogrow
 [error]  Unknown method/function 'drush_tarball_extract'.
jrockowitz’s picture

What version of Drush do you have installed?

drush --version

jrockowitz’s picture

Status: Fixed » Needs review
FileSize
2.72 KB

I figure out the issue is 9.0.0-rc2. It appears that drush 9.x is going to be moving target for a little while.

The attached patch fixes the missing legacy functions and removes a temporary workaround for 9.0.0-rc1.

  • jrockowitz committed a96c2b7 on 8.x-5.x
    Issue #2916800 by jrockowitz, Grimreaper, NickWilde: Drush 9 support
    
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the latest dev release to review.

dimmech’s picture

The commands are working and now I'm recieving the following php error.

[warning] rename(): The first argument to copy() function cannot be a directory WebformCliService.php:701

It appears to be related to this php bug which descibes the following workaround.

exec("mv ".escapeshellarg($strOldPath)." ".escapeshellarg($strNewPath));

It was also subject of a Drupal issue here which @jpstacey resolved. The conditions are the same for me as described there, my /tmp directory is on a different volume then my /var/www directory.

jrockowitz’s picture

FileSize
616 bytes

Let's use core's file_unmanaged_move() function instead.

I am going to just commit the attached patch. Please download the latest dev release to review.

  • jrockowitz committed 1be694f on 8.x-5.x
    Issue #2916800 by jrockowitz, Grimreaper, NickWilde, dimmech: Drush 9...
dimmech’s picture

With the current patch i had to make sure that allow_url_include = On was set in php.ini otherwise I was getting:

Downloading https://download.ckeditor.com/autogrow/releases/autogrow_4.7.2.zip
 [warning] fopen(): SSL: Connection reset by peer WebformCliService.php:680
 [warning] fopen(): Failed to enable crypto WebformCliService.php:680
 [warning] fopen(https://download.ckeditor.com/autogrow/releases/autogrow_4.7.2.zip): failed to open stream: operation failed WebformCliService.php:680
Extracting to /home/user/Work/Sites/d8/libraries/ckeditor.autogrow
 [error]  Unable to unzip /tmp/drush_tmp_1515696941_5a57b32d0e7a2/autogrow_4.7.2.zip.

After changing php.ini and restarting apache, I now get the following error. I can verifiy the files are downloaded and extracted to this point.

Downloading https://download.ckeditor.com/autogrow/releases/autogrow_4.7.2.zip
Extracting to /home/user/Work/Sites/d8/libraries/ckeditor.autogrow
 [error]  The specified file /tmp/drush_tmp_1515700541_5a57c13dc420b/autogrow could not be moved to /home/user/Work/Sites/d8/libraries/ckeditor.autogrow.
jrockowitz’s picture

Status: Fixed » Needs review
FileSize
2.77 KB

@dimmech I am unable to replicate the error. Still, I think there some room for improvements.

The attached is a patch uses native Drush 9 functions with the mv command as a backup. Does this help?

What OS and PHP version are you using?

Does the /libraries directory exist?

Did you check the directories file permissions?

dimmech’s picture

Using Ubuntu 16.04 w/ PHP 7.0, /libraries exsist - yes, file permissions - yes.

This patch worked, all library files are there, nice work! Looks like the cross-volume php bug will still error on the mv function but I'm sure you'll decide how to handle that.

This was the output:

Downloading https://download.ckeditor.com/autogrow/releases/autogrow_4.7.2.zip
Extracting to /home/user/Work/Sites/d8/libraries/ckeditor.autogrow
Attempting to use 'mv' to move files.
mv: cannot stat '/tmp/drush_tmp_1515710188_5a57e6ec16522/autogrow': No such file or directory

Thanks

jrockowitz’s picture

For now it feels safer to not use the 'mv' command since I can't replicate the error/issue.

Attached is the same patch without the 'mv' command.

Status: Needs review » Needs work

The last submitted patch, 56: 2916800-56.patch, failed testing. View results

jrockowitz’s picture

Status: Needs work » Fixed

I committed the last patch.

  • jrockowitz committed bc46dbb on 8.x-5.x
    Issue #2916800 by jrockowitz, Grimreaper, NickWilde: Drush 9 support
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

devil2005’s picture

Hi, i reopen because i have this error with drush 9


  [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
  The service "webform.commands" has a dependency on a non-existent service "webform.cli_service".

Can you help me please ?

thanks

jrockowitz’s picture

Did you clear drupal's cache?

devil2005’s picture

Yes :(

devil2005’s picture

In fact... "drush cr" is ok, but not "drush status", "drush entup" broken too

devil2005’s picture

A fully update with composer and dependencies to RC4 solved the problem.

Thanks ;)