Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-tool_lifecycle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-tool_lifecycle
Commits
ffff7a24
Unverified
Commit
ffff7a24
authored
8 years ago
by
Tobias Reischmann
Browse files
Options
Downloads
Patches
Plain Diff
First working version of backup step
parent
86ba8cca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
classes/manager/backup_manager.php
+72
-0
72 additions, 0 deletions
classes/manager/backup_manager.php
step/createbackup/lib.php
+5
-5
5 additions, 5 deletions
step/createbackup/lib.php
version.php
+1
-1
1 addition, 1 deletion
version.php
with
78 additions
and
6 deletions
classes/manager/backup_manager.php
0 → 100644
+
72
−
0
View file @
ffff7a24
<?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/>.
/**
* Manager to create & restore backups for courses
*
* @package tool_cleanupcourses
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
tool_cleanupcourses\manager
;
use
WebDriver\Exception
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
class
backup_manager
{
/**
* Creates a course backup in a specific cleanup courses backup folder
* @param int $courseid id of the course the backup should be created for.
* @return bool tells if the backup was completed successfully.
*/
public
static
function
create_course_backup
(
$courseid
)
{
global
$CFG
;
try
{
// Build filename.
$archivefile
=
date
(
"Y-m-d"
)
.
"-ID-
{
$courseid
}
.mbz"
;
// Path of backup folder.
$path
=
$CFG
->
dataroot
.
'/cleanupcourses_backups'
;
// If the path doesn't exist, make it so!
if
(
!
is_dir
(
$path
))
{
umask
(
0000
);
// Create the directory for Backups.
if
(
!
mkdir
(
$path
,
$CFG
->
directorypermissions
,
true
))
{
throw
new
\moodle_exception
(
get_string
(
'errorbackuppath'
,
'tool_cleanupcourses'
));
}
}
// Perform Backup.
$bc
=
new
\backup_controller
(
\backup
::
TYPE_1COURSE
,
$courseid
,
\backup
::
FORMAT_MOODLE
,
\backup
::
INTERACTIVE_NO
,
\backup
::
MODE_AUTOMATED
,
get_admin
()
->
id
);
$bc
->
execute_plan
();
// Execute backup.
$results
=
$bc
->
get_results
();
// Get the file information needed.
$file
=
$results
[
'backup_destination'
];
if
(
!
empty
(
$file
))
{
$file
->
copy_content_to
(
$path
.
'/'
.
$archivefile
);
}
$bc
->
destroy
();
unset
(
$bc
);
return
true
;
}
catch
(
\moodle_exception
$e
)
{
debugging
(
'There was a problem during backup!'
);
debugging
(
$e
->
getMessage
());
return
false
;
}
}
}
This diff is collapsed.
Click to expand it.
step/createbackup/lib.php
+
5
−
5
View file @
ffff7a24
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
namespace
tool_cleanupcourses\step
;
namespace
tool_cleanupcourses\step
;
use
tool_cleanupcourses\response\step_response
;
use
tool_cleanupcourses\response\step_response
;
use
tool_cleanupcourses\manager\backup_manager
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
defined
(
'MOODLE_INTERNAL'
)
||
die
();
...
@@ -51,12 +52,11 @@ class createbackup extends libbase {
...
@@ -51,12 +52,11 @@ class createbackup extends libbase {
* @return step_response
* @return step_response
*/
*/
public
function
process_course
(
$processid
,
$instanceid
,
$course
)
{
public
function
process_course
(
$processid
,
$instanceid
,
$course
)
{
$bc
=
new
\backup_controller
(
\backup
::
TYPE_1COURSE
,
$course
->
id
,
\backup
::
FORMAT_MOODLE
,
if
(
backup_manager
::
create_course_backup
(
$course
->
id
))
{
\backup
::
INTERACTIVE_NO
,
\backup
::
MODE_AUTOMATED
,
get_admin
()
->
id
);
$bc
->
execute_plan
();
$results
=
$bc
->
get_results
();
return
step_response
::
proceed
();
return
step_response
::
proceed
();
}
}
return
step_response
::
waiting
();
}
public
function
get_subpluginname
()
{
public
function
get_subpluginname
()
{
return
'createbackup'
;
return
'createbackup'
;
...
...
This diff is collapsed.
Click to expand it.
version.php
+
1
−
1
View file @
ffff7a24
...
@@ -23,5 +23,5 @@
...
@@ -23,5 +23,5 @@
defined
(
'MOODLE_INTERNAL'
)
||
die
;
defined
(
'MOODLE_INTERNAL'
)
||
die
;
$plugin
->
version
=
201706190
1
;
$plugin
->
version
=
201706190
2
;
$plugin
->
component
=
'tool_cleanupcourses'
;
$plugin
->
component
=
'tool_cleanupcourses'
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment