在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