74 Commits

Author SHA1 Message Date
Meirza
8a5485a714 MDL-77338 backup: Added class properties that are not declared.
In PHP 8.2 and later, setting a value to an undeclared class property is
deprecated and emits a deprecation notice.
So we need to add missing class properties that still need to be declared.
2023-04-03 22:39:39 +07:00
Matthew Hilton
49c4cfb2d5 MDL-73317 restore: Reset navcache before closing session
As part of a restore, the session is closed early so it does not
interrupt the users session during the restore.

Currently the restore controller rebuilds the course caches while
restoring. This inadvertently resets the navcache, which would edit the
session despite it being closed.

Because this tracker now adds logging for this behaviour, it means
restoring now outputs a debugging message as a warning.

To resolve the debugging message, the navcache is now reset just before
closing the session. This is allowed, since the caches are designed
to be volatile.
2023-02-09 12:03:49 +10:00
Cameron Ball
2ac93db399 MDL-74548 backup: Deprecate get/set copy from base controller 2022-06-29 09:14:02 +08:00
Cameron Ball
bc9c536335 MDL-74548 backup: Unit tests for course copy refactor 2022-06-29 09:13:29 +08:00
Cameron Ball
29df52af19 MDL-74548 backup: Refactor course copies
This patch modifies the way copy data is shared in order to mitigate potential race conditions
and ensure that the serialised controller stored in the DB is always in a valid state.

The restore controller is now considered the "source of truth" for all information about the
copy operation. Backup controllers can no longer contain information about course copies.

As copy creation is not atomic, it is still possible for copy controllers to become orphaned or
exist in an invalid state. To mitigate this the backup cleanup task has been modified to call
a new helper method copy_helper::cleanup_orphaned_copy_controllers.

Summary of changes in this patch:

    - Copy data must now be passed through the restore controller's constructor
    - base_controller::get_copy has been deprecated in favour of restore_controller::get_copy
    - base_controller::set_copy has been deprecated without replacement
    - core_backup\copy\copy has been deprecated, use copy_helper.class.php's copy_helper instead
    - backup_cleanup_task will now clean up orphaned controllers from copy operations that went awry

Thanks to Peter Burnett for assiting with testing this patch.
2022-06-29 09:13:29 +08:00
Eloy Lafuente (stronk7)
9f53b0e965 MDL-73971 phpunit: Move more tests to use correct names and namespaces
Applied the following changes to various testcase classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.

Special mention to:

- Some fixtures, initially defined in the test files have been
  moved to new files in fixtures subdirectory, leaving the unit
  test files clearer:
  - moodle2_course_format_test.php
- Rename wrong named test:
  - baseoptiogroup_test = baseoptigroup_test
2022-05-06 18:29:11 +02:00
Tim Hunt
e7880337ad MDL-72265 backup: fix checking of override capabilites on restore
Thanks to Peter Dias <peter@moodle.com> for his help with the unit test.
2021-08-05 13:54:59 +01:00
Neill Magill
3a8db568e1 MDL-69524 backup: Code style fixes for the file 2021-06-17 09:31:17 +01:00
Neill Magill
0f073a4b10 MDL-69524 backup: Add PHPdocs to backup_controller class 2021-06-17 09:31:15 +01:00
Mihail Geshoski
c8ac07fb50 MDL-67837 backup: Verify caps before unenrolling users on course restore 2020-11-03 12:34:28 +01:00
Eloy Lafuente (stronk7)
f6711bb394 MDL-67673 phpunit: Fix the return type of template methods
All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.

At the same time, fix a few wrong function names,
provider data and param types, return statements...
2020-10-21 12:45:59 +02:00
Matt Porritt
01436f7539 MDL-64843 Backup: Course copy user interface
This patch adds better core support for copying courses.
There is now a simplified and dedicated UI for copying
courses. This can be accessed from the course context
menu or course management screens.

