Merge branch 'MDL-69166-310-4' of git://github.com/rezaies/moodle into MOODLE_310_STABLE
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 27 Oct 2020 04:59:25 +0000 (12:59 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 27 Oct 2020 04:59:25 +0000 (12:59 +0800)
1  2 
lang/en/moodle.php
lib/db/access.php
lib/db/install.xml
lib/db/upgrade.php
version.php

Simple merge
@@@ -2577,25 -2577,21 +2577,41 @@@ $capabilities = array
          ]
      ],
  
-         )
 +    // Allow users to download course content.
 +    'moodle/course:downloadcoursecontent' => [
 +        'captype' => 'read',
 +        'contextlevel' => CONTEXT_COURSE,
 +        'archetypes' => array(
 +            'student' => CAP_ALLOW,
 +            'teacher' => CAP_ALLOW,
 +            'editingteacher' => CAP_ALLOW,
 +            'manager' => CAP_ALLOW
 +        )
 +    ],
 +
 +    // Allow users to configure download course content functionality within a course, if the feature is available.
 +    'moodle/course:configuredownloadcontent' => [
 +        'captype' => 'write',
 +        'contextlevel' => CONTEXT_COURSE,
 +        'archetypes' => array(
 +            'editingteacher' => CAP_ALLOW,
 +            'manager' => CAP_ALLOW
 -        'archetypes' => [
 -        ]
++        ),
++    ],
++
+     // Allow to manage payment accounts.
+     'moodle/payment:manageaccounts' => [
+         'captype' => 'write',
+         'riskbitmask' => RISK_PERSONAL | RISK_CONFIG | RISK_DATALOSS,
+         'contextlevel' => CONTEXT_COURSE,
 -        'archetypes' => [
 -        ]
++        'archetypes' => [],
+     ],
+     // Allow to view payments.
+     'moodle/payment:viewpayments' => [
+         'captype' => 'read',
+         'riskbitmask' => RISK_PERSONAL,
+         'contextlevel' => CONTEXT_COURSE,
++        'archetypes' => [],
      ],
  );
index 00697cb,5974516..87a8826
mode 100644,100755..100755
@@@ -2863,59 -2862,95 +2863,137 @@@ function xmldb_main_upgrade($oldversion
          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;
  }
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2020102300.02;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2020102700.03;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2020102700.04;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
  $release  = '3.10dev+ (Build: 20201023)';// Human-friendly version name