本文整理汇总了PHP中tag_cron函数的典型用法代码示例。如果您正苦于以下问题:PHP tag_cron函数的具体用法?PHP tag_cron怎么用?PHP tag_cron使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tag_cron函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $CFG;
if (!empty($CFG->usetags)) {
require_once $CFG->dirroot . '/tag/lib.php';
tag_cron();
}
}
示例2: cron_run
/**
* Execute cron tasks
*/
function cron_run()
{
global $DB, $CFG, $OUTPUT;
if (CLI_MAINTENANCE) {
echo "CLI maintenance mode active, cron execution suspended.\n";
exit(1);
}
if (moodle_needs_upgrading()) {
echo "Moodle upgrade pending, cron execution suspended.\n";
exit(1);
}
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/gradelib.php';
if (!empty($CFG->showcronsql)) {
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
set_debugging(DEBUG_DEVELOPER, true);
}
set_time_limit(0);
$starttime = microtime();
// Increase memory limit
raise_memory_limit(MEMORY_EXTRA);
// Emulate normal session - we use admin accoutn by default
cron_setup_user();
// Start output log
$timenow = time();
mtrace("Server Time: " . date('r', $timenow) . "\n\n");
// Run cleanup core cron jobs, but not every time since they aren't too important.
// These don't have a timer to reduce load, so we'll use a random number
// to randomly choose the percentage of times we should run these jobs.
$random100 = rand(0, 100);
if ($random100 < 20) {
// Approximately 20% of the time.
mtrace("Running clean-up tasks...");
cron_trace_time_and_memory();
// Delete users who haven't confirmed within required period
if (!empty($CFG->deleteunconfirmed)) {
$cuttime = $timenow - $CFG->deleteunconfirmed * 3600;
$rs = $DB->get_recordset_sql("SELECT *\n FROM {user}\n WHERE confirmed = 0 AND firstaccess > 0\n AND firstaccess < ?", array($cuttime));
foreach ($rs as $user) {
delete_user($user);
// we MUST delete user properly first
$DB->delete_records('user', array('id' => $user->id));
// this is a bloody hack, but it might work
mtrace(" Deleted unconfirmed user for " . fullname($user, true) . " ({$user->id})");
}
$rs->close();
}
// Delete users who haven't completed profile within required period
if (!empty($CFG->deleteincompleteusers)) {
$cuttime = $timenow - $CFG->deleteincompleteusers * 3600;
$rs = $DB->get_recordset_sql("SELECT *\n FROM {user}\n WHERE confirmed = 1 AND lastaccess > 0\n AND lastaccess < ? AND deleted = 0\n AND (lastname = '' OR firstname = '' OR email = '')", array($cuttime));
foreach ($rs as $user) {
if (isguestuser($user) or is_siteadmin($user)) {
continue;
}
delete_user($user);
mtrace(" Deleted not fully setup user {$user->username} ({$user->id})");
}
$rs->close();
}
// Delete old logs to save space (this might need a timer to slow it down...)
if (!empty($CFG->loglifetime)) {
// value in days
$loglifetime = $timenow - $CFG->loglifetime * 3600 * 24;
$DB->delete_records_select("log", "time < ?", array($loglifetime));
mtrace(" Deleted old log records");
}
// Delete old backup_controllers and logs.
$loglifetime = get_config('backup', 'loglifetime');
if (!empty($loglifetime)) {
// Value in days.
$loglifetime = $timenow - $loglifetime * 3600 * 24;
// Delete child records from backup_logs.
$DB->execute("DELETE FROM {backup_logs}\n WHERE EXISTS (\n SELECT 'x'\n FROM {backup_controllers} bc\n WHERE bc.backupid = {backup_logs}.backupid\n AND bc.timecreated < ?)", array($loglifetime));
// Delete records from backup_controllers.
$DB->execute("DELETE FROM {backup_controllers}\n WHERE timecreated < ?", array($loglifetime));
mtrace(" Deleted old backup records");
}
// Delete old cached texts
if (!empty($CFG->cachetext)) {
// Defined in config.php
$cachelifetime = time() - $CFG->cachetext - 60;
// Add an extra minute to allow for really heavy sites
$DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
mtrace(" Deleted old cache_text records");
}
if (!empty($CFG->usetags)) {
require_once $CFG->dirroot . '/tag/lib.php';
tag_cron();
mtrace(' Executed tag cron');
}
// Context maintenance stuff
context_helper::cleanup_instances();
mtrace(' Cleaned up context instances');
context_helper::build_all_paths(false);
//.........这里部分代码省略.........
示例3: cron_run
//.........这里部分代码省略.........
if (!empty($CFG->cachetext)) {
// Defined in config.php
$cachelifetime = time() - $CFG->cachetext - 60;
// Add an extra minute to allow for really heavy sites
if ($DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime))) {
mtrace("Deleted old cache_text records");
}
}
flush();
if (!empty($CFG->notifyloginfailures)) {
notify_login_failures();
mtrace('Notified login failured');
}
flush();
//
// generate new password emails for users
//
mtrace('checking for create_password');
if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
mtrace('creating passwords for new users');
$newusers = $DB->get_records_sql("SELECT u.id as id, u.email, u.firstname,\n u.lastname, u.username,\n p.id as prefid\n FROM {user} u\n JOIN {user_preferences} p ON u.id=p.userid\n WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
foreach ($newusers as $newuserid => $newuser) {
// email user
if (setnew_password_and_mail($newuser)) {
// remove user pref
$DB->delete_records('user_preferences', array('id' => $newuser->prefid));
} else {
trigger_error("Could not create and mail new user password!");
}
}
}
if (!empty($CFG->usetags)) {
require_once $CFG->dirroot . '/tag/lib.php';
tag_cron();
mtrace('Executed tag cron');
}
// Accesslib stuff
cleanup_contexts();
mtrace('Cleaned up contexts');
gc_cache_flags();
mtrace('Cleaned cache flags');
// If you suspect that the context paths are somehow corrupt
// replace the line below with: build_context_path(true);
build_context_path();
mtrace('Built context paths');
if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
$notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
$DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime' => $notificationdeletetime));
mtrace('Cleaned up read notifications');
}
mtrace("Finished clean-up tasks...");
}
// End of occasional clean-up tasks
// Run automated backups if required.
require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
require_once $CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php';
backup_cron_automated_helper::run_automated_backup();
/// Run the auth cron, if any
/// before enrolments because it might add users that will be needed in enrol plugins
$auths = get_enabled_auth_plugins();
mtrace("Running auth crons if required...");
foreach ($auths as $auth) {
$authplugin = get_auth_plugin($auth);
if (method_exists($authplugin, 'cron')) {
mtrace("Running cron for auth/{$auth}...");
$authplugin->cron();