All backups are done asynchronously and there can be multiple
copies of a course in flight at once.
2020-05-15 06:02:02 +00:00
Rossco Hellmans
383b0f95ab MDL-64310 backup: allow session to be released during backup/restore
Amended to fix a wrong call to backup_controller() constructor,
originally not passing USER->id
2020-01-14 23:54:42 +01:00
Tim Hunt
a6a4034b38 MDL-66709 backup: improve some PHPdoc type hints
I hope these are right. They seem to be, and made the autocomplete
better in some backup/restore code I was writing.
2019-09-23 19:21:09 +01:00
Mark Nelson
56e28c3bf1 MDL-35773 core_backup: controller has full responsibility for files 2019-07-26 17:00:40 +08:00
Mark Nelson
8e83e54815 MDL-35773 core_backup: removed introduction of 'set_mode' 2019-07-26 11:59:56 +08:00
Matt Porritt
d7e4481e98 MDL-35773 Backup: API should have option to not backup files
Allow both UI and automated backups to be created without
including files.  Instead include only file references.
This is essentially implementing "SAMESITE" to backup files
instead of only for import and export functionality.
A new backup setting to include files (defaults to yes)
has been included.

The restore process will also look for and attempt to
restore files from the trashdir as part of restoring
backups.  Additionally to support this process the
ammount of time files are kept in trashdir before they
are cleaned up via cron is also adjustable via admin
setting.
2019-07-26 11:59:56 +08:00
Peter
ee1062686c MDL-66021 backup: Clear course if required before restore 2019-07-15 13:16:50 +08:00
David Monllaó
e034670fac Merge branch 'MDL-62572-master' of git://github.com/damyon/moodle 2019-04-15 11:04:54 +02:00
Damyon Wiese
f10c22b691 MDL-62572 backup: Duplicating an activity
Don't apply admin defaults for import when using the duplicate function.
2019-04-12 14:04:40 +08:00
Matt Porritt
2cd901a4e7 MDL-28505 Backup: Asynchronous backup and restore
This patch adds asynchronous backup and restore functionality
to Moodle. This is an optional feature and is not enabled by
default. It can be enabled by site administrators.
Asynchronous backup and restores are actioned by the Moodle
adhoc task API. The progress of backup and restores is
displayedin the Moodle UI.  Users can also be sent a message
when a backup or restore operation completes via the
Moodle messaging API.
2019-04-09 00:15:42 +00:00
Matteo Scaramuccia
ef844148a9 MDL-60923 backup: Added $CFG->backuptempdir
The new setting will allow to host the temporary backup files
into a specific target directory. Defaults to '$CFG->tempdir/backup'.

Calling make_backup_temp_directory() checks that the required sub-directory
will be properly created under the new target directory.
2018-04-16 23:50:28 +02:00
John Okely
d1b79250c6 MDL-57698 backup: Decrease deadlock fixture size 2017-07-26 10:45:58 +08:00
John Okely
b1fc170b21 MDL-57698 sqlsrv: Unit test deadlock case 2017-07-21 14:41:54 +08:00
Marina Glancy
44e86fb3d5 MDL-34859 backup: add restore defaults 2017-03-20 14:59:45 +08:00
Marina Glancy
92253b15b7 MDL-40838 backup: restore enrolment methods without users 2017-02-20 12:08:35 +08:00
Eloy Lafuente (stronk7)
53f95c99cb MDL-54205 backup: loggers close() and destroy()
Any backup & restore operation may be leaving opened files
if a file logger is being used. This implementes the close()
method, so every logger can close any resource.

Also, the recommended backup_controlled::destroy() method
now calls to new logger::destroy() method in charge of
deleting all the references and closing any resource.

Finally, some internally used controllers, were missing
their destroy call, leading to associated loggers to
remain open. Now all them are explicitly deltroyed.
2016-05-13 01:54:28 +02:00
Tony Levi
303936aa57 MDL-50453 core: Replace reserved word usage in progress\null (PHP7) 2015-06-15 12:21:27 +09:30
sam marshall
ddf368a213 MDL-44141 Completion: System updates data during restore
The completion system has code which is supposed to prevent it
updating completion status while grades are being restored. This
code was a nasty hack and had not worked for some time. As a result
completion dates were restored incorrectly.

This commit implements a 'proper' way to find out if a restore is
currently running, replacing the previous hack.
2014-03-18 13:31:34 +00:00
James Pratt
809fdb83b1 MDL-41754 (1) Progress tracking : moved from backup and restore to core 2014-01-27 17:45:50 +07:00
sam marshall
3ef7279f26 MDL-42084 Core: Change set_time_limit to core_php_time_limit::raise everywhere
Exceptions (places where set_time_limit is still left) are:

Third-party libraries:
  ADODB
  PHPMailer

Moodle core:
  PHPUnit - not relevant (CLI mode)
