Merge branch 'MDL-69166-master-4' of git://github.com/rezaies/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 27 Oct 2020 04:47:50 +0000 (12:47 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 27 Oct 2020 04:47:50 +0000 (12:47 +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,58 -2862,94 +2863,135 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2021052500.30);
      }
  
 +    if ($oldversion < 2021052500.32) {
 +        // 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, 2021052500.32);
 +    }
 +
      if ($oldversion < 2021052500.33) {
 -        // Main savepoint reached.
 -        upgrade_main_savepoint(true, 2021052500.33);
 -    }
 -
 -    if ($oldversion < 2021052500.34) {
 -
 +        $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, 2021052500.33);
++        }
++    }
++
++    if ($oldversion < 2021052500.33) {
+         // 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, 2021052500.34);
 -    }
 -
 -    if ($oldversion < 2021052500.35) {
 -
+         // 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);
+         }
+         // 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, 2021052500.33);
 -        upgrade_main_savepoint(true, 2021052500.35);
++        upgrade_main_savepoint(true, 2021052500.36);
      }
  
      return true;
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2021052500.33;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2021052500.35;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2021052500.36;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
  $release  = '4.0dev (Build: 20201023)'; // Human-friendly version name