Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 159... Línea 159...
159
        $xmldb_table->add_index('backupid_contextid_component_filearea_itemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid','contextid','component','filearea','itemid'));
159
        $xmldb_table->add_index('backupid_contextid_component_filearea_itemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid','contextid','component','filearea','itemid'));
Línea 160... Línea 160...
160
 
160
 
161
        $dbman->create_temp_table($xmldb_table); // And create it
161
        $dbman->create_temp_table($xmldb_table); // And create it
Línea -... Línea 162...
-
 
162
    }
-
 
163
 
-
 
164
    /**
-
 
165
     * Create temporary tables to store a partial copies of question category data from the backup_ids_temp table.
-
 
166
     *
-
 
167
     * This is to work around MySQL's restruction on joining the same temporary table multiple times in the same query. It isn't
-
 
168
     * necessary on PostgreSQL (which can join temporary tables multiple times) or MSSQL (which doesn't really use temporary tables)
-
 
169
     * but doing it this way keeps things database-agnostic.
-
 
170
     */
-
 
171
    public static function create_question_category_temp_tables(): void {
-
 
172
        global $DB;
-
 
173
        $dbman = $DB->get_manager();
-
 
174
 
-
 
175
        foreach (['question_category_complete_temp', 'question_category_partial_temp'] as $tablename) {
-
 
176
            $xmldbtable = new xmldb_table($tablename);
-
 
177
            $xmldbtable->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
-
 
178
            $xmldbtable->add_field('backupid', XMLDB_TYPE_CHAR, 32, null, XMLDB_NOTNULL);
-
 
179
            $xmldbtable->add_field('itemid', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
-
 
180
            $xmldbtable->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
 
181
 
-
 
182
            $dbman->create_temp_table($xmldbtable);
-
 
183
        }
162
    }
184
    }
163
 
185
 
164
    public static function drop_backup_ids_temp_table($backupid) {
186
    public static function drop_backup_ids_temp_table($backupid) {
Línea 165... Línea 187...
165
        global $DB;
187
        global $DB;
Línea 171... Línea 193...
171
            $dbman->drop_table($table); // And drop it
193
            $dbman->drop_table($table); // And drop it
172
        }
194
        }
173
    }
195
    }
Línea 174... Línea 196...
174
 
196
 
-
 
197
    /**
-
 
198
     * Dispose of the additional temporary tables.
-
 
199
     */
-
 
200
    public static function drop_question_category_temp_tables(): void {
-
 
201
        global $DB;
-
 
202
        $dbman = $DB->get_manager();
-
 
203
 
-
 
204
        foreach (['question_category_complete_temp', 'question_category_partial_temp'] as $tablename) {
-
 
205
            if ($dbman->table_exists($tablename)) {
-
 
206
                $xmldbtable = new xmldb_table($tablename);
-
 
207
                $dbman->drop_table($xmldbtable);
-
 
208
            }
-
 
209
        }
-
 
210
    }
-
 
211
 
