Skip to content

Commit

Permalink
MDL-47162 core_message: Cleanup of messaging course ids code
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmerrill authored and stronk7 committed Oct 27, 2016
1 parent cc350fd commit 0e8b516
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 57 deletions.
2 changes: 1 addition & 1 deletion enrol/paypal/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function message_paypal_error_to_admin($subject, $data) {
$message .= "$key => $value\n";
}

$eventdata = new \stdClass();
$eventdata = new \core\message\message();
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_paypal';
$eventdata->name = 'paypal_enrolment';
Expand Down
49 changes: 1 addition & 48 deletions enrol/paypal/ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}

if (! $context = context_course::instance($course->id, IGNORE_MISSING)) {
message_paypal_error_to_admin("Not a valid context id", $data);
\enrol_paypal\util::message_paypal_error_to_admin("Not a valid context id", $data);
die;
}

Expand Down Expand Up @@ -319,50 +319,3 @@
}

exit;


//--- HELPER FUNCTIONS --------------------------------------------------------------------------------------


function message_paypal_error_to_admin($subject, $data) {
echo $subject;
$admin = get_admin();
$site = get_site();

$message = "$site->fullname: Transaction failed.\n\n$subject\n\n";

foreach ($data as $key => $value) {
$message .= "$key => $value\n";
}

$eventdata = new \core\message\message();
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_paypal';
$eventdata->name = 'paypal_enrolment';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = "PAYPAL ERROR: ".$subject;
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
message_send($eventdata);
}

/**
* Silent exception handler.
*
* @param Exception $ex
* @return void - does not return. Terminates execution!
*/
function enrol_paypal_ipn_exception_handler($ex) {
$info = get_exception_info($ex);

$logerrmsg = "enrol_paypal IPN exception handler: ".$info->message;
if (debugging('', DEBUG_NORMAL)) {
$logerrmsg .= ' Debug: '.$info->debuginfo."\n".format_backtrace($info->backtrace, true);
}
error_log($logerrmsg);

exit(0);
}
2 changes: 1 addition & 1 deletion lib/classes/message/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function send_message($eventdata, \stdClass $savemessage, array $p
$eventdata->courseid = null;
}

debugging('eventdata as \stdClass is deprecated. Please use core\message\message instead.', DEBUG_DEVELOPER);
debugging('eventdata as \stdClass is deprecated. Please use \core\message\message instead.', DEBUG_DEVELOPER);
}

require_once($CFG->dirroot.'/message/lib.php'); // This is most probably already included from messagelib.php file.
Expand Down
2 changes: 1 addition & 1 deletion lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ information provided here is intended especially for developers.
* Webservice function mod_assign_get_submissions returns a new field 'gradingstatus' from each submission.
* The return signature for the antivirus::scan_file() function has changed.
The calling function will now handle removal of infected files from Moodle based on the new integer return value.
* The first parameter $eventdata of \core\manager::send_message() should be \core\message. usage of \stdClass is depecated.
* The first parameter $eventdata of \core\manager::send_message() should be \core\message. Use of \stdClass is depecated.
* message_sent::create_from_ids has an additional required parameter $courseid with a default value of SITEID.

=== 3.1 ===
Expand Down
2 changes: 2 additions & 0 deletions message/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ public function test_get_messages() {

$userfrom = core_user::get_noreply_user();
$userfrom->maildisplay = true;
$eventdata = new \core\message\message();
$eventdata->courseid = $course->id;
$eventdata->component = 'moodle';
$eventdata->name = 'badgecreatornotice';
$eventdata->userfrom = $userfrom;
Expand Down
1 change: 1 addition & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ public function test_cron_message_includes_courseid() {

$this->preventResetByRollback();
$sink = $this->redirectEvents();
$this->expectOutputRegex('/Done processing 1 assignment submissions/');

assign::cron();

Expand Down
1 change: 1 addition & 0 deletions mod/forum/tests/mail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public function test_cron_message_includes_courseid() {
// core\event\message_sent
// core\event\message_viewed.
$this->helper->eventsink = $this->redirectEvents();
$this->expectOutputRegex('/Processing user/');

forum_cron();

Expand Down
6 changes: 1 addition & 5 deletions mod/lesson/essay.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@
$a->lesson = format_string($lesson->name, true);

// Fetch message HTML and plain text formats
$b = new stdClass();
$b->essay = format_string($pages[$attempt->pageid]->title, true);
$b->lesson = $lesson->properties()->name;
$b->course = $course->idnumber ? $course->idnumber : $course->fullname;
$message = get_string('essayemailmessage2', 'lesson', $a);
$plaintext = format_text_email($message, FORMAT_HTML);

Expand All @@ -279,7 +275,7 @@
$eventdata->fullmessage = $plaintext;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = $message;
$eventdata->smallmessage = $smallmessage;
$eventdata->smallmessage = '';
$eventdata->contexturl = $contexturl;

// Required for messaging framework
Expand Down
1 change: 0 additions & 1 deletion mod/lesson/lang/en/lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
$string['eolstudentoutoftimenoanswers'] = 'You did not answer any questions. You have received a 0 for this lesson.';
$string['essay'] = 'Essay';
$string['essayemailmessage2'] = '<p>Essay prompt: {$a->question}</p><p>Your response: <em>{$a->response}</em></p><p>Grader\'s comments: <em>{$a->comment}</em></p><p>You have received {$a->earned} out of {$a->outof} for this essay question.</p><p>Your grade for the {$a->lesson} lesson has been changed to {$a->newgrade}&#37;.</p>';
$string['essayemailmessage3'] = 'Your submission to {$a->lesson} essay {$a->essay} in {$a->course} has been graded.';
$string['essayemailsubject'] = 'Grade available for lesson question';
$string['essayresponses'] = 'Essay responses';
$string['essays'] = 'Essays';
Expand Down

0 comments on commit 0e8b516

Please sign in to comment.