本文整理汇总了PHP中forum_mark_old_posts_as_mailed函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_mark_old_posts_as_mailed函数的具体用法?PHP forum_mark_old_posts_as_mailed怎么用?PHP forum_mark_old_posts_as_mailed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_mark_old_posts_as_mailed函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum_cron
/**
* Function to be run periodically according to the scheduled task.
*
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers as well as other maintance tasks.
*
* NOTE: Since 2.7.2 this function is run by scheduled task rather
* than standard cron.
*
* @todo MDL-44734 The function will be split up into seperate tasks.
*/
function forum_cron()
{
global $CFG, $USER, $DB, $PAGE;
$site = get_site();
// The main renderers.
$htmlout = $PAGE->get_renderer('mod_forum', 'email', 'htmlemail');
$textout = $PAGE->get_renderer('mod_forum', 'email', 'textemail');
$htmldigestfullout = $PAGE->get_renderer('mod_forum', 'emaildigestfull', 'htmlemail');
$textdigestfullout = $PAGE->get_renderer('mod_forum', 'emaildigestfull', 'textemail');
$htmldigestbasicout = $PAGE->get_renderer('mod_forum', 'emaildigestbasic', 'htmlemail');
$textdigestbasicout = $PAGE->get_renderer('mod_forum', 'emaildigestbasic', 'textemail');
// All users that are subscribed to any post that needs sending,
// please increase $CFG->extramemorylimit on large sites that
// send notifications to a large number of users.
$users = array();
$userscount = 0;
// Cached user counter - count($users) in PHP is horribly slow!!!
// Status arrays.
$mailcount = array();
$errorcount = array();
// caches
$discussions = array();
$forums = array();
$courses = array();
$coursemodules = array();
$subscribedusers = array();
$messageinboundhandlers = array();
// Posts older than 2 days will not be mailed. This is to avoid the problem where
// cron has not been running for a long time, and then suddenly people are flooded
// with mail from the past few weeks or months
$timenow = time();
$endtime = $timenow - $CFG->maxeditingtime;
$starttime = $endtime - 48 * 3600;
// Two days earlier
// Get the list of forum subscriptions for per-user per-forum maildigest settings.
$digestsset = $DB->get_recordset('forum_digests', null, '', 'id, userid, forum, maildigest');
$digests = array();
foreach ($digestsset as $thisrow) {
if (!isset($digests[$thisrow->forum])) {
$digests[$thisrow->forum] = array();
}
$digests[$thisrow->forum][$thisrow->userid] = $thisrow->maildigest;
}
$digestsset->close();
// Create the generic messageinboundgenerator.
$messageinboundgenerator = new \core\message\inbound\address_manager();
$messageinboundgenerator->set_handler('\\mod_forum\\message\\inbound\\reply_handler');
if ($posts = forum_get_unmailed_posts($starttime, $endtime, $timenow)) {
// Mark them all now as being mailed. It's unlikely but possible there
// might be an error later so that a post is NOT actually mailed out,
// but since mail isn't crucial, we can accept this risk. Doing it now
// prevents the risk of duplicated mails, which is a worse problem.
if (!forum_mark_old_posts_as_mailed($endtime)) {
mtrace('Errors occurred while trying to mark some posts as being mailed.');
return false;
// Don't continue trying to mail them, in case we are in a cron loop
}
// checking post validity, and adding users to loop through later
foreach ($posts as $pid => $post) {
$discussionid = $post->discussion;
if (!isset($discussions[$discussionid])) {
if ($discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
$discussions[$discussionid] = $discussion;
\mod_forum\subscriptions::fill_subscription_cache($discussion->forum);
\mod_forum\subscriptions::fill_discussion_subscription_cache($discussion->forum);
} else {
mtrace('Could not find discussion ' . $discussionid);
unset($posts[$pid]);
continue;
}
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
if ($forum = $DB->get_record('forum', array('id' => $forumid))) {
$forums[$forumid] = $forum;
} else {
mtrace('Could not find forum ' . $forumid);
unset($posts[$pid]);
continue;
}
}
$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
if ($course = $DB->get_record('course', array('id' => $courseid))) {
$courses[$courseid] = $course;
} else {
mtrace('Could not find course ' . $courseid);
unset($posts[$pid]);
continue;
//.........这里部分代码省略.........
示例2: forum_cron
/**
* Function to be run periodically according to the moodle cron
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers
*
* @global object
* @global object
* @global object
* @uses CONTEXT_MODULE
* @uses CONTEXT_COURSE
* @uses SITEID
* @uses FORMAT_PLAIN
* @return void
*/
function forum_cron() {
global $CFG, $USER, $DB;
$site = get_site();
// All users that are subscribed to any post that needs sending,
// please increase $CFG->extramemorylimit on large sites that
// send notifications to a large number of users.
$users = array();
$userscount = 0; // Cached user counter - count($users) in PHP is horribly slow!!!
// status arrays
$mailcount = array();
$errorcount = array();
// caches
$discussions = array();
$forums = array();
$courses = array();
$coursemodules = array();
$subscribedusers = array();
// Posts older than 2 days will not be mailed. This is to avoid the problem where
// cron has not been running for a long time, and then suddenly people are flooded
// with mail from the past few weeks or months
$timenow = time();
$endtime = $timenow - $CFG->maxeditingtime;
$starttime = $endtime - 48 * 3600; // Two days earlier
if ($posts = forum_get_unmailed_posts($starttime, $endtime, $timenow)) {
// Mark them all now as being mailed. It's unlikely but possible there
// might be an error later so that a post is NOT actually mailed out,
// but since mail isn't crucial, we can accept this risk. Doing it now
// prevents the risk of duplicated mails, which is a worse problem.
if (!forum_mark_old_posts_as_mailed($endtime)) {
mtrace('Errors occurred while trying to mark some posts as being mailed.');
return false; // Don't continue trying to mail them, in case we are in a cron loop
}
// checking post validity, and adding users to loop through later
foreach ($posts as $pid => $post) {
$discussionid = $post->discussion;
if (!isset($discussions[$discussionid])) {
if ($discussion = $DB->get_record('forum_discussions', array('id'=> $post->discussion))) {
$discussions[$discussionid] = $discussion;
} else {
mtrace('Could not find discussion '.$discussionid);
unset($posts[$pid]);
continue;
}
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
if ($forum = $DB->get_record('forum', array('id' => $forumid))) {
$forums[$forumid] = $forum;
} else {
mtrace('Could not find forum '.$forumid);
unset($posts[$pid]);
continue;
}
}
$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
if ($course = $DB->get_record('course', array('id' => $courseid))) {
$courses[$courseid] = $course;
} else {
mtrace('Could not find course '.$courseid);
unset($posts[$pid]);
continue;
}
}
if (!isset($coursemodules[$forumid])) {
if ($cm = get_coursemodule_from_instance('forum', $forumid, $courseid)) {
$coursemodules[$forumid] = $cm;
} else {
mtrace('Could not find course module for forum '.$forumid);
unset($posts[$pid]);
continue;
}
}
// caching subscribed users of each forum
//.........这里部分代码省略.........
示例3: forum_cron
/**
* Function to be run periodically according to the moodle cron
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers
* @return void
*/
function forum_cron()
{
global $CFG, $USER;
$cronuser = clone $USER;
$site = get_site();
// all users that are subscribed to any post that needs sending
$users = array();
// status arrays
$mailcount = array();
$errorcount = array();
// caches
$discussions = array();
$forums = array();
$courses = array();
$coursemodules = array();
$subscribedusers = array();
// Posts older than 2 days will not be mailed. This is to avoid the problem where
// cron has not been running for a long time, and then suddenly people are flooded
// with mail from the past few weeks or months
$timenow = time();
$endtime = $timenow - $CFG->maxeditingtime;
$starttime = $endtime - 48 * 3600;
// Two days earlier
if ($posts = forum_get_unmailed_posts($starttime, $endtime, $timenow)) {
// Mark them all now as being mailed. It's unlikely but possible there
// might be an error later so that a post is NOT actually mailed out,
// but since mail isn't crucial, we can accept this risk. Doing it now
// prevents the risk of duplicated mails, which is a worse problem.
if (!forum_mark_old_posts_as_mailed($endtime)) {
mtrace('Errors occurred while trying to mark some posts as being mailed.');
return false;
// Don't continue trying to mail them, in case we are in a cron loop
}
// checking post validity, and adding users to loop through later
foreach ($posts as $pid => $post) {
$discussionid = $post->discussion;
if (!isset($discussions[$discussionid])) {
if ($discussion = get_record('forum_discussions', 'id', $post->discussion)) {
$discussions[$discussionid] = $discussion;
} else {
mtrace('Could not find discussion ' . $discussionid);
unset($posts[$pid]);
continue;
}
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
if ($forum = get_record('forum', 'id', $forumid)) {
$forums[$forumid] = $forum;
} else {
mtrace('Could not find forum ' . $forumid);
unset($posts[$pid]);
continue;
}
}
$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
if ($course = get_record('course', 'id', $courseid)) {
$courses[$courseid] = $course;
} else {
mtrace('Could not find course ' . $courseid);
unset($posts[$pid]);
continue;
}
}
if (!isset($coursemodules[$forumid])) {
if ($cm = get_coursemodule_from_instance('forum', $forumid, $courseid)) {
$coursemodules[$forumid] = $cm;
} else {
mtrace('Could not course module for forum ' . $forumid);
unset($posts[$pid]);
continue;
}
}
// caching subscribed users of each forum
if (!isset($subscribedusers[$forumid])) {
if ($subusers = forum_subscribed_users($courses[$courseid], $forums[$forumid], 0, false)) {
foreach ($subusers as $postuser) {
// do not try to mail users with stopped email
if ($postuser->emailstop) {
if (!empty($CFG->forum_logblocked)) {
add_to_log(SITEID, 'forum', 'mail blocked', '', '', 0, $postuser->id);
}
continue;
}
// this user is subscribed to this forum
$subscribedusers[$forumid][$postuser->id] = $postuser->id;
// this user is a user we have to process later
$users[$postuser->id] = $postuser;
}
unset($subusers);
// release memory
}
}
//.........这里部分代码省略.........