Skip to content

Commit

Permalink
Completed updates for moodle 404
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed Mar 12, 2024
1 parent bb98d33 commit a705aa0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
6 changes: 3 additions & 3 deletions classes/manager/mail_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use context_course;
use context_module;
use core\context\course;
use core_php_time_limit;
use mod_moodleoverflow\anonymous;
use mod_moodleoverflow\output\moodleoverflow_email;
Expand Down Expand Up @@ -496,9 +497,8 @@ private static function send_post($userto, $post, array &$coursemodules, array &

// Preapare to actually send the post now. Build up the content.
$cleanname = str_replace('"', "'", strip_tags(format_string($moodleoverflow->name)));
$coursecontext = context_course::instance($course->id);
// TODO: deprecated, option array should not contain context objects.
$shortname = format_string($course->shortname, true, ['context' => $coursecontext]);
$formatter = \core\di::get(\core\formatting::class);
$shortname = $formatter->format_string($course->shortname, true, course::instance($course->id));

// Define a header to make mails easier to track.
$emailmessageid = generate_email_messageid('moodlemoodleoverflow' . $moodleoverflow->id);
Expand Down
6 changes: 4 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

// Require needed files.
use core\context\course;

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once($CFG->dirroot . '/course/lib.php');
Expand Down Expand Up @@ -214,8 +216,8 @@
$returnto = moodleoverflow_go_back_to($url);

// Prepare the message to be displayed.
// TODO: Deprecated, options should not contain a context object.
$shortname = format_string($course->shortname, true, ['context' => context_course::instance($course->id)]);
$formatter = \core\di::get(\core\formatting::class);
$shortname = $formatter->format_string($course->shortname, true, course::instance($course->id));
$notification = \core\output\notification::NOTIFY_SUCCESS;

// Redirect the user depending on the subscription state.
Expand Down
7 changes: 4 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\context\course;

defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__) . '/locallib.php');

Expand Down Expand Up @@ -883,9 +885,8 @@ function moodleoverflow_send_mails() {

// Preapare to actually send the post now. Build up the content.
$cleanname = str_replace('"', "'", strip_tags(format_string($moodleoverflow->name)));
$coursecontext = context_course::instance($course->id);
// TODO: Deprecated, options should not contain a context object.
$shortname = format_string($course->shortname, true, ['context' => $coursecontext]);
$formatter = \core\di::get(\core\formatting::class);
$shortname = $formatter->format_string($course->shortname, true, course::instance($course->id));

// Define a header to make mails easier to track.
$emailmessageid = generate_email_messageid('moodlemoodleoverflow' . $moodleoverflow->id);
Expand Down
22 changes: 5 additions & 17 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @copyright 2017 Kennet Winter <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_moodleoverflow\anonymous;
use mod_moodleoverflow\capabilities;
use mod_moodleoverflow\event\post_deleted;
Expand Down Expand Up @@ -928,12 +927,7 @@ function moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discuss

// Retrieve all posts of the discussion.
$posts = moodleoverflow_get_all_discussion_posts($discussion->id, $istracked, $modulecontext);
/*$newpost = [];
foreach($posts as $posti) {
$newpost[] = $posti->message;
}
var_dump($newpost);
*/$usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussion->id);
$usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussion->id);

// Start with the parent post.
$post = $posts[$post->id];
Expand Down Expand Up @@ -1432,12 +1426,6 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co
}
$mustachedata->questioner = $post->userid == $discussion->userid ? 'questioner' : '';

// Set options for the post.
$options = new stdClass();
$options->para = false;
$options->trusted = false;
$options->context = $modulecontext;

$reviewdelay = get_config('moodleoverflow', 'reviewpossibleaftertime');
$mustachedata->reviewdelay = format_time($reviewdelay);
$mustachedata->needsreview = !$post->reviewed;
Expand All @@ -1446,8 +1434,8 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co
$mustachedata->withinreviewperiod = $reviewable;

