tripal_launch_jobs_multi.php 2.5 KB

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