175
    /**
212
    /**
176
     * Decode the info field from backup_ids_temp or backup_files_temp.
213
     * Decode the info field from backup_ids_temp or backup_files_temp.
177
     *
214
     *
178
     * @param mixed $info The info field data to decode, may be an object or a simple integer.
215
     * @param mixed $info The info field data to decode, may be an object or a simple integer.
179
     * @return mixed The decoded information.  For simple types it returns, for complex ones we decode.
216
     * @return mixed The decoded information.  For simple types it returns, for complex ones we decode.
Línea 232... Línea 269...
232
        $contentinfo = array(
269
        $contentinfo = array(
233
            'moduleid'   => $task->get_moduleid(),
270
            'moduleid'   => $task->get_moduleid(),
234
            'sectionid'  => $task->get_sectionid(),
271
            'sectionid'  => $task->get_sectionid(),
235
            'modulename' => $task->get_modulename(),
272
            'modulename' => $task->get_modulename(),
236
            'title'      => $task->get_name(),
273
            'title'      => $task->get_name(),
237
            'directory'  => 'activities/' . $task->get_modulename() . '_' . $task->get_moduleid());
274
            'directory'  => 'activities/' . $task->get_modulename() . '_' . $task->get_moduleid(),
-
 
275
            'insubsection' => ($task->is_in_subsection()) ? 1 : '',
-
 
276
        );
Línea 238... Línea 277...
238
 
277
 
239
        // Now get activity settings
278
        // Now get activity settings
240
        // Calculate prefix to find valid settings
279
        // Calculate prefix to find valid settings
241
        $prefix = basename($contentinfo['directory']);
280
        $prefix = basename($contentinfo['directory']);
Línea 244... Línea 283...
244
            // Discard ones without valid prefix
283
            // Discard ones without valid prefix
245
            if (strpos($setting->get_name(), $prefix) !== 0) {
284
            if (strpos($setting->get_name(), $prefix) !== 0) {
246
                continue;
285
                continue;
247
            }
286
            }
248
            // Validate level is correct (activity)
287
            // Validate level is correct (activity)
249
            if ($setting->get_level() != backup_setting::ACTIVITY_LEVEL) {
288
            if (!in_array($setting->get_level(), [backup_setting::ACTIVITY_LEVEL, backup_setting::SUBACTIVITY_LEVEL])) {
250
                throw new backup_controller_exception('setting_not_activity_level', $setting);
289
                throw new backup_controller_exception('setting_not_activity_level', $setting);
251
            }
290
            }
252
            $settinginfo = array(
291
            $settinginfo = array(
253
                'level'    => 'activity',
292
                'level'    => 'activity',
254
                'activity' => $prefix,
293
                'activity' => $prefix,
Línea 266... Línea 305...
266
    private static function get_section_backup_information($task) {
305
    private static function get_section_backup_information($task) {
Línea 267... Línea 306...
267
 
306
 
268
        $contentinfo = array(
307
        $contentinfo = array(
269
            'sectionid'  => $task->get_sectionid(),
308
            'sectionid'  => $task->get_sectionid(),
270
            'title'      => $task->get_name(),
309
            'title'      => $task->get_name(),
-
 
310
            'directory'  => 'sections/' . 'section_' . $task->get_sectionid(),
-
 
311
            'parentcmid' => $task->get_delegated_cm() ?? '',
-
 
312
            'modname' => $task->get_modname() ?? '',
Línea 271... Línea 313...
271
            'directory'  => 'sections/' . 'section_' . $task->get_sectionid());
313
        );
272
 
314
 
273
        // Now get section settings
315
        // Now get section settings
274
        // Calculate prefix to find valid settings
316
        // Calculate prefix to find valid settings
Línea 278... Línea 320...
278
            // Discard ones without valid prefix
320
            // Discard ones without valid prefix
279
            if (strpos($setting->get_name(), $prefix) !== 0) {
321
            if (strpos($setting->get_name(), $prefix) !== 0) {
280
                continue;
322
                continue;
281
            }
323
            }
282
            // Validate level is correct (section)
324
            // Validate level is correct (section)
283
            if ($setting->get_level() != backup_setting::SECTION_LEVEL) {
325
            if (!in_array($setting->get_level(), [backup_setting::SECTION_LEVEL, backup_setting::SUBSECTION_LEVEL])) {
284
                throw new backup_controller_exception('setting_not_section_level', $setting);
326
                throw new backup_controller_exception('setting_not_section_level', $setting);
285
            }
327
            }
286
            $settinginfo = array(
328
            $settinginfo = array(
287
                'level'    => 'section',
329
                'level'    => 'section',
288
                'section'  => $prefix,
330
                'section'  => $prefix,
Línea 357... Línea 399...
357
     *
399
     *
358
     * @param string $backupid Backup ID
400
     * @param string $backupid Backup ID
359
     * @param \core\progress\base $progress Optional progress monitor
401
     * @param \core\progress\base $progress Optional progress monitor
360
     */
402
     */
