This patch allows php-eval
to be used with php code from stdin.
Usage:
echo 'print "hello world!\n";' | drush php-eval -
The arg to php-eval should be '-' to indicate that the php code should be read from stdin. This could have been a test to check for an empty command, but then drush would hang waiting for input if you ran php-eval with no parameters.
There is an existing unix standard that - in place of a file means stdin; maybe this patch should have modified php-script instead, but I think this is okay as well.
The patch still needs documentation. I'm sketchy on the value of this, so someone who cares more about it will have to finish it up. For the record, I was working on this to investigate #926780: Use drush to write standard Unix scripts in php.
Comment | File | Size | Author |
---|---|---|---|
#11 | drush-script-stdin.patch | 653 bytes | greg.1.anderson |
php-eval-from-stdin.patch | 1.14 KB | greg.1.anderson |
Comments
Comment #2
greg.1.anderson CreditAttribution: greg.1.anderson commentedComment #3
John_Buehrer CreditAttribution: John_Buehrer commentedYes, using STDIN with php-script would be appreciated too.
Meanwhile I'm wondering how to rebuild content_access
permissions in an automated way, ie, via Bash & Drush.
I'm guessing the error below isn't from the new STDIN feature?
According to Pro Drupal Development p.247: "Simply provide the form ID and the values
for the form, and call drupal_execute()". But drush is nowhere to be found in that book.
(So who's the pro? :-)
Comment #4
greg.1.anderson CreditAttribution: greg.1.anderson commentedPlease do not change the topic of existing issues. Start new issues for new questions. Thank you.
Are you getting the error above after applying the patch in #0 manually? It has not been committed to HEAD yet.
Comment #5
John_Buehrer CreditAttribution: John_Buehrer commentedYes I applied the patch manually, though with a slight problem as shown below.
I don't know whether the above error is related to running via STDIN or not,
or trying to do this via Drush or not, or for other reasons.
Hence I put it here as an example of a real STDIN use-case.
Comment #6
greg.1.anderson CreditAttribution: greg.1.anderson commentedYou should try the same script with php-script. I notice that your alias specifies -r but not -l. Does it work for other drush operations?
Comment #7
John_Buehrer CreditAttribution: John_Buehrer commentedIn my environment, this Drush alias works well for module downloads and make.
I use "-r" because I'm typically don't `cd` into Drupal dirs during my work.
I don't use "-l" because "--help" says that's for multisite which I don't use.
Does it do other things, and hence I should use it anyway??
With php-script (and without STDIN) I get a similar failure as above.
I'm not sure where to ask about this.
Is Drush intended to be used this way?
Is more PHP context needed - eg, to run this snippet as a specific user?
Or maybe this problem is specific to the content_access module?
Do other people (such as yourself) see the same error?
Thanks.
Comment #8
John_Buehrer CreditAttribution: John_Buehrer commentedSome more info:
I get the same error if I replace "node_configure_rebuild_confirm" with "garbage_string".
But the former string does appear in my installation:
This quest comes when I see a common message in the status report:
"The content access permissions need to be rebuilt. Please visit this page."
(http://localhost:8888/mySite/admin/content/node-settings/rebuild)
With a front-end Curl login (http://drupal.org/node/89710),
I discover the form_id of this rebuild page:
Often I can simply "press the button" with another Curl operation.
But rebuilding these permissions runs some Javascript with a progress bar,
and more HTTP GETs - which are hard to parse.
So I thought I'd invoke the form instead via the Drush back-end
with a php snippet read from STDIN.
Would you expect Drush to work for this?
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedThe first thing to test is whether your alias is bootstrapping your Drupal site correctly. Does
dr status
show that your database is connected?I would think that you would want to do the above operation more than once, and therefore would use drush php-script rather than php-eval from stdin.
Comment #10
John_Buehrer CreditAttribution: John_Buehrer commentedMy Drush->Drupal DB connection seems OK, can you confirm this based on info below?
Should the Drupal user shown below be "root" rather than "Anonymous"?
Can you confirm that my php-eval example above works or fails
in a known-to-be-good Drush/Drupal installation -
and whether this sort of Drush thing is expected to work in the first place ?
Running the same php-script code in succession just gives the same error over again.
Is there another implementation of "do the above operation more than once" ?
The Pro Drupal Development book mentions a batch mode on p.560 but I'm not
sure whether this applies to Drush - no examples are given of callbacks & Drush.
Thanks for your assistance.
Please let me know if there's a better place for this topic.
I guess this exceeds the STDIN test case for php-eval ?
Comment #11
greg.1.anderson CreditAttribution: greg.1.anderson commentedI think it is reasonable to allow evaluation from stdin, but it should be supported in php-script, not php-eval. Patch included.
@John_Buehrer: If you are still having trouble with #3 - #10, try again with HEAD and post in a separate issue.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedLooks reasonable to me. Committed.
The OP sounds like he should just do
drush eval "node_access_rebuild();"