I create a LOT of new platforms for development, and it's a little irksome to me that the platform title and publish path almost always reflect each other, i.e. if the platform title is "Drupal 6.20" the publish path is "/var/aegir/platforms/drupal_6_20". So, I created a little module that just generates the publish path automatically based on the title, similar to how Feeds/Views and other modules automatically generate machine names. Maybe someone will find it useful. If it's deemed useful enough to be incorporated into hostmaster, it needs to be cleaned up just a little bit, and there probably needs to be a config option to set the base publish path (i.e. "/var/aegir/platforms/")

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anarcat’s picture

Status: Needs review » Needs work

Very nice! I would very well see this merged directly in the hosting_platform module in 2.x. For this to happen, we would need a patch instead of a full module (and no need for a feature there, in my opinion).

Also, we try not to depend on the /var/aegir assumption, or at least as least as possible. Right now, it is not hardcoded at all in the frontend, and we only depend on the backend for that initial creation - it defaults to the Aegir user's $HOME directory:

      $this->setProperty('aegir_root', getenv('HOME'));

(provision.context.server.inc:50).

That property is not propagated to the frontend, unfortunately... But maybe it should be. There were two variables close to that property in the web_server before, but they were dropped in the great "services" migration:

  db_drop_field($ret, "hosting_web_server", "backup_path");
  db_drop_field($ret, "hosting_web_server", "config_path");

That table was eventually completely dropped.

Maybe we should bring back that table, but I'm not sure it's worth it - maybe a frontend-wide variable configured on install/upgrade would be sufficient. Also, maybe it shouldn't be called "aegir_root" (which doesn't mean much) but "platform_path" or something similar.

As for the code itself, it looks sane. One comment - I would rather see a similar pattern than for context or client sanitization. Example from hosting_client_sanitize():

  return substr(strtolower($prefix . preg_replace("/[!\W\.\-]/", "", $title)), 0, MAX_GROUP_LENGTH);

... same could be done but instead of removing, replace with dashes (I would rather see dashes than underscores), allow dots (drupal-6.20 is fine for a path), throw in lower case and limit the path length.

So there you go. To sum up, I think there could be some improvements to the patch, but before it's merged into aegir, it needs:

1. to be a patch (probably on hosting_platform.module)
2. to not hardcode /var/aegir

In the meantime (and for 1.x?) this can live in contrib too...

j0nathan’s picture

Interesting, subscribing.

Dane Powell’s picture

Glad to see interest, I'll incorporate the changes you suggest, roll a contrib module, then report back with a patch.

Dane Powell’s picture

I rolled a module at http://drupal.org/project/hosting_platform_pathauto

For the module, I made the base path configurable. For a patch, we'd remove this config form / Feature aspect and modify platform_node_form directly, getting the base path value from Aegir. I'll leave it to you to decide how to get the platform base path, I'm no expert in Aegir internals.

Also, there is one bug- if you enter multiple invalid characters in a row, the regex fails to strip them all out. For instance, a platform name of 'test@test' will result in a path of 'test-test', but a name of 'test@@test' will result in 'test-@test'. I'm terrible at regexes, so maybe you can let me know what needs to be tweaked to fix that. I wonder if this also might indicate a bug with client name validation.

So let me know how to get the base path, what's wrong with that regex, and I'll roll a patch.

anarcat’s picture

Status: Needs work » Needs review

For the regex, you probably need /g. I'll review the rest of the code later if i find time.

Dane Powell’s picture

Bingo, thanks for the tip

anarcat’s picture

Status: Needs review » Needs work

I am not sure about that regex still. :)

/[^\w^\.]/g, '-'

I think you only need one caret, at the beginning. The way that regex reads right now, it's *not* going to replace carets....

The javascript is a bit hard to read here:

http://drupalcode.org/project/hosting_platform_pathauto.git/blob/2fea82d...

I suspect line 10 and below have too much indentation, am I right? The code could use some comments as I have trouble understanding exactly what it does... for example, why do we hook only if the path is the same as the name...?

  11       if ($('.platform-path').val() === machine) {

Also, if you provide a patch, we can start looking at merging this in 2.x.

Please keep going! This is great stuff that should get in! :)

