2009-07-06 13:48:10 +00:00
#!/usr/bin/env php
2007-03-01 09:15:42 +00:00
< ? php
2007-03-01 19:53:26 +00:00
/**
2018-01-23 21:03:08 +00:00
* @ file
2007-03-01 09:15:42 +00:00
* Drupal shell execution script
2007-03-01 19:53:26 +00:00
*
2007-03-01 09:15:42 +00:00
* Check for your PHP interpreter - on Windows you ' ll probably have to
* replace line 1 with
* #!c:/program files/php/php.exe
2007-03-01 19:53:26 +00:00
*
2007-03-01 09:15:42 +00:00
* @ param path Drupal ' s absolute root directory in local file system ( optional ) .
* @ param URI A URI to execute , including HTTP protocol prefix .
*/
2018-01-23 21:03:08 +00:00
Issue #1540390 by smustgrave, cosmicdreams, sun, alexpott, Chi, Mile23, dawehner, RobLoach, cweagans, David_Rothstein, webchick, borisson_, Unitoch: Deprecate the drupal.sh script
2022-12-17 00:54:15 +00:00
trigger_error ( 'drupal.sh is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3241346' , E_USER_DEPRECATED );
2007-03-05 16:13:28 +00:00
$script = basename ( array_shift ( $_SERVER [ 'argv' ]));
2007-03-01 09:15:42 +00:00
2008-02-17 20:09:52 +00:00
if ( in_array ( '--help' , $_SERVER [ 'argv' ]) || empty ( $_SERVER [ 'argv' ])) {
2007-03-01 09:15:42 +00:00
echo <<< EOF
Execute a Drupal page from the shell .
2007-03-05 16:13:28 +00:00
Usage : { $script } [ OPTIONS ] " <URI> "
2024-01-11 14:36:13 +00:00
Example : { $script } " http://my-site.org/node "
2007-03-01 09:15:42 +00:00
All arguments are long options .
-- help This page .
-- root Set the working directory for the script to the specified path .
To execute Drupal this has to be the root directory of your
Drupal installation , f . e . / home / www / foo / drupal ( assuming Drupal
2007-03-05 16:13:28 +00:00
running on Unix ) . Current directory is not required .
Use surrounding quotation marks on Windows .
2007-03-01 09:15:42 +00:00
-- verbose This option displays the options as they are set , but will
produce errors from setting the session .
URI The URI to execute , i . e . http :// default / foo / bar for executing
2008-12-20 18:24:41 +00:00
the path '/foo/bar' in your site 'default' . URI has to be
2007-07-02 14:41:37 +00:00
enclosed by quotation marks if there are ampersands in it
2008-12-20 18:24:41 +00:00
( f . e . index . php ? q = node & foo = bar ) . Prefix 'http://' is required ,
2007-03-01 09:15:42 +00:00
and the domain must exist in Drupal ' s sites - directory .
2007-03-01 19:53:26 +00:00
2007-03-01 09:15:42 +00:00
If the given path and file exists it will be executed directly ,
2007-03-01 19:53:26 +00:00
i . e . if URI is set to http :// default / bar / foo . php
and bar / foo . php exists , this script will be executed without
2012-05-07 02:50:05 +00:00
bootstrapping Drupal . To execute Drupal ' s update . php , specify
2014-10-04 15:29:36 +00:00
http :// default / update . php as the URI .
2007-03-05 16:13:28 +00:00
To run this script without -- root argument invoke it from the root directory
of your Drupal installation with
./ scripts / { $script }
2007-03-01 09:15:42 +00:00
\n
EOF ;
exit ;
}
$cmd = 'index.php' ;
2018-08-13 10:13:36 +00:00
// define default settings
2007-03-01 09:15:42 +00:00
$_SERVER [ 'HTTP_HOST' ] = 'default' ;
$_SERVER [ 'PHP_SELF' ] = '/index.php' ;
$_SERVER [ 'REMOTE_ADDR' ] = '127.0.0.1' ;
2009-09-19 10:38:47 +00:00
$_SERVER [ 'SERVER_SOFTWARE' ] = NULL ;
2007-03-01 09:15:42 +00:00
$_SERVER [ 'REQUEST_METHOD' ] = 'GET' ;
$_SERVER [ 'QUERY_STRING' ] = '' ;
$_SERVER [ 'PHP_SELF' ] = $_SERVER [ 'REQUEST_URI' ] = '/' ;
2009-07-06 13:48:10 +00:00
$_SERVER [ 'HTTP_USER_AGENT' ] = 'console' ;
2007-03-01 09:15:42 +00:00
// toggle verbose mode
if ( in_array ( '--verbose' , $_SERVER [ 'argv' ])) {
2018-01-23 21:03:08 +00:00
$_verbose_mode = TRUE ;
2007-03-01 09:15:42 +00:00
}
else {
2018-01-23 21:03:08 +00:00
$_verbose_mode = FALSE ;
2007-03-01 09:15:42 +00:00
}
// parse invocation arguments
while ( $param = array_shift ( $_SERVER [ 'argv' ])) {
switch ( $param ) {
case '--root' :
// change working directory
$path = array_shift ( $_SERVER [ 'argv' ]);
if ( is_dir ( $path )) {
chdir ( $path );
if ( $_verbose_mode ) {
echo " cwd changed to: { $path } \n " ;
}
}
else {
echo " \n ERROR: { $path } not found. \n \n " ;
}
break ;
2007-03-01 19:53:26 +00:00
2007-03-01 09:15:42 +00:00
default :
if ( substr ( $param , 0 , 2 ) == '--' ) {
// ignore unknown options
break ;
}
else {
// parse the URI
$path = parse_url ( $param );
2007-03-01 19:53:26 +00:00
2007-03-01 09:15:42 +00:00
// set site name
if ( isset ( $path [ 'host' ])) {
$_SERVER [ 'HTTP_HOST' ] = $path [ 'host' ];
}
2007-03-01 19:53:26 +00:00
2007-03-01 09:15:42 +00:00
// set query string
if ( isset ( $path [ 'query' ])) {
$_SERVER [ 'QUERY_STRING' ] = $path [ 'query' ];
parse_str ( $path [ 'query' ], $_GET );
$_REQUEST = $_GET ;
}
2007-03-01 19:53:26 +00:00
2012-09-02 04:50:06 +00:00
// set file to execute or Drupal path (clean URLs enabled)
2007-03-01 09:15:42 +00:00
if ( isset ( $path [ 'path' ]) && file_exists ( substr ( $path [ 'path' ], 1 ))) {
$_SERVER [ 'PHP_SELF' ] = $_SERVER [ 'REQUEST_URI' ] = $path [ 'path' ];
$cmd = substr ( $path [ 'path' ], 1 );
}
2008-10-12 04:30:09 +00:00
elseif ( isset ( $path [ 'path' ])) {
2012-04-29 15:16:27 +00:00
$_SERVER [ 'SCRIPT_NAME' ] = '/' . $cmd ;
$_SERVER [ 'REQUEST_URI' ] = $path [ 'path' ];
2007-03-01 09:15:42 +00:00
}
2007-03-01 19:53:26 +00:00
2007-03-01 09:15:42 +00:00
// display setup in verbose mode
if ( $_verbose_mode ) {
echo " Hostname set to: { $_SERVER [ 'HTTP_HOST' ] } \n " ;
echo " Script name set to: { $cmd } \n " ;
2012-04-29 15:16:27 +00:00
echo " Path set to: { $path [ 'path' ] } \n " ;
2007-03-01 09:15:42 +00:00
}
}
break ;
}
}
if ( file_exists ( $cmd )) {
include $cmd ;
}
else {
echo " \n ERROR: { $cmd } not found. \n \n " ;
}
exit ();