// Prepare the post.
// TODO: Deprecated $courseiddonotuse deprecated course id, use context option instead.
$mustachedata->postcontent = format_text($post->message, $post->messageformat, $options, $course->id);
$formatter = \core\di::get(\core\formatting::class);
$mustachedata->postcontent = $formatter->format_text($post->message, $post->messageformat, context_module::instance($cm->id));

// Load the attachments.
$mustachedata->attachments = get_attachments($post, $cm);
Expand Down Expand Up @@ -1857,10 +1845,10 @@ function moodleoverflow_delete_post($post, $deletechildren, $cm, $moodleoverflow
$attachments = $fs->get_area_files($context->id, 'mod_moodleoverflow', 'attachment',
$post->id, "filename", true);
foreach ($attachments as $attachment) {
// Get file
// Get file.
$file = $fs->get_file($context->id, 'mod_moodleoverflow', 'attachment', $post->id,
$attachment->get_filepath(), $attachment->get_filename());
// Delete it if it exists
// Delete it if it exists.
if ($file) {
$file->delete();
}
Expand Down
7 changes: 5 additions & 2 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// TODO refactor this. For more readability, and to avoid security issues.

// Include config and locallib.
use mod_moodleoverflow\anonymous;
use mod_moodleoverflow\review;

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
Expand Down Expand Up @@ -490,7 +491,9 @@
empty($post->id) ? null : $post->id,
mod_moodleoverflow_post_form::attachment_options($moodleoverflow));

if ($draftitemid && $edit && \mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid) && $post->userid != $USER->id) {
if ($draftitemid && $edit && anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid)
&& $post->userid != $USER->id) {

$usercontext = context_user::instance($USER->id);
$anonymousstr = get_string('anonymous', 'moodleoverflow');
foreach (get_file_storage()->get_area_files($usercontext->id, 'user', 'draft', $draftitemid) as $file) {
Expand Down Expand Up @@ -634,7 +637,7 @@
if ($realpost->userid == $USER->id) {
$message .= get_string('postupdated', 'moodleoverflow');
} else {
if (\mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $realpost->userid)) {
if (anonymous::is_post_anonymous($discussion, $moodleoverflow, $realpost->userid)) {
$name = get_string('anonymous', 'moodleoverflow');
} else {
$realuser = $DB->get_record('user', ['id' => $realpost->userid]);
Expand Down
9 changes: 6 additions & 3 deletions tests/review_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,18 @@ private function create_post($options) {
private function check_mail_records($teacherpost, $studentpost, $review1, $review2, $mailed) {
global $DB;

$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING, 'reviewed' => $review1, 'timereviewed' => null],
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING,
'reviewed' => $review1, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id]));
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING, 'reviewed' => $review2, 'timereviewed' => null],
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING,
'reviewed' => $review2, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id]));

$this->run_send_mails();
$this->run_send_mails(); // Execute twice to ensure no duplicate mails.

$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_SUCCESS, 'reviewed' => $review1, 'timereviewed' => null],
$this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_SUCCESS,
'reviewed' => $review1, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id]));
$this->assert_matches_properties(['mailed' => $mailed, 'reviewed' => $review2, 'timereviewed' => null],
$DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id]));
Expand Down
2 changes: 2 additions & 0 deletions tests/subscriptions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ public function is_subscribable_provider() {
* @param array $options
*
* @dataProvider is_subscribable_provider
* @return void
*/
public function test_is_subscribable_logged_out($options): void {
$this->resetAfterTest(true);
Expand All @@ -1416,6 +1417,7 @@ public function test_is_subscribable_logged_out($options): void {
* @param array $options
*
* @dataProvider is_subscribable_provider
* @return void
*/
public function test_is_subscribable_is_guest($options): void {
global $DB;
Expand Down

0 comments on commit a705aa0

Please sign in to comment.