2013-11-06 16:40:01 +00:00
Damyon Wiese
5d5c4c0b73 MDL-43411 Backup: Fix restore from 1.9
The restore progress bars introduced a bug when restoring Moodle 1.9 backups.
build_plan needs to be surrounded with start_progress/end_progress with the mode
set to indeterminite or it throws coding errors.
2013-10-17 15:54:24 +08:00
sam marshall
bf2a039e9a MDL-42039 Restore: Add progress tracking in restore controller load
In the case of a very large backup with many activities, simply loading
the restore controller (specifically, building the plan) can take a long
time and cause timeouts. This change adds progress reporting while the
restore controller is being loaded.

(This also reduces the time between first going to the page, and the
progress bar appearing, making a slightly better user experience.)

Conflicts:

	backup/restore.php
2013-10-10 10:57:24 +08:00
sam marshall
77b3d9dfdf MDL-38196 Backup/restore: Display log if non-empty
When doing a backup or restore operation with the normal user interface,
if there is anything in the backup/restore log, it will now be displayed
at the end of the process below the Continue button.

If you have developer debugging enabled, it sets the display level to
LOG_DEBUG and there will always be content in the log. Otherwise, it
uses LOG_INFO which generally means the log is empty, and nothing
displays (no visible change for users).
2013-10-08 11:00:11 +01:00
Dan Poltawski
0df3254212 Merge branch 'MDL-41254-m' of git://github.com/micaherne/moodle 2013-09-09 18:04:05 +08:00
Michael Aherne
91dbb24442 MDL-41254 backup Raise time and memory limit in precheck. 2013-09-02 10:22:40 +01:00
sam marshall
16cd708835 MDL-38190 (1) Backup/restore: Progress tracking API 2013-08-16 10:50:35 +01:00
Petr Škoda
8252b7c291 MDL-40901 standardise core test case class and file names
This finally allows us to type only the class name when executing individual core test cases.
2013-08-04 22:10:31 +02:00
Andrew Nicols
b1850c12c1 MDL-37761 Backup: Do not include files in backups when importing courses/activities
When we import courses or duplicate activities, the deduplicating nature of
the file_storage system means that we don't actually have to include the
real files in the backup - just their metadata from the file table.

The restoration process needs to know not to expect files from the backup
phase so a flag is set in moodle_backup metadata.
2013-06-18 07:52:04 +01:00
Eloy Lafuente (stronk7)
93f9755c74 MDL-29262 phpunit: fix forgotten mock objects to avoid strict notices 2012-04-23 15:01:14 +02:00
Dan Poltawski
e0ed91ba39 Merge branch 'MDL-29262' of git://github.com/stronk7/moodle
Conflicts:
	version.php
2012-04-23 12:42:16 +08:00
Eloy Lafuente (stronk7)
749fd68cbb MDL-29262 restore: Clean controller obj form DB once finished ok 2012-04-23 00:14:32 +02:00
Eloy Lafuente (stronk7)
6e803b9fe4 MDL-29262 backup: Clean controller obj form DB once finished ok 2012-04-23 00:03:37 +02:00
Petr Skoda
bb7898c6ab MDL-32569 convert remaining backup tests and drop old simpletests 2012-04-21 16:24:33 +02:00
Petr Skoda
4b02743182 MDL-32149 improve testcase naming and list in config file 2012-04-03 22:30:57 +02:00
Petr Skoda
1cbf2a20ca MDL-32149 setUp() and tearDown() are supposed to be 'protected', add missing blog testcase 2012-04-03 22:30:56 +02:00
Petr Skoda
dbf5a44798 MDL-32149 add backup tests and dropping of extra tables 2012-04-03 22:30:54 +02:00
Eloy Lafuente (stronk7)
184acafab6 MDL-28180 backup - set excluded activities for any non-course operation 2011-12-12 00:30:58 +01:00
Sam Hemelryk
f8adfe6cc0 Merge branch 'w36_MDL-28701_m22_tempcachedir' of git://github.com/skodak/moodle 2011-09-12 18:26:09 +12:00
Eloy Lafuente (stronk7)
59fc0cbdb7 MDL-28488 backup - conditionaly apply defaults based on mode
Some modes of backup cannot be preloaded with general backup
settings because they may conflict with the definitions required/set
by the mode (for example, import backups are, by definition, without
users always, so we cannot apply one default in the opposite direction).

So, after the patch, current general_backup setting will be only applied
to general backups, import/hub modes won't be using any default and
automated backup defaults should be loaded here (TODO)
2011-09-11 19:35:56 +02:00