/** * Creates the mail queue and runs query to obtain list of posts that should * be mailed. * @param bool $tracetimes True if it should call mtrace to display * performance information */ function __construct($tracetimes) { global $DB, $CFG; $this->time = time(); $this->forum = null; $this->discussion = null; $this->storedrecord = null; $this->postcount = 0; // Check if an earlier run got aborted. In that case we mark all // messages as mailed anyway because it's better to skip some than // to send out double-posts. if ($pending = get_config('forumng', $this->get_pending_flag_name())) { $this->mark_mailed($pending); } // Note that we are mid-run set_config($this->get_pending_flag_name(), $this->time, 'forumng'); list($wheresql, $whereparams) = $this->get_query_where($this->time); $querychunk = $this->get_query_from() . $wheresql; $this->rs = $DB->get_recordset_sql($sql = "\nSELECT\n " . mod_forumng_utils::select_mod_forumng_fields('f') . ",\n " . mod_forumng_utils::select_discussion_fields('fd') . ",\n " . mod_forumng_utils::select_post_fields('discussionpost') . ",\n " . mod_forumng_utils::select_post_fields('fp') . ",\n " . mod_forumng_utils::select_post_fields('reply') . ",\n " . mod_forumng_utils::select_course_module_fields('cm') . ",\n " . mod_forumng_utils::select_context_fields('x') . ",\n " . mod_forumng_utils::select_username_fields('u', true) . ",\n " . mod_forumng_utils::select_username_fields('eu') . ",\n " . mod_forumng_utils::select_username_fields('replyu') . ",\n " . mod_forumng_utils::select_username_fields('replyeu') . ",\n " . mod_forumng_utils::select_course_fields('c') . ",\n clonecm.id AS cloneid\n{$querychunk}\nORDER BY\n clonecm.course, f.id, fd.id, fp.id", $whereparams); if (!empty($CFG->forumng_cronultradebug)) { $easyread = mod_forumng_utils::debug_query_for_reading($sql, $whereparams); mtrace("\n\n" . $easyread . "\n\n"); } }