361
    public static function get_moodle_backup_information($backupid,
403
    public static function get_moodle_backup_information($backupid,
362
            \core\progress\base $progress = null) {
404
            ?\core\progress\base $progress = null) {
Línea 363... Línea 405...
363
 
405
 
364
        // Start tracking progress if required (for load_controller).
406
        // Start tracking progress if required (for load_controller).
365
        if ($progress) {
407
        if ($progress) {
366
            $progress->start_progress('get_moodle_backup_information', 2);
408
            $progress->start_progress('get_moodle_backup_information', 2);
Línea 554... Línea 596...
554
                        'backup_general_users'              => 'users',
596
                        'backup_general_users'              => 'users',
555
                        'backup_general_anonymize'          => 'anonymize',
597
                        'backup_general_anonymize'          => 'anonymize',
556
                        'backup_general_role_assignments'   => 'role_assignments',
598
                        'backup_general_role_assignments'   => 'role_assignments',
557
                        'backup_general_activities'         => 'activities',
599
                        'backup_general_activities'         => 'activities',
558
                        'backup_general_blocks'             => 'blocks',
600
                        'backup_general_blocks'             => 'blocks',
-
 
601
                        'backup_general_files'              => 'files',
559
                        'backup_general_filters'            => 'filters',
602
                        'backup_general_filters'            => 'filters',
560
                        'backup_general_comments'           => 'comments',
603
                        'backup_general_comments'           => 'comments',
561
                        'backup_general_badges'             => 'badges',
604
                        'backup_general_badges'             => 'badges',
562
                        'backup_general_calendarevents'     => 'calendarevents',
605
                        'backup_general_calendarevents'     => 'calendarevents',
563
                        'backup_general_userscompletion'    => 'userscompletion',
606
                        'backup_general_userscompletion'    => 'userscompletion',
564
                        'backup_general_logs'               => 'logs',
607
                        'backup_general_logs'               => 'logs',
565
                        'backup_general_histories'          => 'grade_histories',
608
                        'backup_general_histories'          => 'grade_histories',
566
                        'backup_general_questionbank'       => 'questionbank',
-
 
567
                        'backup_general_groups'             => 'groups',
609
                        'backup_general_groups'             => 'groups',
568
                        'backup_general_competencies'       => 'competencies',
610
                        'backup_general_competencies'       => 'competencies',
-
 
611
                        'backup_general_customfield'        => 'customfield',
569
                        'backup_general_contentbankcontent' => 'contentbankcontent',
612
                        'backup_general_contentbankcontent' => 'contentbankcontent',
570
                        'backup_general_xapistate'          => 'xapistate',
613
                        'backup_general_xapistate'          => 'xapistate',
571
                        'backup_general_legacyfiles'        => 'legacyfiles'
614
                        'backup_general_legacyfiles'        => 'legacyfiles'
572
                );
615
                );
573
                self::apply_admin_config_defaults($controller, $settings, true);
616
                self::apply_admin_config_defaults($controller, $settings, true);
Línea 576... Línea 619...
576
                // Load the import defaults.
619
                // Load the import defaults.
577
                $settings = array(
620
                $settings = array(
578
                        'backup_import_activities'         => 'activities',
621
                        'backup_import_activities'         => 'activities',
579
                        'backup_import_blocks'             => 'blocks',
622
                        'backup_import_blocks'             => 'blocks',
580
                        'backup_import_filters'            => 'filters',
623
                        'backup_import_filters'            => 'filters',
-
 
624
                        'backup_import_badges'             => 'badges',
581
                        'backup_import_calendarevents'     => 'calendarevents',
625
                        'backup_import_calendarevents'     => 'calendarevents',
582
                        'backup_import_permissions'        => 'permissions',
626
                        'backup_import_permissions'        => 'permissions',
583
                        'backup_import_questionbank'       => 'questionbank',
-
 
584
                        'backup_import_groups'             => 'groups',
627
                        'backup_import_groups'             => 'groups',
585
                        'backup_import_competencies'       => 'competencies',
628
                        'backup_import_competencies'       => 'competencies',
-
 
629
                        'backup_import_customfield'        => 'customfield',
586
                        'backup_import_contentbankcontent' => 'contentbankcontent',
630
                        'backup_import_contentbankcontent' => 'contentbankcontent',
587
                        'backup_import_legacyfiles'        => 'legacyfiles'
631
                        'backup_import_legacyfiles'        => 'legacyfiles'
588
                );
632
                );
589
                self::apply_admin_config_defaults($controller, $settings, true);
633
                self::apply_admin_config_defaults($controller, $settings, true);
590
                if ((!$controller->get_interactive()) &&
634
                if ((!$controller->get_interactive()) &&
Línea 592... Línea 636...
592
                    // This is duplicate - there is no concept of defaults - these settings must be on.
636
                    // This is duplicate - there is no concept of defaults - these settings must be on.
593
                    $settings = array(
637
                    $settings = array(
594
                         'activities',
638
                         'activities',
595
                         'blocks',
639
                         'blocks',
596
                         'filters',
640
                         'filters',
597
                         'questionbank'
-
 
598
                    );
641
                    );
599
                    self::force_enable_settings($controller, $settings);
642
                    self::force_enable_settings($controller, $settings);
-
 
643
                    // Badges are not included by default when duplicating activities.
-
 
644
                    self::force_settings($controller, ['badges'], false);
600
                }
645
                }
601
                break;
646
                break;
602
            case backup::MODE_AUTOMATED:
647
            case backup::MODE_AUTOMATED:
603
                // Load the automated defaults.
648
                // Load the automated defaults.
604
                $settings = array(
649
                $settings = array(
605
                        'backup_auto_users'              => 'users',
650
                        'backup_auto_users'              => 'users',
606
                        'backup_auto_role_assignments'   => 'role_assignments',
651
                        'backup_auto_role_assignments'   => 'role_assignments',
607
                        'backup_auto_activities'         => 'activities',
652
                        'backup_auto_activities'         => 'activities',
608
                        'backup_auto_blocks'             => 'blocks',
653
                        'backup_auto_blocks'             => 'blocks',
-
 
654
                        'backup_auto_files'              => 'files',
609
                        'backup_auto_filters'            => 'filters',
655
                        'backup_auto_filters'            => 'filters',
610
                        'backup_auto_comments'           => 'comments',
656
                        'backup_auto_comments'           => 'comments',
611
                        'backup_auto_badges'             => 'badges',
657
                        'backup_auto_badges'             => 'badges',
612
                        'backup_auto_calendarevents'     => 'calendarevents',
658
                        'backup_auto_calendarevents'     => 'calendarevents',
613
                        'backup_auto_userscompletion'    => 'userscompletion',
659
                        'backup_auto_userscompletion'    => 'userscompletion',
614
                        'backup_auto_logs'               => 'logs',
660
                        'backup_auto_logs'               => 'logs',
615
                        'backup_auto_histories'          => 'grade_histories',
661
                        'backup_auto_histories'          => 'grade_histories',
616
                        'backup_auto_questionbank'       => 'questionbank',
-
 
617
                        'backup_auto_groups'             => 'groups',
662
                        'backup_auto_groups'             => 'groups',
618
                        'backup_auto_competencies'       => 'competencies',
663
                        'backup_auto_competencies'       => 'competencies',
-
 
664
                        'backup_auto_customfield'        => 'customfield',
619
                        'backup_auto_contentbankcontent' => 'contentbankcontent',
665
                        'backup_auto_contentbankcontent' => 'contentbankcontent',
620
                        'backup_auto_xapistate'          => 'xapistate',
666
                        'backup_auto_xapistate'          => 'xapistate',
621
                        'backup_auto_legacyfiles'        => 'legacyfiles'
667
                        'backup_auto_legacyfiles'        => 'legacyfiles'
622
                );
668
                );
623
                self::apply_admin_config_defaults($controller, $settings, false);
669
                self::apply_admin_config_defaults($controller, $settings, false);
Línea 633... Línea 679...
633
     *
679
     *
634
     * @param backup_controller $controller
680
     * @param backup_controller $controller
635
     * @param array $settings a map from admin config names to setting names (Config name => Setting name)
681
     * @param array $settings a map from admin config names to setting names (Config name => Setting name)
636
     */
682
     */
637
    private static function force_enable_settings(backup_controller $controller, array $settings) {
683
    private static function force_enable_settings(backup_controller $controller, array $settings) {
-
 
684
        self::force_settings($controller, $settings, true);
-
 
685
    }
-
 
686
 
-
 
687
    /**
-
 
688
     * Set these settings to the given $value. No defaults from admin settings.
-
 
689
     *
-
 
690
     * @param backup_controller $controller The backup controller.
-
 
691
     * @param array $settings a map from admin config names to setting names (Config name => Setting name).
-
 
692
     * @param mixed $value the value to set the settings to.
-
 
693
     */
-
 
694
    private static function force_settings(backup_controller $controller, array $settings, $value) {
638
        $plan = $controller->get_plan();
695
        $plan = $controller->get_plan();
639
        foreach ($settings as $config => $settingname) {
696
        foreach ($settings as $config => $settingname) {
640
            $value = true;
-
 
641
            if ($plan->setting_exists($settingname)) {
697
            if ($plan->setting_exists($settingname)) {
642
                $setting = $plan->get_setting($settingname);
698
                $setting = $plan->get_setting($settingname);
643
                // We do not allow this setting to be locked for a duplicate function.
699
                // We do not allow this setting to be locked for a duplicate function.
644
                if ($setting->get_status() !== base_setting::NOT_LOCKED) {
700
                if ($setting->get_status() !== base_setting::NOT_LOCKED) {
645
                    $setting->set_status(base_setting::NOT_LOCKED);
701
                    $setting->set_status(base_setting::NOT_LOCKED);