在EE2 Forums和EE1 Forums,你会发现使用cron作业的各种事情很多人。
最流行的应用似乎是automatically closing expired entries,使用命令行PHP脚本计划cron作业:
#!usr/local/bin/php -n
<?php global $PREFS; // ee_cli_sql.php v0.3.5
/* Copyright (c) 2003 - 2007 EllisLab, Inc. --- ExpressionEngine 1.6.0.
Some code by Ingmar Greil, 2007. <[email protected]>
My modfications and code released under a Creative Commons
"Attribution" license: http://creativecommons.org/licenses/by/2.0/
This PHP command line script allows you to perform arbitrary
SQL queries on your EE database. There will be no visible output
(in this case we'd simply use the Query module in a template, right?),
since the whole point is to run this script unattended.
Put this file in your EE "system" folder, make sure the executable
bit is set (chmod +x ee_cli_sql.php), then call manually or via cron.
Try "crontab -e".
"5 * * * * command" will run your script 5 minutes past the hour, every hour.
"0,10,20,30,40,50 6-22 * * * 1-5" will run your script every ten minutes
between 6am and 10pm, except on weekends. The general syntax is:
<Minute> <Hour> <Day> <Month> <Day of Week> <Command line>
*/
// This query will set all expired entries to "closed" status:
$query = "UPDATE `exp_weblog_titles` SET status = 'closed' WHERE status <> 'closed'
AND expiration_date <> '0' AND expiration_date < UNIX_TIMESTAMP()";
// Change the above query to suit your needs.
// That's it, folks! No user-serviceable parts below.
define("EXT",".php"); // Get around EE's security mechanisms. Kludgy? Hell, yes.
// Got a better solution? I am all ears.
require("config".EXT); // Read the config file
require("core/core.prefs".EXT); // Load the PREFS cass
$PREFS = new Preferences(); $PREFS->core_ini = $conf; unset($conf);
$db = mysql_connect( // Handle the connection to the database:
$PREFS->core_ini['db_hostname'], // hostname,
$PREFS->core_ini['db_username'], // username and
$PREFS->core_ini['db_password']); // password are all pulled automatically.
mysql_select_db($PREFS->core_ini['db_name']); // Now it's selecting the appropriate db,
mysql_query($query,$db); // performing the actual query, then
mysql_close(); // cleaning up after ourselves. Done.
?>
的ExpressionEngine维基文章提供了一些洞察脚本是如何设置和安排:
这个PHP命令行脚本允许您在您的EE数据库上执行任意SQL查询 。将不会有可见的输出 (在这种情况下, 只需使用 模板中的查询模块,对吗?),因为整个 点是无人值守地运行此脚本 。
将这个文件在你的EE“系统” 文件夹,确保可执行位 设置(使用chmod + X ee_cli_sql.php),然后 呼叫手动或通过cron。
如果你不想使用CLI(命令行界面)来管理你的cron作业,你可能会考虑从EllisLab的Cron Plugin,它可以设置为调用一个常规,计划的基础上一个插件或模块。
来源
2011-05-26 17:20:44
rjb
自动关闭过期的条目链接无法使用 – williamcarswell 2013-01-28 13:21:44
当EllisLab 2012年11月重新设计了自己的网站,他们似乎并没有在维基携带 - 所有的链接都是简单的301重定向到'ellislab.com'。幸运的是,我能够从[Internet Archive WayBack Machine]中找到原始文章(http://web.archive。组织/网络/ 20120103211342/HTTP://expressionengine.com/wiki/Automatically_close_expired_entries) – rjb 2013-01-28 19:30:57