tripal_launch_jobs_multi.php 2.5 KB

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