drupal 6 - Perl Drush Command script error -
i'm trying add php code snippet drupal web form node. i'm getting error message syntax error near unexpected token `(' occurring on line below drupal query comment. help? escaped parens , dollar signs.
#!/usr/bin/perl use strict; $updatesdir = '/var/www/html/mysite/releaseupdates/spint1'; $drupalroot = '/var/www/html/mysite/web'; $drushcmd = '/usr/bin/drush'; # drupal query system("$drushcmd -r $drupalroot -u sites.admin --yes sql-query 'update node_revisions set body = replace\(body,\'</div>\',\'<?php \$contact_us_node = abc_drupal_node_load\(null, \'my_group\'\);if \(isset\(\$contact_us_node->field_contact_us_message_body\)\) {echo \$contact_us_node->field_contact_us_message_body[0][\'value\'] . \"<br />\";}?></div>\'\) nid=123'") == 0 or die "$drushcmd failed: $?"; print "contact body text updated php code.\n";
you passing string system
, , shell (formatted better readability):
/usr/bin/drush -r /var/www/html/mysite/web -u sites.admin --yes sql-query ' update node_revisions set body = replace(body,'</div>', '<?php $contact_us_node = abc_drupal_node_load(null, 'my_group'); if (isset($contact_us_node->field_contact_us_message_body)) { echo $contact_us_node->field_contact_us_message_body[0]['value'] . "<br />"; } ?></div>' ) nid=123'
why? perl's double quoted strings ignore unknown escapes removing backslash. example: "\(" eq "("
. means when shell sees command, backslashes missing! let's see “strings” shell sees:
/usr/bin/drush -r /var/www/html/mysite/web -u sites.admin --yes sql-query 'update node_revisions set body = replace(body,' </div> ',' <?php $contact_us_node = abc_drupal_node_load(null, 'my_group' );if (isset($contact_us_node->field_contact_us_message_body)) {echo $contact_us_node->field_contact_us_message_body[0][ 'value' ] . "<br />" ;}?></div> ') nid=123'
this absolutely not intended. have three levels of escaping:
- the perl string
- the shell
- the sql
- (the php code, doesn't use escapes here)
how can solve this? can remove shell level having perl exec
command directly without passing shell. this, use list form of command:
system( $drushcmd, '-r', $drupalroot, '-u', 'sites.admin', '--yes', 'sql-query', "update node_revisions set body = replace\(body,\'</div>\',\'<?php \$contact_us_node = abc_drupal_node_load\(null, \'my_group\'\);if \(isset\(\$contact_us_node->field_contact_us_message_body\)\) {echo \$contact_us_node->field_contact_us_message_body[0][\'value\'] . \"<br />\";}?></div>\'\) nid=123'", ) == 0 or die "$drushcmd failed: $?";
ah yes, better. can further eliminate need escaping inside perl code using single quoted strings alternative delimiter:
q#update node_revisions set body = replace(body,'</div>','<?php $contact_us_node = abc_drupal_node_load(null, 'my_group');if (isset($contact_us_node->field_contact_us_message_body)) {echo $contact_us_node->field_contact_us_message_body[0]['value'] . "<br />";}?></div>') nid=123'#
we have eliminated escaping levels perl , shell, sql left.
Comments
Post a Comment