Skip to content

Commit

Permalink
Update upgrade.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ralferlebach committed Sep 27, 2024
1 parent 7c7cf73 commit 652bae5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @return bool
*/
function xmldb_local_catquiz_upgrade($oldversion) {
global $DB;
global $DB, $CFG;

$dbman = $DB->get_manager();

Expand Down Expand Up @@ -952,21 +952,21 @@ function xmldb_local_catquiz_upgrade($oldversion) {

if ($oldversion < 2024092700) {

if ($DB->get_dbtype() === 'mysqli') {
if ($DB->get_dbfamily() === 'mysql') {

$sql = <<<ENDSQL
UPDATE {local_catquiz_tests}
SET json = REGEXP_REPLACE(json,
'"(feedbackeditor_[^"]+)":\{"text":"(([^"\\\\]*(\\\\.[^"\\\\]*)*))"(,(?:"format":"[0-9]+","itemid":"[0-9]+")?)?\}',
'"\\1":"\\2","\\1trust":false,"\\1format":"1"')
:regexp,
:replace)
ENDSQL;
} else if ($DB->get_dbtype() === 'pgsql') {
} else if ($DB->get_dbfamily() === 'postgres') {

$sql = <<<ENDSQL
UPDATE {local_catquiz_tests}
SET json = REGEXP_REPLACE(json,
'"(feedbackeditor_[^"]+)":\{"text":"(([^"\\\\]*(\\\\.[^"\\\\]*)*))"(,(?:"format":"[0-9]+","itemid":"[0-9]+")?)?\}',
'"\\1":"\\2","\\1trust":false,"\\1format":"1"','g')
:regexp,
:replace,'g')
ENDSQL;
} else {
require_once($CFG->libdir . '/moodlelib.php');
Expand All @@ -976,7 +976,11 @@ function xmldb_local_catquiz_upgrade($oldversion) {
echo $OUTPUT->notification($errormessage, 'error');
}

$DB->execute($sql);
$DB->execute($sql,
['regexp' =>
'\'"(feedbackeditor_[^"]+)":\{"text":"(([^"\\\\]*(\\\\.[^"\\\\]*)*))"(,(?:"format":"[0-9]+","itemid":"[0-9]+")?)?\}\'',
'replace' => '\'"\\1":"\\2","\\1trust":false,"\\1format":"1"\'',
]);

// Catquiz savepoint reached.
upgrade_plugin_savepoint(true, 2024092700, 'local', 'catquiz');
Expand Down

0 comments on commit 652bae5

Please sign in to comment.