--- multisite_manager.module.orig Tue Aug 28 13:16:32 2007 +++ multisite_manager.module Tue Aug 28 15:08:19 2007 @@ -12,6 +12,8 @@ * test postgres * actual 'management' options? * update.php support + * option to run each sub-site's cron (add default parameter and drupal site + * parameter; requires upgrade script) */ /** @@ -36,18 +38,40 @@ } /** + * Implementation of hook_cron() + */ +function multisite_manager_cron() { + global $db_prefix, $conf; + + // TODO: check if we should run sub-sites' cron jobs + + // find all drupal sites + $res = db_query('SELECT `nid` FROM {node} WHERE `type` = "%s"', 'drupal_site'); + while ($node = db_fetch_object($res)) { + $node = node_load($node->nid); + $node = _multisite_manager_node_url($node); + $node_cron_url = $node->url . '/cron.php'; + watchdog('cron', t('Running cron for %title at "%url".', array('%title' => $node->title, '%url' => $node_cron_url))); + $result = drupal_http_request($node_cron_url); + + if ($result->code >= 400) { + watchdog('cron', t('Error running cron for %title due to %error.', array('%title' => $node->title, '%error' => $result->code .' '. $result->error)), WATCHDOG_WARNING); + } // end if error + } // end while nodes +} // end function multisite_manager_cron() + +/** * Implementation of hook_view(). */ function multisite_manager_view($node, $teaser = FALSE, $page = FALSE) { global $base_url; $node = node_prepare($node, $teaser); if ($node->link) { - $url = str_replace('{base_url}', $base_url, $node->link); - $url = str_replace('{shortname}', $node->shortname, $url); + $node = _multisite_manager_node_url($node); //header('Location: '. $url); $node->content['link'] = array( - '#value' => "$node->title Site", + '#value' => "url\">$node->title Site", '#weight' => 1, ); } @@ -744,4 +768,20 @@ return system_settings_form($form); } -?> +/** + * Gets the node url from the link + * + * @param object $node + * @return object + */ +function _multisite_manager_node_url($node) { + if ($node->link) { + $node->url = str_replace('{base_url}', $base_url, $node->link); + $node->url = str_replace('{shortname}', $node->shortname, $node->url); + } // end if node link + + return $node; +} // end function _multisite_manager_node_url() + +// vim:fenc=utf-8:ft=php:ai:si:ts=2:sw=2:et: +