Ah, and ahem... sorry for the delays ;)

Dane Powell’s picture

Thanks for the tips. I've tweaked the regex and added code comments as you suggested.

I'm not sure what you mean about indentation being wrong- it looks fine to me...

If the actual path is different from the sanitized human-readable name, that indicates that the user has manually edited the path, in which case we don't want to clobber it- that wouldn't be very nice :)

Let me know if that looks good and I'll roll a patch based on the latest version.

Steven Jones’s picture

Thanks for the work, I'm going to suggest some improvements to your javascript too:

$('.platform-name:not(.processed)').each(function() {
    $('.platform-name')
      .addClass('processed')

Since you've made jQuery find the elements once, you don't need to bother doing it again, so you can write the code above as:

$('.platform-name:not(.processed)').each(function() {
    $(this)
      .addClass('processed')

You can do this throughout the .each callback function.

Also, you shouldn't just add a 'processed' class, but name the class to match your behavior, so: 'hosting-platform-pathauto-processed' this means that you don't conflict with other behaviors.

You should also wrap the entire javascript in a closure, which is super simple, add the following to the top of the file:

(function ($) {

And this to the bottom:

})(jQuery);

Keep up the good work!

j0nathan’s picture

Hi Dane,
I don't know PHP so I am not sure of what I'll tell you.

"If the actual path is different from the sanitized human-readable name, that indicates that the user has manually edited the path"

This makes me remember when pathauto decides the path is automatic after changing the title of the node, even if we gave him a path not automatic at the beginning. I think this module tries to resolve this: Pathauto persistent state (http://drupal.org/project/pathauto_persist).

So, would it be possible to save that somewhere in the DB? If the path is really automatic or it has been written down by a human.

Thanks for your work.

Dane Powell’s picture

@Steven Thanks for the tips, they sound reasonable so I've committed them. I've never seen the 'closure' wrapper that you describe in any other .js files in Drupal- can you point to a canonical example or documentation, or provide a little more explanation as to why it's necessary? Also, I based this off of js in the Feeds module, I suppose these tweaks should be sent 'upstream' to Feeds as well?

@Jonathan It's a good point, in an ideal world yes we would save whether the user has actually clicked the button to override the path, rather than just inferring whether or not the path has been overridden. But it seems like a lot of trouble/overhead for not much payoff.

If no one has any other suggestions, I'll roll a new version of the module in a few days and submit a patch against Hostmaster 6.x-2.x

Steven Jones’s picture

Javascript closures:
It was a change introduced in D7 core JS files, but there's no reason to not be compatible now. More details are here: http://drupal.org/node/224333#javascript_compatibility

Dane Powell’s picture

I've released hosting_platform_pathauto-6.x-1.0. What's the next step to get this incorporated into 2.x? I assume you don't want it to be user-configurable in any way, meaning we need to figure out where the code will live, and we need to figure out how to get the base path (i.e. /var/aegir).

Also, is there only a 7.x version of 2.x (if that makes sense :P)? I see a 7.x-2.x branch in the repository, but no 6.x-2.x branch...

Steven Jones’s picture

Version: 6.x-0.4-alpha3 » 6.x-2.x-dev
Steven Jones’s picture

Issue tags: +AUX Project

@Dane Powell I'd like to merge this into the 2.x branch of Aegir soon, would it be possible to get commit access to your project, so I can make some tweaks, then we'll just pull it in with our make file.

Dane Powell’s picture

No problem, you've got it.

Steven Jones’s picture

Awesome thanks!

Steven Jones’s picture

Status: Needs work » Fixed

Added to 2.x in commit:030853e67295b9bf31a07ba2aebfb4568cb17f2c

I've done this in our makefile, and enabled it by default. @Dane Powell thanks for your contribution, if you keep maintaining it, and then give us a shout when you want us to pull in a new version, we can.

Dane Powell’s picture

No problem, I hope it makes people's lives a little easier!

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

  • Commit 030853e 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 #1138104 by Dane Powell: Added Tiny module to automatically fill...

  • Commit 030853e 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 #1138104 by Dane Powell: Added Tiny module to automatically fill...