upgrade_main_savepoint(true, 2020102100.02);
}
- if ($oldversion < 2020102700.01) {
+ if ($oldversion < 2020102300.01) {
+ // Define field downloadcontent to be added to course.
+ $table = new xmldb_table('course');
+ $field = new xmldb_field('downloadcontent', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'visibleold');
+
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2020102300.01);
+ }
+
+ if ($oldversion < 2020102300.02) {
+ $table = new xmldb_table('badge_backpack');
+
+ // There is no key_exists, so test the equivalent index.
+ $oldindex = new xmldb_index('backpackcredentials', XMLDB_KEY_UNIQUE, ['userid', 'externalbackpackid']);
+ if (!$dbman->index_exists($table, $oldindex)) {
+ // All external backpack providers/hosts are now exclusively stored in badge_external_backpack.
+ // All credentials are stored in badge_backpack and are unique per user, backpack.
+ $uniquekey = new xmldb_key('backpackcredentials', XMLDB_KEY_UNIQUE, ['userid', 'externalbackpackid']);
+ $dbman->add_key($table, $uniquekey);
+ }
+
+ // Drop the password field as this is moved to badge_backpack.
+ $table = new xmldb_table('badge_external_backpack');
+ $field = new xmldb_field('password', XMLDB_TYPE_CHAR, '50');
+ if ($dbman->field_exists($table, $field)) {
+ // If there is a current backpack set then copy it across to the new structure.
+ if ($CFG->badges_defaultissuercontact) {
+ // Get the currently used site backpacks.
+ $records = $DB->get_records_select('badge_external_backpack', "password IS NOT NULL AND password != ''");
+ $backpack = [
+ 'userid' => '0',
+ 'email' => $CFG->badges_defaultissuercontact,
+ 'backpackuid' => -1
+ ];
+
+ // Create records corresponding to the site backpacks.
+ foreach ($records as $record) {
+ $backpack['password'] = $record->password;
+ $backpack['externalbackpackid'] = $record->id;
+ $DB->insert_record('badge_backpack', (object) $backpack);
+ }
+ }
+
+ $dbman->drop_field($table, $field);
+ }
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2020102300.02);
+ }
+
++ if ($oldversion < 2020102700.04) {
+
+ // Define table payment_accounts to be created.
+ $table = new xmldb_table('payment_accounts');
+
+ // Adding fields to table payment_accounts.
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null);
+ $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
+ $table->add_field('archived', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
+ $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
+ $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
+
+ // Adding keys to table payment_accounts.
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
+
+ // Conditionally launch create table for payment_accounts.
+ if (!$dbman->table_exists($table)) {
+ $dbman->create_table($table);
+ }
+
- // Main savepoint reached.
- upgrade_main_savepoint(true, 2020102700.01);
- }
-
- if ($oldversion < 2020102700.02) {
-
+ // Define table payment_gateways to be created.
+ $table = new xmldb_table('payment_gateways');
+
+ // Adding fields to table payment_gateways.
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('accountid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('gateway', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
+ $table->add_field('config', XMLDB_TYPE_TEXT, null, null, null, null, null);
+ $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+
+ // Adding keys to table payment_gateways.
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
+ $table->add_key('accountid', XMLDB_KEY_FOREIGN, ['accountid'], 'payment_accounts', ['id']);
+
+ // Conditionally launch create table for payment_gateways.
+ if (!$dbman->table_exists($table)) {
+ $dbman->create_table($table);
+ }
+
- // Main savepoint reached.
- upgrade_main_savepoint(true, 2020102700.02);
- }
-
- if ($oldversion < 2020102700.03) {
-
+ // Define table payments to be created.
+ $table = new xmldb_table('payments');
+
+ // Adding fields to table payments.
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('paymentarea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('amount', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('currency', XMLDB_TYPE_CHAR, '3', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('accountid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('gateway', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
+ $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
+
+ // Adding keys to table payments.
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
+ $table->add_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
+ $table->add_key('accountid', XMLDB_KEY_FOREIGN, ['accountid'], 'payment_accounts', ['id']);
+
+ // Adding indexes to table payments.
+ $table->add_index('gateway', XMLDB_INDEX_NOTUNIQUE, ['gateway']);
+ $table->add_index('component-paymentarea-itemid', XMLDB_INDEX_NOTUNIQUE, ['component', 'paymentarea', 'itemid']);
+
+ // Conditionally launch create table for payments.
+ if (!$dbman->table_exists($table)) {
+ $dbman->create_table($table);
+ }
+
+ // Main savepoint reached.
- upgrade_main_savepoint(true, 2020102700.03);
++ upgrade_main_savepoint(true, 2020102700.04);
+ }
+
return true;
}