2010-04-21 09:26:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package moodlecore
|
|
|
|
* @subpackage backup
|
|
|
|
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class defining common stuff to be used by the backup stuff
|
|
|
|
*
|
|
|
|
* This class defines various constants and methods that will be used
|
|
|
|
* by different classes, all related with the backup process. Just provides
|
|
|
|
* the top hierarchy of the backup controller/worker stuff.
|
|
|
|
*
|
|
|
|
* TODO: Finish phpdocs
|
|
|
|
*/
|
|
|
|
abstract class backup implements checksumable {
|
|
|
|
|
|
|
|
// Backup type
|
2010-04-28 21:43:48 +00:00
|
|
|
const TYPE_1ACTIVITY = 'activity';
|
|
|
|
const TYPE_1SECTION = 'section';
|
|
|
|
const TYPE_1COURSE = 'course';
|
2010-04-21 09:26:06 +00:00
|
|
|
|
|
|
|
// Backup format
|
|
|
|
const FORMAT_MOODLE = 'moodle2';
|
2011-05-05 02:21:23 +02:00
|
|
|
const FORMAT_MOODLE1 = 'moodle1';
|
2011-10-26 10:14:54 -07:00
|
|
|
const FORMAT_IMSCC1 = 'imscc1';
|
|
|
|
const FORMAT_IMSCC11 = 'imscc11';
|
2010-07-05 16:37:50 +00:00
|
|
|
const FORMAT_UNKNOWN = 'unknown';
|
2010-04-21 09:26:06 +00:00
|
|
|
|
|
|
|
// Interactive
|
|
|
|
const INTERACTIVE_YES = true;
|
|
|
|
const INTERACTIVE_NO = false;
|
|
|
|
|
2019-03-13 11:41:13 +10:00
|
|
|
/** Release the session during backup/restore */
|
|
|
|
const RELEASESESSION_YES = true;
|
|
|
|
/** Don't release the session during backup/restore */
|
|
|
|
const RELEASESESSION_NO = false;
|
|
|
|
|
2010-04-21 09:26:06 +00:00
|
|
|
// Predefined modes (purposes) of the backup
|
backup MDL-22184 Scheduled backups are now possible again through cron.
AMOS BEGIN
MOV [move scheduledsetup,core_backup],[automatedsetup,core_backup]
MOV [scheduledsettings,core_backup],[automatedsettings,core_backup]
MOV [scheduledstorage,core_backup],[automatedstorage,core_backup]
MOV [scheduledstoragehelp,core_backup],[automatedstoragehelp,core_backup]
MOV [scheduledbackupsinactive,core],[automatedbackupsinactive,core_backup]
MOV [scheduledbackupstatus,core],[automatedbackupstatus,core_backup]
CPY [schedule,core],[automatedbackupschedule,core_backup]
MOV [backupschedulehelp,core],[automatedbackupschedulehelp,core_backup]
AMOS END
2010-11-10 06:07:43 +00:00
|
|
|
const MODE_GENERAL = 10;
|
2013-05-14 11:44:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is used for importing courses, and for duplicating activities.
|
|
|
|
*
|
|
|
|
* This mode will ensure that files are not included in the backup generation, and
|
|
|
|
* during a restore they are copied from the existing file record.
|
|
|
|
*/
|
backup MDL-22184 Scheduled backups are now possible again through cron.
AMOS BEGIN
MOV [move scheduledsetup,core_backup],[automatedsetup,core_backup]
MOV [scheduledsettings,core_backup],[automatedsettings,core_backup]
MOV [scheduledstorage,core_backup],[automatedstorage,core_backup]
MOV [scheduledstoragehelp,core_backup],[automatedstoragehelp,core_backup]
MOV [scheduledbackupsinactive,core],[automatedbackupsinactive,core_backup]
MOV [scheduledbackupstatus,core],[automatedbackupstatus,core_backup]
CPY [schedule,core],[automatedbackupschedule,core_backup]
MOV [backupschedulehelp,core],[automatedbackupschedulehelp,core_backup]
AMOS END
2010-11-10 06:07:43 +00:00
|
|
|
const MODE_IMPORT = 20;
|
|
|
|
const MODE_HUB = 30;
|
2013-05-14 11:44:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This mode is intended for duplicating courses and cases where the backup target is
|
|
|
|
* within the same site.
|
|
|
|
*
|
|
|
|
* This mode will ensure that files are not included in the backup generation, and
|
|
|
|
* during a restore they are copied from the existing file record.
|
|
|
|
*
|
|
|
|
* For creating a backup for archival purposes or greater longevity, use MODE_GENERAL.
|
|
|
|
*/
|
backup MDL-22184 Scheduled backups are now possible again through cron.
AMOS BEGIN
MOV [move scheduledsetup,core_backup],[automatedsetup,core_backup]
MOV [scheduledsettings,core_backup],[automatedsettings,core_backup]
MOV [scheduledstorage,core_backup],[automatedstorage,core_backup]
MOV [scheduledstoragehelp,core_backup],[automatedstoragehelp,core_backup]
MOV [scheduledbackupsinactive,core],[automatedbackupsinactive,core_backup]
MOV [scheduledbackupstatus,core],[automatedbackupstatus,core_backup]
CPY [schedule,core],[automatedbackupschedule,core_backup]
MOV [backupschedulehelp,core],[automatedbackupschedulehelp,core_backup]
AMOS END
2010-11-10 06:07:43 +00:00
|
|
|
const MODE_SAMESITE = 40;
|
|
|
|
const MODE_AUTOMATED = 50;
|
2011-05-16 19:02:13 +02:00
|
|
|
const MODE_CONVERTED = 60;
|
2010-04-21 09:26:06 +00:00
|
|
|
|
2018-12-20 15:32:46 +11:00
|
|
|
/**
|
|
|
|
* This mode is for asynchronous backups.
|
|
|
|
* These backups will run via adhoc scheduled tasks.
|
|
|
|
*/
|
|
|
|
const MODE_ASYNC = 70;
|
|
|
|
|
2020-03-02 04:24:19 +11:00
|
|
|
/**
|
|
|
|
* This mode is for course copies.
|
|
|
|
* It is similar to async, but identifies back up and restore tasks
|
|
|
|
* as course copies.
|
|
|
|
*
|
|
|
|
* These copies will run via adhoc scheduled tasks.
|
|
|
|
*/
|
|
|
|
const MODE_COPY = 80;
|
|
|
|
|
2010-07-06 22:25:54 +00:00
|
|
|
// Target (new/existing/current/adding/deleting)
|
|
|
|
const TARGET_CURRENT_DELETING = 0;
|
|
|
|
const TARGET_CURRENT_ADDING = 1;
|
|
|
|
const TARGET_NEW_COURSE = 2;
|
|
|
|
const TARGET_EXISTING_DELETING= 3;
|
|
|
|
const TARGET_EXISTING_ADDING = 4;
|
|
|
|
|
2010-04-21 09:26:06 +00:00
|
|
|
// Execution mode
|
|
|
|
const EXECUTION_INMEDIATE = 1;
|
|
|
|
const EXECUTION_DELAYED = 2;
|
|
|
|
|
|
|
|
// Status of the backup_controller
|
|
|
|
const STATUS_CREATED = 100;
|
2010-07-05 16:37:50 +00:00
|
|
|
const STATUS_REQUIRE_CONV= 200;
|
|
|
|
const STATUS_PLANNED = 300;
|
|
|
|
const STATUS_CONFIGURED = 400;
|
|
|
|
const STATUS_SETTING_UI = 500;
|
2010-07-05 22:10:51 +00:00
|
|
|
const STATUS_NEED_PRECHECK=600;
|
|
|
|
const STATUS_AWAITING = 700;
|
|
|
|
const STATUS_EXECUTING = 800;
|
|
|
|
const STATUS_FINISHED_ERR= 900;
|
|
|
|
const STATUS_FINISHED_OK =1000;
|
2010-04-21 09:26:06 +00:00
|
|
|
|
|
|
|
// Logging levels
|
|
|
|
const LOG_DEBUG = 50;
|
|
|
|
const LOG_INFO = 40;
|
|
|
|
const LOG_WARNING = 30;
|
|
|
|
const LOG_ERROR = 20;
|
|
|
|
const LOG_NONE = 10;
|
|
|
|
|
|
|
|
// Some constants used to identify some helpfull processor variables
|
|
|
|
// (using negative numbers to avoid any collision posibility
|
|
|
|
// To be used when defining backup structures
|
|
|
|
const VAR_COURSEID = -1; // To reference id of course in a processor
|
|
|
|
const VAR_SECTIONID = -11; // To reference id of section in a processor
|
|
|
|
const VAR_ACTIVITYID = -21; // To reference id of activity in a processor
|
|
|
|
const VAR_MODID = -31; // To reference id of course_module in a processor
|
|
|
|
const VAR_MODNAME = -41; // To reference name of module in a processor
|
|
|
|
const VAR_BLOCKID = -51; // To reference id of block in a processor
|
|
|
|
const VAR_BLOCKNAME = -61; // To reference name of block in a processor
|
|
|
|
const VAR_CONTEXTID = -71; // To reference context id in a processor
|
|
|
|
const VAR_PARENTID = -81; // To reference the first parent->id in a backup structure
|
|
|
|
|
|
|
|
// Used internally by the backup process
|
|
|
|
const VAR_BACKUPID = -1001; // To reference the backupid being processed
|
|
|
|
const VAR_BASEPATH = -1011; // To reference the dir where the file is generated
|
|
|
|
|
2010-07-05 16:37:50 +00:00
|
|
|
// Type of operation
|
|
|
|
const OPERATION_BACKUP ='backup'; // We are performing one backup
|
|
|
|
const OPERATION_RESTORE ='restore';// We are performing one restore
|
|
|
|
|
2017-01-10 15:59:44 +08:00
|
|
|
// Options for "Include enrolment methods" restore setting.
|
|
|
|
const ENROL_NEVER = 0;
|
|
|
|
const ENROL_WITHUSERS = 1;
|
|
|
|
const ENROL_ALWAYS = 2;
|
|
|
|
|
2015-05-05 18:23:21 +02:00
|
|
|
// Version and release (to keep CFG->backup_version (and release) updated automatically).
|
|
|
|
/**
|
|
|
|
* Usually same than major release version, this is used to mark important
|
|
|
|
* point is backup when some behavior/approach channged, in order to allow
|
|
|
|
* conditional coding based on it.
|
|
|
|
*/
|
2023-10-04 13:57:17 +08:00
|
|
|
const VERSION = 2023100900;
|
2015-05-05 18:23:21 +02:00
|
|
|
/**
|
|
|
|
* Usually same than major release zero version, mainly for informative/historic purposes.
|
|
|
|
*/
|
2023-10-10 10:06:31 +08:00
|
|
|
const RELEASE = '4.4';
|
2016-06-27 02:32:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cipher to be used in backup and restore operations.
|
|
|
|
*/
|
|
|
|
const CIPHER = 'aes-256-cbc';
|
|
|
|
/**
|
|
|
|
* Bytes enforced for key, using the cypher above. Restrictive? Yes, but better than unsafe lengths
|
|
|
|
*/
|
|
|
|
const CIPHERKEYLEN = 32;
|
2010-04-21 09:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exception class used by all the @backup stuff
|
|
|
|
*/
|
2010-04-27 01:02:38 +00:00
|
|
|
abstract class backup_exception extends moodle_exception {
|
2010-04-21 09:26:06 +00:00
|
|
|
|
|
|
|
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
2011-06-10 15:44:20 +01:00
|
|
|
parent::__construct($errorcode, 'error', '', $a, $debuginfo);
|
2010-04-21 09:26:06 +00:00
|
|
|
}
|
|
|
|
}
|