Skip to content

Commit c0d6b21

Browse files
committed
Make index for code column not unique (#674)
1 parent 5b45c87 commit c0d6b21

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

db/install.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</KEYS>
5858
<INDEXES>
5959
<INDEX NAME="userid-customcertid" UNIQUE="false" FIELDS="userid, customcertid"/>
60-
<INDEX NAME="code" UNIQUE="true" FIELDS="code"/>
60+
<INDEX NAME="code" UNIQUE="false" FIELDS="code"/>
6161
</INDEXES>
6262
</TABLE>
6363
<TABLE NAME="customcert_pages" COMMENT="Stores each page of a custom cert">

db/upgrade.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,22 @@ function xmldb_customcert_upgrade($oldversion) {
298298
upgrade_mod_savepoint(true, 2024042205, 'customcert');
299299
}
300300

301-
// Define the new unique index for the 'code' column.
302-
if ($oldversion < 2024042209) {
301+
if ($oldversion < 2024042210) {
303302
$table = new xmldb_table('customcert_issues');
304303
$index = new xmldb_index('code', XMLDB_INDEX_UNIQUE, ['code']);
305304

306-
// Check if an index exists before adding.
305+
if ($dbman->index_exists($table, $index)) {
306+
$dbman->drop_index($table, $index);
307+
}
308+
309+
$index = new xmldb_index('code', XMLDB_INDEX_NOTUNIQUE, ['code']);
310+
307311
if (!$dbman->index_exists($table, $index)) {
308312
$dbman->add_index($table, $index);
309313
}
310314

311315
// Update the plugin version in the database.
312-
upgrade_plugin_savepoint(true, 2024042209, 'mod', 'customcert');
316+
upgrade_plugin_savepoint(true, 2024042210, 'mod', 'customcert');
313317
}
314318

315319
return true;

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
2626

27-
$plugin->version = 2024042209; // The current module version (Date: YYYYMMDDXX).
27+
$plugin->version = 2024042210; // The current module version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2024042200; // Requires this Moodle version (4.4).
2929
$plugin->cron = 0; // Period for cron to check this module (secs).
3030
$plugin->component = 'mod_customcert';

0 commit comments

Comments
 (0)