diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-05-19 13:41:52 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-05-19 13:41:52 +0000 |
commit | 34af2a3a8e1f7b9fa6a9797f6d501bc3f2c1fd84 (patch) | |
tree | 22be017f1a80cf81c772f6bb5d7ca69179535214 /modules | |
parent | c5f9c709fd7372eaa301c6f4a4487908cb34d72b (diff) | |
download | brdo-34af2a3a8e1f7b9fa6a9797f6d501bc3f2c1fd84.tar.gz brdo-34af2a3a8e1f7b9fa6a9797f6d501bc3f2c1fd84.tar.bz2 |
CHANGES:
- Rewrote the cron system. Removed cron.module and moved all cron
related options to settings.module. Cron was a confusing thing:
it has been made simpler both in terms of code and configuration.
+ You had to rehash your modules to make the cron show up in
the list. This is no longer required.
+ You couldn't tell what cron "watchdog" or cron "story" were
up to. Instead, we now display a clear description message
for every cron involved.
+ The user interface of setting.module - and the admin section
in general, looks a bit ackward but I couldn't care less and
don't want to see this improve at the time being.
- Improved setting.module:
+ Now uses variable_set().
+ Added some help and documentaition on how to setup cron.
- Improved ./export.
- Updated CHANGELOG.
TODO:
- I'm now going to look into UnConeD's question with regard to
check_output() and $theme->node(), as well as the filter and
macro stuff. I'll probably be fine-tuning setting.module a
bit more on my way.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/cron.module | 65 | ||||
-rw-r--r-- | modules/cvs.module | 22 | ||||
-rw-r--r-- | modules/headline.module | 42 | ||||
-rw-r--r-- | modules/rating.module | 28 | ||||
-rw-r--r-- | modules/settings.module | 38 | ||||
-rw-r--r-- | modules/watchdog.module | 10 | ||||
-rw-r--r-- | modules/watchdog/watchdog.module | 10 |
7 files changed, 102 insertions, 113 deletions
diff --git a/modules/cron.module b/modules/cron.module deleted file mode 100644 index 97b59a10e..000000000 --- a/modules/cron.module +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -function cron_help() { - ?> - <P>Cron (which stands for chronograph) is a periodic command scheduler: it executes commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period of <i>n</i> seconds). Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution.</P> - <P>Note that cron does not guarantee the commands will be executed at the specified interval. However, the engine will make sure that the commands are run as close to the specified intervals as possible.</P> - <P>Check the documentation page for more information about cron and how to setup it correctly.</P> - <?php -} - -function cron_save($edit) { - foreach ($edit as $key=>$value) { - db_query("UPDATE crons SET scheduled = '$value' WHERE module = '$key'"); - } -} - -function cron_execute($name) { - watchdog("message", "cron: executed '". $name ."_cron()'"); - module_invoke($name, "cron"); - db_query("UPDATE crons SET timestamp = ". time() ." WHERE module = '$name'"); -} - -function cron_display() { - $intervals = array(300, 900, 1800, 3600, 7200, 10800, 21600, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200); - - // Perform query: - $result = db_query("SELECT * FROM crons"); - - // Generate output: - $output .= "<FORM ACTION=\"admin.php?mod=cron\" METHOD=\"post\">\n"; - $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n"; - $output .= " <TR><TH>module</TH><TH>period</TH><TH>last run</TH><TH>next run</TH><TH>operations</TH></TR>\n"; - while ($cron = db_fetch_object($result)) { - foreach ($intervals as $value) $period .= "<OPTION VALUE=\"$value\"". (($cron->scheduled == $value) ? " SELECTED" : "") .">every ". format_interval($value) ."</OPTION>\n"; - $output .= " <TR><TD>". check_output($cron->module) ."</TD><TD><SELECT NAME=\"edit[$cron->module]\">$period</SELECT></TD><TD>". ($cron->timestamp ? format_interval(time() - $cron->timestamp) ." ago" : "never") ."</TD><TD>". ($cron->timestamp ? format_interval($cron->timestamp + $cron->scheduled - time()) ." left" : "never") ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=cron&op=execute&name=$cron->module\">execute</A></TD></TR>\n"; - unset($period); - } - $output .= "</TABLE>\n"; - $output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save crons\">\n"; - $output .= "</FORM>\n"; - print $output; -} - -function cron_admin() { - global $op, $edit, $name; - - print "<SMALL><A HREF=\"admin.php?mod=cron\">overview</A> | <A HREF=\"admin.php?mod=cron&op=help\">help</A></SMALL><HR>\n"; - - switch($op) { - case "help": - cron_help(); - break; - case "execute": - cron_execute($name); - cron_display(); - break; - case "Save crons": - cron_save($edit); - // fall through - default: - cron_display(); - } -} - -?> diff --git a/modules/cvs.module b/modules/cvs.module index 8aaf65b08..f31dd2d26 100644 --- a/modules/cvs.module +++ b/modules/cvs.module @@ -1,19 +1,27 @@ <?php function cvs_cron() { - $result = db_query("SELECT * FROM cvs WHERE status = '0' ORDER BY timestamp DESC LIMIT 50"); + if (time() - variable_get("cvs_cron_last", 0) > variable_get("cvs_cron_time", time())) { - while ($cvs = db_fetch_object($result)) { - $body .= "File: $cvs->files\nDate: ". format_date($cvs->timestamp) ."\nUser: $cvs->user\n\n$cvs->message\n----------------------------------------------------------------------\n"; - } + print "cvs cron ran"; - $result = db_query("UPDATE cvs SET status = '1'"); + variable_set("cvs_cron_last", time()); - if ($body) mail(variable_get(cvs_mail, "root@localhost"), "CVS log messages", $body, "From: no-reply"); + $result = db_query("SELECT * FROM cvs WHERE status = '0' ORDER BY timestamp DESC LIMIT 50"); + while ($cvs = db_fetch_object($result)) { + $body .= "File: $cvs->files\nDate: ". format_date($cvs->timestamp) ."\nUser: $cvs->user\n\n$cvs->message\n----------------------------------------------------------------------\n"; + } + $result = db_query("UPDATE cvs SET status = '1'"); + + if ($body) mail(variable_get(cvs_mail, "root@localhost"), "CVS log messages", $body, "From: no-reply"); + } } function cvs_conf() { - return form_textfield(t("CVS digest recepient"), "cvs_mail", variable_get(cvs_mail, "root@localhost"), 30, 55, t("The e-mail address to mail the CVS log messages to. Multiple recipients can be specified by putting a comma between each address.")); + $period = array(43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600)); + $output .= form_textfield(t("Digest recepients"), "cvs_mail", variable_get("cvs_mail", "root@localhost"), 30, 55, t("The e-mail address to mail the CVS log messages to. Multiple recipients can be specified by putting a comma between each address.")); + $output .= form_select(t("Digest interval"), "cvs_cron_time" , variable_get("cvs_cron_time", 86400), $period, t("The time interval at which batched CVS digests are dispatched. Requires crontab.")); + return $output; } function cvs_page() { diff --git a/modules/headline.module b/modules/headline.module index 8402e504a..cfb347086 100644 --- a/modules/headline.module +++ b/modules/headline.module @@ -2,6 +2,33 @@ include_once "modules/backend.class"; +function headline_help() { + ?> + <P>Drupal's headline module both imports and exports RDF/RSS headlines.</P> + <P>A lot of news-oriented websites are now publishing news (headlines) and making their content available through XML, RSS and RDF backend files. They syndicate free content and allow retrieval and further transmission, aggregation, and online publication. In its current state, drupal's headline module supports RDF and RSS backends.</P> + <P>RSS was originally developed by Netscape to allow adding news channels to "My Netscape" sites, but it has since become adopted as the <I>de facto</I> net standard for distributing headlines and brief dynamic texts.</P> + <P>The headline module goes out to a list of configured news sites once an hour or so (driven by cron), downloads new RSS/RDF data and makes it available to your visitors. In addition, your headlines are exported as well and can be retrieved by other sites from <CODE><?php echo path_uri(); ?>export/headlines.rdf</CODE>.</P> + <?php +} + +function headline_conf() { + $period = array(900 => format_interval(900), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 64800 => format_interval(64800), 86400 => format_interval(86400)); + $output .= form_select(t("Update interval"), "headline_cron_time" , variable_get("headline_cron_time", 86400), $period, t("The update interval indicating how often you want to update your headline channels. Requires crontab.")); + return $output; +} + + +function headline_cron() { + if (time() - variable_get("headline_cron_last", 0) > variable_get("headline_cron_time", time())) { + variable_set("headline_cron_last", time()); + + $result = db_query("SELECT * FROM channel"); + while ($channel = db_fetch_object($result)) { + $backend = new Backend($channel->id); + } + } +} + function headline_blocks() { global $theme; @@ -52,21 +79,6 @@ function headline_page() { } } -function headline_cron() { - $result = db_query("SELECT * FROM channel"); - while ($channel = db_fetch_object($result)) { - $backend = new Backend($channel->id); - } -} - -function headline_help() { - ?> - <P>Drupal's headline module both imports and exports RDF/RSS headlines.</P> - <P>A lot of news-oriented websites are now publishing news (headlines) and making their content available through XML, RSS and RDF backend files. They syndicate free content and allow retrieval and further transmission, aggregation, and online publication. In its current state, drupal's headline module supports RDF and RSS backends.</P> - <P>RSS was originally developed by Netscape to allow adding news channels to "My Netscape" sites, but it has since become adopted as the <I>de facto</I> net standard for distributing headlines and brief dynamic texts.</P> - <P>The headline module goes out to a list of configured news sites once an hour or so (driven by cron), downloads new RSS/RDF data and makes it available to your visitors. In addition, your headlines are exported as well and can be retrieved by other sites from <CODE><?php echo path_uri(); ?>export/headlines.rdf</CODE>.</P> - <?php -} function headline_block() { $result = db_query("SELECT * FROM channel"); diff --git a/modules/rating.module b/modules/rating.module index d8382cf7a..3c3e301b7 100644 --- a/modules/rating.module +++ b/modules/rating.module @@ -1,17 +1,27 @@ <?php +function rating_conf() { + $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600)); + $output .= form_select(t("Update interval"), "rating_cron_time" , variable_get("rating_cron_time", 86400), $period, t("The update interval for the user ratings. Requires crontab.")); + return $output; +} + function rating_cron() { - $r1 = db_query("SELECT id FROM users ORDER BY rating DESC"); - while ($account = db_fetch_object($r1)) { - db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'"); - $rating[$account->id] = ++$i; - } + if (time() - variable_get("rating_cron_last", 0) > variable_get("rating_cron_time", time())) { + variable_set("rating_cron_last", time()); + + $r1 = db_query("SELECT id FROM users ORDER BY rating DESC"); + while ($account = db_fetch_object($r1)) { + db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'"); + $rating[$account->id] = ++$i; + } - db_query("DELETE FROM rating"); + db_query("DELETE FROM rating"); - $r2 = db_query("SELECT id FROM users ORDER BY rating DESC"); - while ($account = db_fetch_object($r2)) { - db_query("INSERT INTO rating (user, new, old) VALUES ('$account->id', '". ++$j ."', '". $rating[$account->id] ."')"); + $r2 = db_query("SELECT id FROM users ORDER BY rating DESC"); + while ($account = db_fetch_object($r2)) { + db_query("INSERT INTO rating (user, new, old) VALUES ('$account->id', '". ++$j ."', '". $rating[$account->id] ."')"); + } } } diff --git a/modules/settings.module b/modules/settings.module index 2edda844a..736ddbee2 100644 --- a/modules/settings.module +++ b/modules/settings.module @@ -1,5 +1,17 @@ <?php +function settings_help() { + ?> + <P>Drupal comes with system-wide defaults but the setting-module provides control over many Drupal preferences, behaviors including visual and operational settings.</P> + <H3>Cron</H3> + <P>Some settings require a <I>cron</I> or <I>crontab</I>. Cron (which stands for chronograph) is a periodic command scheduler: it executes commands at intervals specified in seconds. It can be used to control the execution of daily, weekly and monthly jobs (or anything with a period of <i>n</i> seconds). Automating tasks is one of the best ways to keep a system running smoothly, and if most of your administration does not require your direct involvement, cron is an ideal solution.</P> + <P>Whenever <A HREF="<?php echo path_uri(); ?>cron.php"><?php echo path_uri(); ?>cron.php</A> is accessed, cron will run: it checks for the jobs cron controls, and their periods in seconds. If a certain task wasn't executed in the last n seconds, where n is the period of that job, it will be executed. When all the executed commands terminate, cron is done.</P> + <P>The recommended way to setup your cron system is to setup a Unix/Linux crontab that frequently visits <A HREF="<?php echo path_uri(); ?>cron.php"><?php echo path_uri(); ?>cron.php</A>. Note that cron does not guarantee the commands will be executed at the specified interval. However, Drupal will try his best and run the crons as close to the specified intervals as possible. The more you visit cron.php, the more accurate cron will be.</P> + <P>If your hosting company does not allow you to setup crontabs, you can always ask someone else to setup a crontab for you. After all, virtually any Unix/Linux machine with access to the internet can setup a crontab to frequently visit <A HREF="<?php echo path_uri(); ?>cron.php"><?php echo path_uri(); ?>cron.php</A>.</P> + <P>For the Unix/Linux crontab itself, use a browser like <I>lynx</I> or <I>wget</I> but make sure the process terminates: either use <CODE>/usr/bin/lynx -source <?php echo path_uri(); ?>cron.php</CODE> or <CODE>/usr/bin/wget -O /dev/null <?php echo path_uri(); ?>cron.php</CODE>. Take a look at the example scripts in the <CODE>scripts</CODE>-directory and make sure to adjust them to your needs. A good crontab-line to run the cron-script once every hour would be: <CODE>00 * * * * /home/www/drupal/scripts/cron-lynx</CODE>.</P> + <?php +} + function settings_conf() { global $conf, $cmodes, $corder, $themes; @@ -41,7 +53,7 @@ function settings_conf() { // development settings: $output .= "<H3>Development settings</H3>\n"; - $output .= form_select(t("Display timings"), "dev_timing", variable_get(dev_timing, 0), array("Disabled", "Enabled"), t("Display the time it took to generate a page: for drupal development only.")); + $output .= form_select(t("Display timings"), "dev_timing", variable_get(dev_timing, 0), array("Disabled", "Enabled"), t("Display the time it took to generate a page: for Drupal development only.")); return $output; } @@ -57,17 +69,9 @@ function setting_modules() { return $output; } -function settings_save($edit) { - global $conf; - - // save all variables: - if ($edit) { - db_query("DELETE FROM variable"); - foreach ($edit as $name=>$value) db_query("INSERT INTO variable (name, value) VALUES ('". check_input($name) ."', '". check_input($value) ."')"); - } - - // update context: - $conf = variable_init(); +function settings_save($edit = array()) { + // save variables: + foreach ($edit as $name=>$value) variable_set($name, $value); return "all settings have been saved."; } @@ -90,15 +94,23 @@ function settings_overview() { function settings_admin() { global $edit, $op; + print "<SMALL><A HREF=\"admin.php?mod=settings\">overview</A> | <A HREF=\"admin.php?mod=settings&op=help\">help</A></SMALL><HR>\n"; + switch ($op) { + case "help": + settings_help(); + break; case "Reset to defaults": print status(settings_default($edit)); + print settings_overview(); break; case "Save settings": print status(settings_save($edit)); + print settings_overview(); break; + default: + print settings_overview(); } - print settings_overview(); } ?>
\ No newline at end of file diff --git a/modules/watchdog.module b/modules/watchdog.module index a3d04b36d..8397da666 100644 --- a/modules/watchdog.module +++ b/modules/watchdog.module @@ -3,12 +3,18 @@ function watchdog_help() { ?> <P>The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time. The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.</P> - <P>To ease administration, the watchdog will automatically remove old logs.</P> + <P>To ease administration, the watchdog will automatically discard old log entries.</P> <?php } +function watchdog_conf() { + $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200)); + $output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("The time watchdog entries should be kept. Older entries will be automatically discarded. Requires crontab.")); + return $output; +} + function watchdog_cron() { - db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get(watchdog_clear, "302400")); + db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800)); } function watchdog_overview() { diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module index a3d04b36d..8397da666 100644 --- a/modules/watchdog/watchdog.module +++ b/modules/watchdog/watchdog.module @@ -3,12 +3,18 @@ function watchdog_help() { ?> <P>The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time. The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.</P> - <P>To ease administration, the watchdog will automatically remove old logs.</P> + <P>To ease administration, the watchdog will automatically discard old log entries.</P> <?php } +function watchdog_conf() { + $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200)); + $output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("The time watchdog entries should be kept. Older entries will be automatically discarded. Requires crontab.")); + return $output; +} + function watchdog_cron() { - db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get(watchdog_clear, "302400")); + db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800)); } function watchdog_overview() { |