--- multisite_manager.install.orig Tue Sep 4 13:18:32 2007 +++ multisite_manager.install Tue Sep 4 13:56:20 2007 @@ -12,6 +12,7 @@ nid int(10) unsigned NOT NUL shortname varchar(45) NOT NULL, profile varchar(255) NOT NULL, link varchar(255) NOT NULL default '', + run_cron tinyint NOT NULL default '0', db_prefix varchar(45) NOT NULL default '', db_user varchar(45) NOT NULL default '', db_path varchar(45) NOT NULL default '', @@ -28,6 +29,7 @@ nid int NOT NULL default '0' shortname varchar(45) NOT NULL, profile varchar(255) NOT NULL, link varchar(255) NOT NULL default '', + run_cron smallint NOT NULL default '0', db_prefix varchar(45) NOT NULL default '', db_user varchar(45) NOT NULL default '', db_path varchar(45) NOT NULL default '', @@ -48,3 +50,25 @@ variable_del('multisite_manager_dbpref variable_del('multisite_manager_dbpath_default'); variable_del('multisite_manager_link_default'); } + +// following versioning described at: http://drupal.org/node/136078 +// XYZZ +// X = Drupal major number (eg 5 = 5.x) +// Y = Module major number (eg 0 = 0.x, 1 = 1.x) +// ZZ = increment +function multisite_manager_update_5000() { + $items = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $items[] = update_sql("ALTER TABLE {drupal_site} ADD COLUMN run_cron tinyint NOT NULL default '0' AFTER link"); + break; + case 'pgsql': + $items[] = update_sql("ALTER TABLE {drupal_site} ADD COLUMN run_cron smallint NOT NULL default '0'"); + break; + } // end switch db_type + return $items; +} // end function multisite_manager_update_5000() + +// vim:fenc=utf-8:ft=php:ai:si:ts=2:sw=2:et: + --- multisite_manager.module.orig Tue Aug 28 13:16:32 2007 +++ multisite_manager.module Tue Sep 4 13:57:50 2007 @@ -36,18 +36,51 @@ ); } /** + * Implementation of hook_cron() + */ +function multisite_manager_cron() { + global $db_prefix, $conf; + + // check if we should run sub-sites' cron jobs + if (!variable_get('multisite_manager_run_cron', 0)) { + return; + } // end if not run cron + + // 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'; + + // if don't run this site's cron jobs + if (!$node->run_cron) { + watchdog('cron', t('Skipping cron for %title.', array('%title' => $node->title))); + } + // if run this site's cron jobs + else { + 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, ); } @@ -122,6 +155,7 @@ 'db_user' => '', 'db_pass' => '', 'db_path' => variable_get('multisite_manager_dbpath_default', ''), 'link' => variable_get('multisite_manager_link_default', ''), + 'run_cron' => variable_get('multisite_manager_run_cron', 0), ); } @@ -154,6 +188,13 @@ '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5 ); + $form['run_cron'] = array( + '#type' => 'checkbox', + '#title' => t('Run Drupal Sites\' Cron'), + '#required' => FALSE, + '#default_value' => isset($node->run_cron)?$node->run_cron:$defaults['run_cron'], + '#description' => t('This sets whether this drupal site\'s cron jobs will be run when the master site\'s cron is run.'), + ); $form['shortname'] = array( '#required' => TRUE, '#type' => 'textfield', @@ -514,7 +555,7 @@ global $multisite_manager_installmodul //Store some info about the new site in the main site. //Note that we DO NOT store the password - db_query("INSERT INTO {drupal_site} (vid, nid, shortname, profile, link, db_prefix, db_user, db_path) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s')", $node->vid, $node->nid, $node->shortname, $node->profile, $node->link, $node->db_prefix, $node->db_user, $node->db_path); + db_query("INSERT INTO {drupal_site} (vid, nid, shortname, profile, link, run_cron, db_prefix, db_user, db_path) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $node->vid, $node->nid, $node->shortname, $node->profile, $node->link, $node->run_cron, $node->db_prefix, $node->db_user, $node->db_path); include_once './includes/install.inc'; @@ -610,10 +651,11 @@ */ function multisite_manager_update($node) { if (user_access('advanced database setup')) { db_query("UPDATE {drupal_site} SET - link = '%s', shortname = '%s', db_prefix = '%s', db_user = '%s', db_path = '%s' + link = '%s', shortname = '%s', run_cron = '%s', db_prefix = '%s', db_user = '%s', db_path = '%s' WHERE vid = %d", $node->link, $node->shortname, + $node->run_cron, $node->db_prefix, $node->db_user, $node->db_path, @@ -623,7 +665,7 @@ db_query("UPDATE {drupal_site} SET } } else { - db_query("UPDATE {drupal_site} SET link = '%s' WHERE vid = %d", $node->link, $node->vid); + db_query("UPDATE {drupal_site} SET link = '%s', run_cron = '%s' WHERE vid = %d", $node->link, $node->run_cron, $node->vid); } } @@ -694,7 +736,7 @@ /** * Implementation of hook_load(). */ function multisite_manager_load($node) { - $additions = db_fetch_object(db_query('SELECT shortname, profile, link, db_prefix, db_user, db_path FROM {drupal_site} WHERE vid = %d', $node->vid)); + $additions = db_fetch_object(db_query('SELECT shortname, profile, link, run_cron, db_prefix, db_user, db_path FROM {drupal_site} WHERE vid = %d', $node->vid)); return $additions; } @@ -711,7 +753,15 @@ $defaults = array('db_prefix' => '{sho 'db_path' => '', 'link' => '{base_url}/site/{shortname}', 'profile' => 'default', + 'run_cron' => 0, ); + $form['multisite_manager_run_cron'] = array( + '#type' => 'checkbox', + '#title' => t('Run drupal sites\' cron jobs'), + '#required' => FALSE, + '#default_value' => variable_get('multisite_manager_run_cron', $defaults['run_cron']), + '#description' => t('This sets whether each drupal site\'s cron jobs will be run when this master site\'s cron is run. This changes whether any drupal sites will have their cron jobs executed regardless of each individual sites\' settings for running cron jobs.') + ); $form['multisite_manager_dbprefix_default'] = array( '#type' => 'textfield', '#title' => t('Table prefix default'), @@ -744,4 +794,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: +