Just did a basic ugly debug output (file datasync.hosts.inc, around line 55):

  print_r($ret);die();
  return (($get_host === NULL) ? $ret : $ret[$get_host]);
}

My 'datasync_hosts' variable has this data:

preprod-drupal01
guinevere
www.somehost.net
localhost

When running the cron using Drush, this what I get:

pounard@guinevere:/var/www/mysite/drupal-dr/www$ drush cron
Array
(
    [preprod-drupal01] => Array
        (
            [run_post_hook] => 1
        )

)
Drush command could not be completed.

My current hostname is 'guinevere', the datasync_get_hosts() function does care only about the first line.

So, I did rewrite your function with a preg_split() instead of the str_replace() and explode() function usage, which is a bit more tolerant with whitespaces (among other things).

Running back my cron, I get:

pounard@guinevere:/var/www/mysite/drupal-dr/www/sites/all/modules/contrib/datasync$ drush cron
Array
(
    [preprod-drupal01] => Array
        (
            [run_post_hook] => 1
        )

    [guinevere] => Array
        (
            [run_post_hook] => 1
        )

    [www.somehost.net] => Array
        (
            [run_post_hook] => 1
        )

    [localhost] => Array
        (
            [run_post_hook] => 1
        )

)
Drush command could not be completed.

Which is a lot better, because this time the DataSync cron does run this time.

Patch attached, for the latest release (without the ugly debugging thing).

CommentFileSizeAuthor
#1 datasync.hosts-wrong_hosts_reading.patch683 bytespounard

Comments

pounard’s picture

StatusFileSize
new683 bytes

Oups, patch did not attached.

neilnz’s picture

I can confirm this patch fixes the case of having a simple hosts configuration (one host per line), but I think it's more a documentation issue with Datasync that causes this bug.

Datasync expects there to be double newlines in between each host (\n\n), but this is not documented anywhere. This is to allow the extended syntax where key/value pairs can be specified on the line after the host, but again this isn't documented (although the web interface claims README.txt specifies this syntax). This patch breaks the extended syntax which relies on there being a blank line in between each host config.

From looking at the code, it seems like a sample config might be something like:

host1
run_post_hook=1

host2
run_post_hook=0

host3
run_post_hook=1

Alternatively, a simple list could be specified like:

host1

host2

host3

It'd be really nice if Datasync had a more structured configuration method (eg. a form per host), rather than this buggy parsing of a textarea...

pounard’s picture

Oh right, totally not documented.. This needs a lot of work I think.

andrewlevine’s picture

Status: Needs review » Closed (works as designed)

You guys are right :) This configuration variable could use some work, but as far as I can tell, it currently works "as expected"

If you have time to work on it, we can start a separate issue to improve how this works.