Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/backup/moodle2/backup_stepslib.php

    r136 r1331  
    9292/**
    9393 * Abstract structure step, parent of all the activity structure steps. Used to wrap the
    94  * activity structure definition within the main <activity ...> tag. Also provides
    95  * subplugin support for activities (that must be properly declared)
     94 * activity structure definition within the main <activity ...> tag.
    9695 */
    9796abstract class backup_activity_structure_step extends backup_structure_step {
    98 
    99     /**
    100      * Add subplugin structure to any element in the activity backup tree
    101      *
    102      * @param string $subplugintype type of subplugin as defined in activity db/subplugins.php
    103      * @param backup_nested_element $element element in the activity backup tree that
    104      *                                       we are going to add subplugin information to
    105      * @param bool $multiple to define if multiple subplugins can produce information
    106      *                       for each instance of $element (true) or no (false)
    107      * @return void
    108      */
    109     protected function add_subplugin_structure($subplugintype, $element, $multiple) {
    110 
    111         global $CFG;
    112 
    113         // Check the requested subplugintype is a valid one
    114         $subpluginsfile = $CFG->dirroot . '/mod/' . $this->task->get_modulename() . '/db/subplugins.php';
    115         if (!file_exists($subpluginsfile)) {
    116              throw new backup_step_exception('activity_missing_subplugins_php_file', $this->task->get_modulename());
    117         }
    118         include($subpluginsfile);
    119         if (!array_key_exists($subplugintype, $subplugins)) {
    120              throw new backup_step_exception('incorrect_subplugin_type', $subplugintype);
    121         }
    122 
    123         // Arrived here, subplugin is correct, let's create the optigroup
    124         $optigroupname = $subplugintype . '_' . $element->get_name() . '_subplugin';
    125         $optigroup = new backup_optigroup($optigroupname, null, $multiple);
    126         $element->add_child($optigroup); // Add optigroup to stay connected since beginning
    127 
    128         // Get all the optigroup_elements, looking across all the subplugin dirs
    129         $subpluginsdirs = core_component::get_plugin_list($subplugintype);
    130         foreach ($subpluginsdirs as $name => $subpluginsdir) {
    131             $classname = 'backup_' . $subplugintype . '_' . $name . '_subplugin';
    132             $backupfile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php';
    133             if (file_exists($backupfile)) {
    134                 require_once($backupfile);
    135                 $backupsubplugin = new $classname($subplugintype, $name, $optigroup, $this);
    136                 // Add subplugin returned structure to optigroup
    137                 $backupsubplugin->define_subplugin_structure($element->get_name());
    138             }
    139         }
    140     }
    141 
    142     /**
    143      * As far as activity backup steps are implementing backup_subplugin stuff, they need to
    144      * have the parent task available for wrapping purposes (get course/context....)
    145      *
    146      * @return backup_activity_task
    147      */
    148     public function get_task() {
    149         return $this->task;
    150     }
    15197
    15298    /**
     
    504450class backup_enrolments_structure_step extends backup_structure_step {
    505451
     452    /**
     453     * Skip enrolments on the front page.
     454     * @return bool
     455     */
     456    protected function execute_condition() {
     457        return ($this->get_courseid() != SITEID);
     458    }
     459
    506460    protected function define_structure() {
    507461
     
    517471        $enrol = new backup_nested_element('enrol', array('id'), array(
    518472            'enrol', 'status', 'name', 'enrolperiod', 'enrolstartdate',
    519             'enrolenddate', 'expirynotify', 'expirytreshold', 'notifyall',
     473            'enrolenddate', 'expirynotify', 'expirythreshold', 'notifyall',
    520474            'password', 'cost', 'currency', 'roleid',
    521475            'customint1', 'customint2', 'customint3', 'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
     
    818772        $criteria = new backup_nested_element('criteria');
    819773        $criterion = new backup_nested_element('criterion', array('id'), array('badgeid',
    820                 'criteriatype', 'method'));
     774                'criteriatype', 'method', 'description', 'descriptionformat'));
    821775
    822776        $parameters = new backup_nested_element('parameters');
     
    923877     */
    924878    protected function execute_condition() {
    925         return backup_plan_dbops::require_gradebook_backup($this->get_courseid(), $this->get_backupid());
    926     }
    927 
    928     protected function define_structure() {
     879        $courseid = $this->get_courseid();
     880        if ($courseid == SITEID) {
     881            return false;
     882        }
     883
     884        return backup_plan_dbops::require_gradebook_backup($courseid, $this->get_backupid());
     885    }
     886
     887    protected function define_structure() {
     888        global $CFG, $DB;
    929889
    930890        // are we including user info?
     
    987947        $grade_settings->add_child($grade_setting);
    988948
     949        // Add attribute with gradebook calculation freeze date if needed.
     950        $gradebookcalculationfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->get_courseid());
     951        if ($gradebookcalculationfreeze) {
     952            $gradebook->add_attributes(array('calculations_freeze'));
     953            $gradebook->get_attribute('calculations_freeze')->set_value($gradebookcalculationfreeze);
     954        }
     955
    989956        // Define sources
    990957
     
    1011978        $letter->set_source_table('grade_letters', array('contextid' => backup::VAR_CONTEXTID));
    1012979
    1013         $grade_setting->set_source_table('grade_settings', array('courseid' => backup::VAR_COURSEID));
     980        // Set the grade settings source, forcing the inclusion of minmaxtouse if not present.
     981        $settings = array();
     982        $rs = $DB->get_recordset('grade_settings', array('courseid' => $this->get_courseid()));
     983        foreach ($rs as $record) {
     984            $settings[$record->name] = $record;
     985        }
     986        $rs->close();
     987        if (!isset($settings['minmaxtouse'])) {
     988            $settings['minmaxtouse'] = (object) array('name' => 'minmaxtouse', 'value' => $CFG->grade_minmaxtouse);
     989        }
     990        $grade_setting->set_source_array($settings);
     991
    1014992
    1015993        // Annotations (both as final as far as they are going to be exported in next steps)
     
    10371015     */
    10381016    protected function execute_condition() {
    1039         return backup_plan_dbops::require_gradebook_backup($this->get_courseid(), $this->get_backupid());
     1017        $courseid = $this->get_courseid();
     1018        if ($courseid == SITEID) {
     1019            return false;
     1020        }
     1021
     1022        return backup_plan_dbops::require_gradebook_backup($courseid, $this->get_backupid());
    10401023    }
    10411024
     
    10901073class backup_userscompletion_structure_step extends backup_structure_step {
    10911074
     1075    /**
     1076     * Skip completion on the front page.
     1077     * @return bool
     1078     */
     1079    protected function execute_condition() {
     1080        return ($this->get_courseid() != SITEID);
     1081    }
     1082
    10921083    protected function define_structure() {
    10931084
     
    11241115    protected function define_structure() {
    11251116
    1126         // To know if we are including users
    1127         $users = $this->get_setting_value('users');
     1117        // To know if we are including users.
     1118        $userinfo = $this->get_setting_value('users');
     1119        // To know if we are including groups and groupings.
     1120        $groupinfo = $this->get_setting_value('groups');
    11281121
    11291122        // Define each element separated
     
    11651158        // Define sources
    11661159
    1167         $group->set_source_sql("
    1168             SELECT g.*
    1169               FROM {groups} g
    1170               JOIN {backup_ids_temp} bi ON g.id = bi.itemid
    1171              WHERE bi.backupid = ?
    1172                AND bi.itemname = 'groupfinal'", array(backup::VAR_BACKUPID));
    1173 
    1174         // This only happens if we are including users
    1175         if ($users) {
    1176             $member->set_source_table('groups_members', array('groupid' => backup::VAR_PARENTID));
    1177         }
    1178 
    1179         $grouping->set_source_sql("
    1180             SELECT g.*
    1181               FROM {groupings} g
    1182               JOIN {backup_ids_temp} bi ON g.id = bi.itemid
    1183              WHERE bi.backupid = ?
    1184                AND bi.itemname = 'groupingfinal'", array(backup::VAR_BACKUPID));
    1185 
    1186         $groupinggroup->set_source_table('groupings_groups', array('groupingid' => backup::VAR_PARENTID));
     1160        // This only happens if we are including groups/groupings.
     1161        if ($groupinfo) {
     1162            $group->set_source_sql("
     1163                SELECT g.*
     1164                  FROM {groups} g
     1165                  JOIN {backup_ids_temp} bi ON g.id = bi.itemid
     1166                 WHERE bi.backupid = ?
     1167                   AND bi.itemname = 'groupfinal'", array(backup::VAR_BACKUPID));
     1168
     1169            $grouping->set_source_sql("
     1170                SELECT g.*
     1171                  FROM {groupings} g
     1172                  JOIN {backup_ids_temp} bi ON g.id = bi.itemid
     1173                 WHERE bi.backupid = ?
     1174                   AND bi.itemname = 'groupingfinal'", array(backup::VAR_BACKUPID));
     1175            $groupinggroup->set_source_table('groupings_groups', array('groupingid' => backup::VAR_PARENTID));
     1176
     1177            // This only happens if we are including users.
     1178            if ($userinfo) {
     1179                $member->set_source_table('groups_members', array('groupid' => backup::VAR_PARENTID));
     1180            }
     1181        }
    11871182
    11881183        // Define id annotations (as final)
     
    12161211        $roleassignments = $this->get_setting_value('role_assignments');
    12171212
    1218         // Define each element separated
     1213        // Define each element separate.
    12191214
    12201215        $users = new backup_nested_element('users');
     
    14891484        return $logs;
    14901485    }
     1486}
     1487
     1488/**
     1489 * Structure step in charge of constructing the logstores.xml file for the course logs.
     1490 *
     1491 * This backup step will backup the logs for all the enabled logstore subplugins supporting
     1492 * it, for logs belonging to the course level.
     1493 */
     1494class backup_course_logstores_structure_step extends backup_structure_step {
     1495
     1496    protected function define_structure() {
     1497
     1498        // Define the structure of logstores container.
     1499        $logstores = new backup_nested_element('logstores');
     1500        $logstore = new backup_nested_element('logstore');
     1501        $logstores->add_child($logstore);
     1502
     1503        // Add the tool_log logstore subplugins information to the logstore element.
     1504        $this->add_subplugin_structure('logstore', $logstore, true, 'tool', 'log');
     1505
     1506        return $logstores;
     1507    }
     1508}
     1509
     1510/**
     1511 * Structure step in charge of constructing the logstores.xml file for the activity logs.
     1512 *
     1513 * Note: Activity structure is completely equivalent to the course one, so just extend it.
     1514 */
     1515class backup_activity_logstores_structure_step extends backup_course_logstores_structure_step {
    14911516}
    14921517
     
    16191644        $info['original_course_id'] = $this->get_courseid();
    16201645        $originalcourseinfo = backup_controller_dbops::backup_get_original_course_info($this->get_courseid());
     1646        $info['original_course_format'] = $originalcourseinfo->format;
    16211647        $info['original_course_fullname']  = $originalcourseinfo->fullname;
    16221648        $info['original_course_shortname'] = $originalcourseinfo->shortname;
     
    16361662            'name', 'moodle_version', 'moodle_release', 'backup_version',
    16371663            'backup_release', 'backup_date', 'mnet_remoteusers', 'include_files', 'include_file_references_to_external_content', 'original_wwwroot',
    1638             'original_site_identifier_hash', 'original_course_id',
     1664            'original_site_identifier_hash', 'original_course_id', 'original_course_format',
    16391665            'original_course_fullname', 'original_course_shortname', 'original_course_startdate',
    16401666            'original_course_contextid', 'original_system_contextid'));
     
    21452171     */
    21462172    protected function execute_condition() {
     2173
     2174        // No grades on the front page.
     2175        if ($this->get_courseid() == SITEID) {
     2176            return false;
     2177        }
     2178
    21472179        return plugin_supports('mod', $this->get_task()->get_modulename(), FEATURE_ADVANCED_GRADING, false);
    21482180    }
     
    22182250class backup_activity_grades_structure_step extends backup_structure_step {
    22192251
     2252    /**
     2253     * No grades on the front page.
     2254     * @return bool
     2255     */
     2256    protected function execute_condition() {
     2257        return ($this->get_courseid() != SITEID);
     2258    }
     2259
    22202260    protected function define_structure() {
    22212261
     
    23012341 */
    23022342class backup_activity_grade_history_structure_step extends backup_structure_step {
     2343
     2344    /**
     2345     * No grades on the front page.
     2346     * @return bool
     2347     */
     2348    protected function execute_condition() {
     2349        return ($this->get_courseid() != SITEID);
     2350    }
    23032351
    23042352    protected function define_structure() {
     
    23492397
    23502398    protected function execute_condition() {
     2399
     2400        // No completion on front page.
     2401        if ($this->get_courseid() == SITEID) {
     2402            return false;
     2403        }
     2404
    23512405        // Check that all activities have been included
    23522406        if ($this->task->is_excluding_activities()) {
     
    23692423
    23702424        $criteria = new backup_nested_element('course_completion_criteria', array('id'), array(
    2371             'course','criteriatype', 'module', 'moduleinstance', 'courseinstanceshortname', 'enrolperiod', 'timeend', 'gradepass', 'role'
     2425            'course', 'criteriatype', 'module', 'moduleinstance', 'courseinstanceshortname', 'enrolperiod',
     2426            'timeend', 'gradepass', 'role', 'roleshortname'
    23722427        ));
    23732428
     
    23922447        $cc->add_child($aggregatemethod);
    23932448
    2394         // We need to get the courseinstances shortname rather than an ID for restore
    2395         $criteria->set_source_sql("SELECT ccc.*, c.shortname AS courseinstanceshortname
    2396                                    FROM {course_completion_criteria} ccc
    2397                                    LEFT JOIN {course} c ON c.id = ccc.courseinstance
    2398                                    WHERE ccc.course = ?", array(backup::VAR_COURSEID));
    2399 
     2449        // We need some extra data for the restore.
     2450        // - courseinstances shortname rather than an ID.
     2451        // - roleshortname in case restoring on a different site.
     2452        $sourcesql = "SELECT ccc.*, c.shortname AS courseinstanceshortname, r.shortname AS roleshortname
     2453                        FROM {course_completion_criteria} ccc
     2454                   LEFT JOIN {course} c ON c.id = ccc.courseinstance
     2455                   LEFT JOIN {role} r ON r.id = ccc.role
     2456                       WHERE ccc.course = ?";
     2457        $criteria->set_source_sql($sourcesql, array(backup::VAR_COURSEID));
    24002458
    24012459        $aggregatemethod->set_source_table('course_completion_aggr_methd', array('course' => backup::VAR_COURSEID));
Note: See TracChangeset for help on using the changeset viewer.