232 lines
No EOL
6.7 KiB
PHP
Executable file
232 lines
No EOL
6.7 KiB
PHP
Executable file
#!/usr/bin/php5
|
|
<?php
|
|
|
|
/**
|
|
* This set of scripts is intended to accomplish the following:
|
|
*
|
|
* When triggered by a call from cron, survey a master directory of
|
|
* drupal sites and the call the cron.php script on behalf of each of
|
|
* them.
|
|
*/
|
|
|
|
/* PEAR_LIB_DIR PEAR library directory. */
|
|
define('PEAR_LIB_DIR', '/usr/share/pear');
|
|
// dummy error constant for this example
|
|
define('MYCLASS_ERROR_CODE', 1);
|
|
|
|
/* system constants */
|
|
define('EG_APP','egdrupalcron');
|
|
define('EG_DIR','/etc/egscripts/egdrupalcron');
|
|
define('DRUPAL_DIR','/home/sites/public_html/drupal');
|
|
define('DRUPAL_SITES_DIR',DRUPAL_DIR.'/sites');
|
|
define('DRUPAL_SITES_SUFFIX','drupal.kc');
|
|
define('DRUPAL_SITES_SUBDOMAIN','sites');
|
|
define('DRUPAL_CRON_SCRIPT','cron.php');
|
|
define('CURL','/usr/bin/curl');
|
|
define('OPTS','--silent --compressed');
|
|
|
|
/**
|
|
* Program includes go below this
|
|
*/
|
|
/* PHP ini set to local PEAR library */
|
|
ini_set('include_path', PEAR_LIB_DIR);
|
|
/* Require main PEAR class and PLUM classes. */
|
|
require_once('PEAR.php');
|
|
/* include the logging functionality */
|
|
require_once('Log.php');
|
|
/* include file reading/writing functionality */
|
|
require_once('File.php');
|
|
/* include command line argument processing functionality */
|
|
require_once('Console/Getopt.php');
|
|
/* include command line argument processing functionality */
|
|
require_once('Config.php');
|
|
|
|
/**
|
|
* DrupalCron class - class that knows how to find a list of Drupal sites in
|
|
* a multi-site configuration, and trigger their cron.php scripts
|
|
*
|
|
* @author Dave Lane <dave@egressive.com>
|
|
* @copyright Copyright (C) 2005 Egressive Limited (www.egressive.com)
|
|
* @version $Id: egawstats.php 0 2005-08-18 08:07:26Z dave $
|
|
* @package egawstats
|
|
*/
|
|
|
|
class DrupalCron extends PEAR {
|
|
/**
|
|
* @var array $domain a mixed array of "name" and "values"
|
|
* for the current domain.
|
|
* @access private
|
|
*/
|
|
private $domain = array();
|
|
/**
|
|
* @var array $domain_array array of strings representing drupal
|
|
* site directory names
|
|
* @access private
|
|
*/
|
|
private $domain_array = array();
|
|
|
|
/**
|
|
* @var object $logger - reference to a PEAR log object
|
|
* @access private
|
|
*/
|
|
private $logger = null;
|
|
/**
|
|
* @var string $short_args - one letter command line arguments
|
|
* obeys GNU args conventions - args take form -a or -b value or -ab value
|
|
* for multiple arguments
|
|
* @access private
|
|
*/
|
|
private $short_args = "psa";
|
|
/**
|
|
* @var string $long_args - full word command line arguments, more memorable
|
|
* obeys GNU args conventions - args take form --flag or --flagwithvalue=value
|
|
* @access private
|
|
*/
|
|
private $long_args = array('rebuildpages','rebuildstats','rebuildconfs');
|
|
/**
|
|
* @var array $options_array - array of command line arguments and values
|
|
* from the Console/Getopts PEAR class
|
|
* @access private
|
|
*/
|
|
private $options_array = array();
|
|
/**
|
|
* @var array $options - array of just the command line arguments and values
|
|
* @access private
|
|
*/
|
|
private $options = array();
|
|
|
|
public function __construct($logger) {
|
|
$this->logger = $logger;
|
|
|
|
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
|
|
|
|
//
|
|
// Error handling
|
|
//
|
|
$this->setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
|
}
|
|
|
|
/**
|
|
* get the command line arguments
|
|
*/
|
|
public function get_args() {
|
|
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
|
|
$cli_args = new Console_Getopt();
|
|
$args = $cli_args->readPHPArgv();
|
|
array_shift($args);
|
|
$this->options_array = $cli_args->getopt2($args,$this->short_args,$this->long_args);
|
|
$this->options = $this->options_array[0];
|
|
}
|
|
|
|
/**
|
|
* put the command line arguments into an array that's useful
|
|
* elsewhere in the code...
|
|
*/
|
|
public function process_args() {
|
|
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
|
|
|
|
// first, get the command line arguments
|
|
$this->get_args();
|
|
//print_r($this->options);
|
|
if (count($this->options) and
|
|
(count($this->options_array[0]) or count($this->options_array[1]))) {
|
|
foreach($this->options as $option) {
|
|
list($key,$value) = $option;
|
|
if ($value) {
|
|
$this->logger->log('option['.$key.'] = '.$value,PEAR_LOG_DEBUG);
|
|
} else {
|
|
$this->logger->log('option '.$key.' specified',PEAR_LOG_DEBUG);
|
|
}
|
|
}
|
|
} else {
|
|
$this->logger->log('no command line options supplied',PEAR_LOG_DEBUG);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* put the site definitions in the configuration files into an
|
|
* array that's useful elsewhere in the code...
|
|
*/
|
|
public function get_sites() {
|
|
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
|
|
|
|
$sitepaths = glob(DRUPAL_SITES_DIR.'/*.'.DRUPAL_SITES_SUFFIX);
|
|
print_r($sitepaths);
|
|
$this->site_array = $sitepaths;
|
|
}
|
|
|
|
/**
|
|
* run the whole process...
|
|
*/
|
|
public function run() {
|
|
$this->logger->log(__CLASS__.'->'.__FUNCTION__,PEAR_LOG_DEBUG);
|
|
|
|
// process command line argments, if any
|
|
$this->process_args();
|
|
// get site directories...
|
|
$this->get_sites();
|
|
|
|
// shorten things a bit...
|
|
|
|
foreach ($this->site_array as $sitepath) {
|
|
$sitename = basename($sitepath);
|
|
$sitecomponents = explode('.',$sitename);
|
|
$base_url = array_slice($sitecomponents,-2,2);
|
|
$sub_domain = array_slice($sitecomponents,0,-2);
|
|
$domain = DRUPAL_SITES_SUBDOMAIN.".".implode('.',$sub_domain).".".implode('.',$base_url);
|
|
echo "domain = $domain\n";
|
|
$url = "http://".$domain."/".DRUPAL_CRON_SCRIPT;
|
|
$this->logger->log("run ".DRUPAL_CRON_SCRIPT." for $domain by calling $url",PEAR_LOG_INFO);
|
|
|
|
//$result = file_get_contents($url,'r');
|
|
// create a new curl resource
|
|
/*$ch = curl_init();
|
|
|
|
// set URL and other appropriate options
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
// grab URL and pass it to the browser
|
|
curl_exec($ch);
|
|
|
|
// close curl resource, and free up system resources
|
|
curl_close($ch);*/
|
|
$command = CURL." ".OPTS." ".$url;
|
|
$result = exec($command);
|
|
//echo "result = $result";
|
|
//print_r($sitecomponents);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* deal with errors in a uniform way...
|
|
*/
|
|
function handleError($error) {
|
|
global $logger;
|
|
$logger->log(EG_APP.' error: '.$error->getMessage(),'.',PEAR_LOG_ERR);
|
|
}
|
|
|
|
|
|
// initialise logging
|
|
$logger = &Log::singleton('console','','egdrupalcron.php');
|
|
$logger->log("***** Starting egdrupalcron.php *****",PEAR_LOG_DEBUG);
|
|
|
|
// set up default error handling
|
|
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
|
|
|
/**
|
|
* Program logic goes below this
|
|
*/
|
|
|
|
$conf_filename="";
|
|
|
|
$cron = new DrupalCron($logger);
|
|
|
|
$cron->run();
|
|
|
|
// final logging message
|
|
$logger->log("===== Finishing egdrupalcron.php =====",PEAR_LOG_DEBUG);
|
|
?>
|