Skip to content

Commit

Permalink
Bug #8, Catch dml_exception in conditional_embedded_survey [iet:103…
Browse files Browse the repository at this point in the history
…14222]

* Plus, fix to function call in `survey-end/index` PHP [ci skip]
  • Loading branch information
nfreear committed Mar 8, 2018
1 parent f7ca637 commit fc6db1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions classes/local/conditional_embedded_survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class conditional_embedded_survey extends base {
const CONFIG_KEY = self::BASE_KEY . '_conditional_survey_activity';
const MOD_TYPE_NAME = 'assign'; // 'mod/assign'
const MOD_TYPE_ID = 1; // ID in 'mdl_modules' table.
const EMBED_LIKE = '%</iframe>%'; // MySQL 'LIKE'
// const EMBED_LIKE = '%</iframe>%'; // MySQL 'LIKE'
const EMBED_REGEXP = '(<\/iframe>|[?#!]-pre-survey-embed)'; // MySQL 'REGEXP'

protected $course_id; // 4,
protected $course_code; // 'FR',
Expand Down Expand Up @@ -60,11 +61,20 @@ protected function set_config( $course_code, $userid = null ) {
}

public function make_complete() {
$b_ok = false;
if ($this->is_valid_module() && $this->activity_has_embed()) {

$this->assign_grades();
$this->assign_submission();
return $this->course_module_complete();
try {
$this->assign_grades();
$this->assign_submission();
$b_ok = $this->course_module_complete();
} catch (\dml_write_exception $ex) {
self::debug([ __FUNCTION__, 'dml_write_exception', $ex->getMessage(), $ex->debuginfo ]);

if (! preg_match('/Duplicate entry .+/', $ex->debuginfo)) {
throw $ex;
}
}
return $b_ok;
}
return false;
}
Expand All @@ -91,8 +101,11 @@ protected function is_valid_module() {
protected function activity_has_embed() {
global $DB; // Moodle global.

$result = $DB->get_record_sql( 'SELECT * FROM {assign} WHERE ' . $DB->sql_like( 'intro', ':intro' ) . ' AND id = :id ',
[ 'intro' => self::EMBED_LIKE, 'id' => $this->activity_id ]);
$result = $DB->get_record_sql( 'SELECT * FROM {assign} WHERE intro REGEXP :intro_re AND id = :id ',
[ 'intro_re' => self::EMBED_REGEXP, 'id' => $this->activity_id ]);

// Was: $result = $DB->get_record_sql( 'SELECT * FROM {assign} WHERE ' . $DB->sql_like( 'intro', ':intro' ) . ' AND id = :id ',
// [ 'intro' => self::EMBED_LIKE, 'id' => $this->activity_id ]);

self::debug([ __METHOD__, $result ]);
return $result;
Expand Down
2 changes: 1 addition & 1 deletion survey-end/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function complete_conditional() {
<script id="survey-end-config" type="application/json">
<?php
echo json_encode([
'course_code' => Ou_Open_Id_Survey_End::getReturnCode(),
'course_code' => Ou_Open_Id_Survey_End::get_return_code(),
'cond_completed' => $conditional_completed,
'agreement_id' => $agreement_id,
'redirects' => $CFG->auth_ouopenid_redirects,
Expand Down

0 comments on commit fc6db1b

Please sign in to comment.