Merge branch 'MDL-63381_master_v3' of https://github.com/TomoTsuyuki/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 20 Apr 2021 21:06:42 +0000 (23:06 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 20 Apr 2021 21:56:56 +0000 (23:56 +0200)
1  2 
backup/moodle2/restore_stepslib.php
backup/upgrade.txt
version.php

@@@ -2058,7 -2058,9 +2058,9 @@@ class restore_ras_and_caps_structure_st
          if ($this->get_setting_value('role_assignments')) {
              $paths[] = new restore_path_element('assignment', '/roles/role_assignments/assignment');
          }
-         $paths[] = new restore_path_element('override', '/roles/role_overrides/override');
+         if ($this->get_setting_value('permissions')) {
+             $paths[] = new restore_path_element('override', '/roles/role_overrides/override');
+         }
  
          return $paths;
      }
@@@ -3428,81 -3430,6 +3430,81 @@@ class restore_course_logstores_structur
      }
  }
  
 +/**
 + * Structure step in charge of restoring the loglastaccess.xml file for the course logs.
 + *
 + * This restore step will rebuild the table for user_lastaccess table.
 + */
 +class restore_course_loglastaccess_structure_step extends restore_structure_step {
 +
 +    /**
 +     * Conditionally decide if this step should be executed.
 +     *
 +     * This function checks the following parameter:
 +     *
 +     *   1. the loglastaccess.xml file exists
 +     *
 +     * @return bool true is safe to execute, false otherwise
 +     */
 +    protected function execute_condition() {
 +        // Check it is included in the backup.
 +        $fullpath = $this->task->get_taskbasepath();
 +        $fullpath = rtrim($fullpath, '/') . '/' . $this->filename;
 +        if (!file_exists($fullpath)) {
 +            // Not found, can't restore loglastaccess.xml information.
 +            return false;
 +        }
 +
 +        return true;
 +    }
 +
 +    /**
 +     * Return the elements to be processed on restore of loglastaccess.
 +     *
 +     * @return restore_path_element[] array of elements to be processed on restore.
 +     */
 +    protected function define_structure() {
 +
 +        $paths = array();
 +        // To know if we are including userinfo.
 +        $userinfo = $this->get_setting_value('users');
 +
 +        if ($userinfo) {
 +            $paths[] = new restore_path_element('lastaccess', '/lastaccesses/lastaccess');
 +        }
 +        // Return the paths wrapped.
 +        return $paths;
 +    }
 +
 +    /**
 +     * Process the 'lastaccess' elements.
 +     *
 +     * @param array $data element data
 +     */
 +    protected function process_lastaccess($data) {
 +        global $DB;
 +
 +        $data = (object)$data;
 +
 +        $data->courseid = $this->get_courseid();
 +        if (!$data->userid = $this->get_mappingid('user', $data->userid)) {
 +            return; // Nothing to do, not able to find the user to set the lastaccess time.
 +        }
 +
 +        // Check if record does exist.
 +        $exists = $DB->get_record('user_lastaccess', array('courseid' => $data->courseid, 'userid' => $data->userid));
 +        if ($exists) {
 +            // If the time of last access of the restore is newer, then replace and update.
 +            if ($exists->timeaccess < $data->timeaccess) {
 +                $exists->timeaccess = $data->timeaccess;
 +                $DB->update_record('user_lastaccess', $exists);
 +            }
 +        } else {
 +            $DB->insert_record('user_lastaccess', $data);
 +        }
 +    }
 +}
 +
  /**
   * Structure step in charge of restoring the logstores.xml file for the activity logs.
   *
@@@ -4140,30 -4067,9 +4142,30 @@@ class restore_contentbankcontent_struct
          $exists = $DB->record_exists('contentbank_content', $params);
          if (!$exists) {
              $params['configdata'] = $data->configdata;
 +            $params['timemodified'] = time();
 +
 +            // Trying to map users. Users cannot always be mapped, e.g. when copying.
              $params['usercreated'] = $this->get_mappingid('user', $data->usercreated);
 +            if (!$params['usercreated']) {
 +                // Leave the content creator unchanged when we are restoring the same site.
 +                // Otherwise use current user id.
 +                if ($this->task->is_samesite()) {
 +                    $params['usercreated'] = $data->usercreated;
 +                } else {
 +                    $params['usercreated'] = $this->task->get_userid();
 +                }
 +            }
              $params['usermodified'] = $this->get_mappingid('user', $data->usermodified);
 -            $params['timemodified'] = time();
 +            if (!$params['usermodified']) {
 +                // Leave the content modifier unchanged when we are restoring the same site.
 +                // Otherwise use current user id.
 +                if ($this->task->is_samesite()) {
 +                    $params['usermodified'] = $data->usermodified;
 +                } else {
 +                    $params['usermodified'] = $this->task->get_userid();
 +                }
 +            }
 +
              $newitemid = $DB->insert_record('contentbank_content', $params);
              $this->set_mapping('contentbank_content', $oldid, $newitemid, true);
          }
diff --combined backup/upgrade.txt
@@@ -1,10 -1,14 +1,16 @@@
  This files describes API changes in /backup/*,
  information provided here is intended especially for developers.
  
 -=== 4.0 ===
 - * Local plugins can now hook into a backup and restore process of grade items by
 -   using define_grade_item_plugin_structure method (See MDL-69418).
 -
+ === 3.11 ===
++
+  * New setting called "Include override permissions" has been implemented. The default
+    settings is OFF for import, and ON for restore.
 +=== 3.10 ===
++
 + * Local plugins can now hook into a backup and restore process of grade items by
 +   using define_grade_item_plugin_structure method (See MDL-69418).
 +
  === 3.1 ===
  
  * New close() method added to loggers so they can close any open resource. Previously
diff --combined version.php
@@@ -29,9 -29,9 +29,9 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2021052500.81;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2021052500.761;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2021052500.82;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
 -$release  = '4.0dev (Build: 20210406)'; // Human-friendly version name
 +$release  = '4.0dev (Build: 20210420)'; // Human-friendly version name
  $branch   = '400';                      // This version's branch.
  $maturity = MATURITY_ALPHA;             // This version's maturity level.