function drush_core_php_script

8.0.x core.drush.inc drush_core_php_script()
6.x core.drush.inc drush_core_php_script()
7.x core.drush.inc drush_core_php_script()
3.x core.drush.inc drush_core_php_script()
4.x core.drush.inc drush_core_php_script()
5.x core.drush.inc drush_core_php_script()
master core.drush.inc drush_core_php_script()

Command callback. Runs "naked" php scripts.

File

commands/core/core.drush.inc, line 610
Core drush commands.

Code

function drush_core_php_script() {
  $args = func_get_args();

  // Array of paths to search for scripts
  $searchpath['DIR'] = dirname(__FILE__);
  $searchpath['cwd'] = drush_cwd();

  // Additional script paths, specified by 'script-path' option
  if ($script_path = drush_get_option('script-path', FALSE)) {
    foreach (explode(":", $script_path) as $path) {
      $searchpath[] = $path;
    }
  }

  if (empty($args)) {
    // List all available scripts.
    $all = array();
    foreach ($searchpath as $key => $path) {
      $recurse = !$key == 'cwd';
      $all = array_merge($all, array_keys(drush_scan_directory($path, '/\.php$/', array('.', '..', 'CVS'), NULL, $recurse)));
    }
    drush_print(implode("\n", $all));
  }
  else {
    // Execute the specified script.
    $script = $args[0];
    if (!preg_match('/\.php$/i', $script)) {
      $script .= '.php';
    }
    $found = FALSE;
    foreach ($searchpath as $path) {
      $script_filename = $path . '/' . $script;
      if (file_exists($script_filename)) {
        include ($script_filename);
        $found = TRUE;
        break;
      }
      $all[] = $script_filename;
    }

    if (!$found) {
      drush_set_error('Script not found.', dt('Unable to find any of the following: @files', array('@files' => implode(', ', $all))));
    }
  }
}