Problem/Motivation

I am creating some tools for provision + hostmaster tasks.

hook_hosting_tasks() defines "task types", but you can only use the hosting task form (generated by hosting_tasks_TASK_TYPE_form()) with one word task types.

Since the "task type" name has to match a drush command "provision-TASK_TYPE" this breaks naming convention for drush commands, ie. using dashes instead of underscores.

Proposed resolution

Replace all dashes with underscores when looking for a hosting_tasks_TASK_TYPE_form() function.

Remaining tasks

None, as far as I can tell.

User interface changes

None.

API changes

You can now use more than one word (separated by dashes) for task type names

Patch coming...

Comments

jon pugh’s picture

StatusFileSize
new683 bytes

Patch attached

steven jones’s picture

Assigned: jon pugh » Unassigned
jon pugh’s picture

StatusFileSize
new675 bytes

Working patch, sorry bout that

steven jones’s picture

Version: 6.x-1.7 » 6.x-2.x-dev

I think that for 2.x, yes, we should do this, but for 1.x I don't see much point, you can just define your multi-word tasks using underscores, and Drush happily deals with that.

We should also clean up provision and everywhere else to use hyphens for Drush commands.

steven jones’s picture

Status: Needs review » Needs work
jon pugh’s picture

you can just define your multi-word tasks using underscores, and Drush happily deals with that.

We should also clean up provision and everywhere else to use hyphens for Drush commands.

This sounds like a contradictory recommendation. Are you recommending I use underscores in my drush commands while saying provision should use hyphens? Also, "provision-" is automatically appended to my hosting task name to come up with the appropriate drush command, for my project, the drush command would have to be "drush provision-devshop_sync which, to me, is going backwards.

hostmaster doesn't string replace hyphens to underscores when looking up a hook. It should. Form API does the same thing, as do other subsystems of Drupal.

Functions must use underscores. Template files, form IDs both do replacement one way or another. Drush commands use hyphens. This one line change would make it work much like the rest of Drupal does.

I COULD make all of my drush commands use underscores, but then, because

Hosting.module does not convert hyphens for underscores when looking for its hooks. That to me is a bug.

Due to the architecture of hosting.module, in this code, "provision-$task" MUST be a valid drush command. If the drush command is more than one word, it should be hyphenated, which breaks hook lookups.

-  $func = 'hosting_task_' . $task . '_form';
+  $func = 'hosting_task_' . str_replace('-', '_', $task) . '_form';
 if (function_exists($func)) {
     $form['parameters'] += $func($node);
   }
steven jones’s picture

What I mean is that for 6.x-2.x we should do as you say, and change provision to use hyphens when calling drush, but for 1.x, I'm not 100% sure we should worry about it. I know its just a one-line change, but I'm not 100% sure of the ramifications of that change.

steven jones’s picture

Need to get the patch from #3 cleaned up and existing tasks cleaned up in 6.x-2.x

jon pugh’s picture

Status: Needs work » Needs review
StatusFileSize
new683 bytes

Patch attached for 1.9. I need to start here, If approved for 1.9 I'll make it for 2.x and 1.x.

I still think this is a valid backport. What did you mean by:

change provision to use hyphens when calling drush

I didn't see any changes needed in provision, but maybe thats because I haven't dug into 2.x yet.

jon pugh’s picture

Attached is a patch to 2.x-dev branch of hostmaster.

fastangel’s picture

StatusFileSize
new1.71 KB

Attached new patch with other hooks with the same problem. http://drupal.org/node/1778400

NOTE: For version 1.9

steven jones’s picture

Patch in #11 looks good on first inspection.

steven jones’s picture

Status: Needs review » Needs work

Hmm...maybe not the actual patch file, which does the following for me:

fatal: corrupt patch at line 34

fastangel’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB

Resolved the problem.

jon pugh’s picture

Title: hosting_task_confirm_form() should handle multiple word hostmaster tasks. » Hooks based on TASK_NAME should handle task names with dashes in them.

Changing the title to reflect the real issue.

I wonder how drupal core handles this... they switch _ to - and back again for templates, menu items, etc.

/me runs to api.drupal.org....

function node_menu() {
  //...
foreach (node_type_get_types() as $type) {
    $type_url_str = str_replace('_', '-', $type->type);
    $items['node/add/' . $type_url_str] = array(
//...

Same way as us! That's kind of funny... so I guess we are doing this "right"? I gotta admit, it does seem a bit hacky that drupal itself doesn't have a global function to convert dashes to underscores...

steven jones’s picture

Status: Needs review » Patch (to be ported)

Thanks guys, I've pushed the patch from #14 (plus a tiny fix) into 6.x-1.x and now I'll start the work properly converting the tasks in 6.x-2.x.

fastangel’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.71 KB

Attached the patch for version 6.x.2

steven jones’s picture

Status: Needs review » Fixed

This was slightly more complicated in 2.x as we wanted to rename our tasks too, which I've done in provision and hostmaster. Thanks everyone!

Status: Fixed » Closed (fixed)

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

  • Commit ad814aa on 6.x-2.x, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by Steven Jones:
    Issue #1513678 by Jon Pugh, fastangel, Steven Jones: Fixed Hooks based...

  • Commit ad814aa on 6.x-2.x, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by Steven Jones:
    Issue #1513678 by Jon Pugh, fastangel, Steven Jones: Fixed Hooks based...