tripal_launch_jobs_multi.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @file
  4. * This script can be used to launch jobs on a multi-site Drupal installation
  5. */
  6. include_once './includes/bootstrap.inc';
  7. fwrite(STDOUT, "Running Tripal Job Launcher\n");
  8. /**
  9. * SETTINGS
  10. */
  11. //the location of the 'sites' directory relative to this script.
  12. $sites_dir = 'sites';
  13. $debug=0;
  14. /**
  15. * END SETTINGS
  16. */
  17. //error_reporting(E_ALL);
  18. include ("Console/Getopt.php");
  19. // initialize object
  20. $cg = new Console_Getopt();
  21. /* define list of allowed options - p = h:sitename, u:username */
  22. $allowed_short_options = "h:u:";
  23. // read the command line
  24. $args = $cg->readPHPArgv();
  25. // get the options
  26. $ret = $cg->getopt($args, $allowed_short_options);
  27. // check for errors and die with an error message if there was a problem
  28. if (PEAR::isError($ret)) {
  29. die("Error in command line: " . $ret->getMessage() . "\n");
  30. }
  31. ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . './scripts');
  32. /*
  33. * This doesn't work in every case: getopt function is not always available
  34. $options = getopt("h:r:");
  35. var_dump($options);
  36. */
  37. $hostname = "";
  38. $username = "";
  39. // parse the options array
  40. $opts = $ret[0];
  41. if (sizeof($opts) > 0) {
  42. // if at least one option is present
  43. foreach ($opts as $opt) {
  44. switch ($opt[0]) {
  45. case 'h':
  46. $hostname = $opt[1];
  47. break;
  48. case 'u':
  49. $username = $opt[1];
  50. break;
  51. default:
  52. fwrite(STDOUT, 'Usage: \n');
  53. fwrite(STDOUT, '- h hostname\n');
  54. fwrite(STDOUT, " -u username\n");
  55. break;
  56. }
  57. }
  58. }
  59. else {
  60. fwrite(STDOUT, "Usage: \n");
  61. fwrite(STDOUT, " -h hostname\n");
  62. fwrite(STDOUT, " -u username\n");
  63. }
  64. runjob($hostname, $username);
  65. /**
  66. * Runs tripal_launch_jobs() as the specified user
  67. *
  68. * @ingroup tripal_core
  69. */
  70. function runjob($sitename, $username) {
  71. global $user;
  72. $_SERVER['SCRIPT_NAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php';
  73. $_SERVER['SCRIPT_FILENAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php';
  74. $_SERVER['HTTP_HOST'] = $sitename;
  75. $_SERVER['REMOTE_ADDR'] = 'localhost';
  76. $_SERVER['REQUEST_METHOD'] = 'GET';
  77. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  78. if (!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s'", $username))) {
  79. fwrite(STDOUT, "'$username' is not a valid Drupal username. exiting...\n");
  80. exit;
  81. }
  82. $user = $username;
  83. $user = user_load(array('name' => $username));
  84. tripal_jobs_launch();
  85. }