Commit 30c93b88 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add param to interaction_forum_new_post to send forum posts with no delay (for testing)

parent 9a3ed6e0
......@@ -313,12 +313,23 @@ class PluginInteractionForum extends PluginInteraction {
return $forums;
}
/**
* cronjob for new forum posts
*/
public static function interaction_forum_new_post() {
$currenttime = time();
$minpostdelay = $currenttime - 30 * 60;
/**
* Process new forum posts.
*
* @param array $postnow An array of post ids to be sent immediately. If null, send all posts older than 30 mins.
*/
public static function interaction_forum_new_post($postnow=null) {
if (is_array($postnow) && !empty($postnow)) {
$values = array();
$postswhere = 'id IN (' . join(',', $postnow) . ')';
}
else {
$currenttime = time();
$minpostdelay = $currenttime - 30 * 60;
$values = array(db_format_timestamp($minpostdelay));
$postswhere = 'ctime < ?';
}
$posts = get_records_sql_array(
'SELECT s.subscriber, s.type, s.key, p.id
FROM (
......@@ -329,18 +340,21 @@ class PluginInteractionForum extends PluginInteraction {
INNER JOIN {interaction_forum_topic} t ON t.forum = sf.forum
) s
INNER JOIN {interaction_forum_topic} t ON (t.deleted != 1 AND t.id = s.topic)
INNER JOIN {interaction_forum_post} p ON (p.sent != 1 AND p.ctime < ? AND p.deleted != 1 AND p.topic = t.id)
INNER JOIN {interaction_forum_post} p ON (
p.sent != 1 AND p.deleted != 1 AND p.topic = t.id
AND p.' . $postswhere . '
)
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = 0)
INNER JOIN {group_member} gm ON (gm.member = s.subscriber AND gm.group = f.group)
ORDER BY type, p.id',
array(db_format_timestamp($minpostdelay))
$values
);
// query gets a new object for every subscription
// this combines all the objects for the same post together with an array for the subscribers
if ($posts) {
set_field_select('interaction_forum_post', 'sent', 1,
'ctime < ? AND deleted = 0 AND sent = 0', array(db_format_timestamp($minpostdelay)));
'deleted = 0 AND sent = 0 AND ' . $postswhere, $values);
$count = count($posts);
for ($i = 0; $i < $count; $i++) {
$posts[$i]->users = array($posts[$i]->subscriber);
......@@ -363,7 +377,8 @@ class PluginInteractionForum extends PluginInteraction {
'subscriptions' => $post->subscriptions,
),
'interaction',
'forum'
'forum',
(bool) $postnow
);
}
}
......
......@@ -33,9 +33,9 @@ defined('INTERNAL') || die();
* @param string $activitytype type of activity
* @param mixed $data data
*/
function activity_occurred($activitytype, $data, $plugintype=null, $pluginname=null) {
function activity_occurred($activitytype, $data, $plugintype=null, $pluginname=null, $overridedelay=false) {
$at = activity_locate_typerecord($activitytype, $plugintype, $pluginname);
if (!empty($at->delay)) {
if (!empty($at->delay) && !$overridedelay) {
$delayed = new StdClass;
$delayed->type = $at->id;
$delayed->data = serialize($data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment