Tripal v1.1 (6.x-1.1)
|
00001 <?php 00002 00008 include_once './includes/bootstrap.inc'; 00009 00010 fwrite(STDOUT, "Running Tripal Job Launcher\n"); 00011 00016 //the location of the 'sites' directory relative to this script. 00017 $sites_dir = 'sites'; 00018 $debug=0; 00019 00024 //error_reporting(E_ALL); 00025 00026 include ("Console/Getopt.php"); 00027 00028 // initialize object 00029 $cg = new Console_Getopt(); 00030 00031 /* define list of allowed options - p = h:sitename, u:username */ 00032 $allowed_short_options = "h:u:"; 00033 00034 // read the command line 00035 $args = $cg->readPHPArgv(); 00036 00037 // get the options 00038 $ret = $cg->getopt($args, $allowed_short_options); 00039 00040 // check for errors and die with an error message if there was a problem 00041 if (PEAR::isError($ret)) { 00042 die("Error in command line: " . $ret->getMessage() . "\n"); 00043 } 00044 00045 ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . './scripts'); 00046 00047 /* 00048 * This doesn't work in every case: getopt function is not always available 00049 $options = getopt("h:r:"); 00050 var_dump($options); 00051 */ 00052 00053 $hostname = ""; 00054 $username = ""; 00055 00056 // parse the options array 00057 $opts = $ret[0]; 00058 if (sizeof($opts) > 0) { 00059 // if at least one option is present 00060 foreach ($opts as $opt) { 00061 switch ($opt[0]) { 00062 case 'h': 00063 $hostname = $opt[1]; 00064 break; 00065 case 'u': 00066 $username = $opt[1]; 00067 break; 00068 default: 00069 fwrite(STDOUT, 'Usage: \n'); 00070 fwrite(STDOUT, '- h hostname\n'); 00071 fwrite(STDOUT, " -u username\n"); 00072 break; 00073 00074 } 00075 } 00076 } 00077 else { 00078 fwrite(STDOUT, "Usage: \n"); 00079 fwrite(STDOUT, " -h hostname\n"); 00080 fwrite(STDOUT, " -u username\n"); 00081 00082 } 00083 00084 runjob($hostname, $username); 00085 00091 function runjob($sitename, $username) { 00092 global $user; 00093 00094 $_SERVER['SCRIPT_NAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php'; 00095 $_SERVER['SCRIPT_FILENAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php'; 00096 $_SERVER['HTTP_HOST'] = $sitename; 00097 $_SERVER['REMOTE_ADDR'] = 'localhost'; 00098 $_SERVER['REQUEST_METHOD'] = 'GET'; 00099 00100 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 00101 00102 if (!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s'", $username))) { 00103 fwrite(STDOUT, "'$username' is not a valid Drupal username. exiting...\n"); 00104 exit; 00105 } 00106 00107 $user = $username; 00108 $user = user_load(array('name' => $username)); 00109 00110 tripal_jobs_launch(); 00111 }