Closed (fixed)
Project:
Drush
Component:
Base system (internal API)
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
1 Sep 2010 at 17:48 UTC
Updated:
19 Nov 2010 at 20:10 UTC
Jump to comment: Most recent file
Brief intro:
I want to create a server-alias which set common parameters and then add other additional parameters for each site-alias in a multisite environment, then for example my aliases.drushrc.php would be something like this:
$aliases['server'] = array(
'remote-host' => 'myserver.com.ar',
'remote-user' => 'myuser',
'root' => '/path/to/remote/drupal/root',
'path-aliases' => array(
'%drush-script' => 'php /path/to/drush/drush.php',
'%custom' => '/path/to/custom',
),
);
// and, por example:
$aliases['site1-live'] = array(
'parent' => '@server',
'uri' => 'site1.com.ar',
'db-url' => 'mysqli://username:password@localhost/db-site1',
'path-aliases' => array(
'%dump' => '/path/to/live/sql_dump_site1.sql',
'%files' => '/path/to/site1.com.ar/files',
),
);
$aliases['site2-live'] = array(
'parent' => '@server',
'uri' => 'site2.com.ar',
'db-url' => 'mysqli://username:password@localhost/db-site2',
'path-aliases' => array(
'%dump' => '/path/to/live/sql_dump_site2.sql',
'%files' => '/path/to/site2.com.ar/files',
'%other-custom' => '/path/to/other/custom',
),
);
But the resulting alias does not combine both 'path-aliases' correctly:
shell> drush sa @site1-live
$aliases['site1-live'] = array (
'remote-host' => 'myserver.com.ar',
'remote-user' => 'myuser',
'root' => '/path/to/remote/drupal/root',
'path-aliases' =>
array (
'%dump' => '/path/to/live/sql_dump_site1.sql',
'%files' => '/path/to/site1.com.ar/files',
),
'uri' => 'site1.com.ar',
);
and '%drush-script'?
Feel free to make any corrections if my english (or my code) isn't the appropriate one. :)
This patch worked for me:
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | drush_path-aliases_with_parent__2.patch | 4.2 KB | luchochs |
| #16 | drush_path-aliases_with_parent_2_.patch | 4.57 KB | luchochs |
| #14 | drush_path-aliases_with_parent_2.patch | 4.56 KB | luchochs |
| #6 | drush_path-aliases_with_parent_extended_.patch | 3.49 KB | luchochs |
| #1 | drush_path-aliases_with_parent_1.patch | 1.51 KB | luchochs |
Comments
Comment #1
luchochs commentedIn the original patch I try to correct a behavior related to the following property of the array_merge() function:
In this new version of the patch, now also taking advantage of the difference between the functions array_key_exist() and isset()
Both quotes are from the manual of php.net.
I hope this helps someone.
Regards.
Comment #2
greg.1.anderson commentedThis is a great patch, but there might be other arrays in the alias record that need to be merged together. Would array_merge_recursive work here?
Comment #3
luchochs commentedHi Greg.
If there are common keys, array_merge_recursive() does not replace the values, instead transforms the common keys in arrays, where all the values of the above mentioned common keys are stored.
For example, if (in patch):
and in @site2-live replace '%other-custom' by '%custom', then:
Therefore, this is not viable either:
Which might be other arrays to which you refer?
Comment #4
luchochs commentedIf there might be other arrays in the alias record that need to be merged together, some options:
1.- wait for it: #791860: array_merge_recursive() is never what we want in Drupal: add a drupal_array_merge_recursive() function instead. and his backported,
2.- inspired by #791860 in 1, create drush_array_merge_recursive(),
Maybe useful function also in drush_command_invoke_all_ref().
Comment #5
greg.1.anderson commentedSorry, I forgot to answer your question before. There are currently a couple other arrays that may appear in a site alias, and more may be added in future versions.
Here is the current definition of set alias context in sitealias.inc:
Here we do special-case the alias items by key; this is done because there is at least one array-based item,
databases, that should never be merged. So, perhaps your existing patch, with the addition of handling for command-specific and site-aliases, would be appropriate. Better still, get the list of items to skip from a common function used by both your patch anddrush_sitealias_set_alias_context.Comment #6
luchochs commentedThanks for the explanation.
Now the patch also contains some other minor modifications (don't correspond specifically to this topic, but I don't believe that they deserve a new one) to avoid this:
Comment #7
luchochs commentedIgnore the patch in #6 please. It wasn't so simple :).
Is really neccesary special handling also for 'site-aliases' and 'command-specific' in the patch?
The parameters passed to the function _drush_sitealias_add_inherited_values() are preprocessed by _drush_sitealias_find_and_load_alias():
Extract of _drush_sitealias_find_and_load_alias():
And _drush_sitealias_find_and_load_alias() use drush_set_config_special_contexts(), an extract from the latter:
The special handling is currently done, but the problem seems to be again the use of array_merge() on multidimensional associative arrays.
Comment #8
greg.1.anderson commentedI'm going to have to look at this later...
Comment #9
luchochs commentedMmmm, now ignore all in #7 please, except the conclusion.
Before the parent-child combination takes place, both 'command-specific' and 'site-aliases' are in their appropriate context.
This happens (in
_drush_sitealias_add_inherited_values()) here:I could verify it doing the following replace:
(
drush_sitealias_get_record()callsdrush_set_config_special_contexts(), but_drush_sitealias_get_record()does not) and then comparing the return ofdrush_get_context('command-specific')for each case.The wrong combination of 'command-specific' values (when the alias has an 'parent') is apparently caused by the
array_merge()indrush_set_config_special_contexts().Comment #10
luchochs commentedGreg, have you some opinion about this?
If the original patch fixes the original issue I really would appreciate to have the solution in HEAD.
Comment #11
greg.1.anderson commentedRegarding the patch in #1, I would still like to see a
foreach (array('site-aliases', 'command-specific') as ...)wrapped around this part:Furthermore, I would prefer it if the
array('site-aliases', 'command-specific')were retrieved from a function or data structure wherever it was needed, which would be in this patch, plus the existing code blocks referenced in #5 and #7. Perhaps 'command-specific' is not relevant to this patch at this point in time, but the alias code needs some fixing, and future code paths might exercise this function differently. Better to fix it correctly now so it doesn't bite later.The issue of %drush being generated incorrectly should be addressed in a separate issue.
Comment #12
greg.1.anderson commentedComment #13
luchochs commentedOk, I'll see what I can do about it in the coming days, with more time available.
Comment #14
luchochs commentedA new and flexible helper function (
drush_get_special_keys()) is added.Comment #15
luchochs commentedComment #16
luchochs commentedSome minor improvements in the documentation block.
Comment #17
luchochs commentedOn second thought, the $with_defaults parameter does not make much sense.
Changes in this patch:
- Remove the parameter $with_defaults, and
- Change the name of the parameter $more_keys by $extra_keys.
Comment #18
greg.1.anderson commentedThis is looking pretty good; I'm working through my backlog, and will try to find time to test and commit this soon.
Comment #19
greg.1.anderson commentedCommitted. Thanks.
Comment #20
luchochs commentedCommited with a slight modification, right?
Since there must be a special function, why not use it to avoid also this
$array_based_keys = array_merge(drush_get_special_keys(), array('path-aliases'));in favour of$array_based_keys = drush_get_special_keys(array('path-aliases'));?Thanks anyway.
Update: 'favour' instead of 'favor'.