Skip to content

Commit

Permalink
Change upgrade query.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Oct 25, 2024
1 parent c188c93 commit 1e17983
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_verbalfeedback\repository\model\localized_string_type;

/**
* Upgrade code for the verbalfeedback activity plugin.
*
Expand Down Expand Up @@ -83,7 +85,6 @@ function xmldb_verbalfeedback_upgrade($oldversion) {
}

if ($oldversion < 2024101700) {
require_once($CFG->dirroot . '/mod/verbalfeedback/classes/repository/model/localized_string_type.php');
$table = new xmldb_table('verbalfeedback_local_string');
$field = new xmldb_field('typeid', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);

Expand All @@ -92,13 +93,11 @@ function xmldb_verbalfeedback_upgrade($oldversion) {
}

// Convert all strings to ids.
$offset = 0;
while ($records = $DB->get_records('verbalfeedback_local_string', null, 'id', 'id, type, typeid', $offset, 100)) {
foreach ($records as $record) {
$record->typeid = \mod_verbalfeedback\repository\model\localized_string_type::str2id($record->type);
$DB->update_record('verbalfeedback_local_string', $record);
}
$offset += 100;
foreach (localized_string_type::getStringTypes() as $type) {
$DB->execute(
'UPDATE {verbalfeedback_local_string} SET typeid = ? WHERE type = ?',
[localized_string_type::str2id($type), $type]
);
}
$dbman->drop_field($table, new xmldb_field('type'));
$table->add_index('subitemtype', XMLDB_INDEX_NOTUNIQUE, ['foreignkey', 'typeid']);
Expand Down

0 comments on commit 1e17983

Please sign in to comment.