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
da4ca9a9
Unverified
Commit
da4ca9a9
authored
8 years ago
by
Tobias Reischmann
Browse files
Options
Downloads
Patches
Plain Diff
Introducing process_manager and central call to process_course
parent
6365eea8
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
classes/cleanup_processor.php
+28
-17
28 additions, 17 deletions
classes/cleanup_processor.php
classes/entity/process.php
+67
-0
67 additions, 0 deletions
classes/entity/process.php
classes/manager/process_manager.php
+80
-0
80 additions, 0 deletions
classes/manager/process_manager.php
with
175 additions
and
17 deletions
classes/cleanup_processor.php
+
28
−
17
View file @
da4ca9a9
...
...
@@ -24,8 +24,11 @@
namespace
tool_cleanupcourses
;
use
tool_cleanupcourses\entity\trigger_subplugin
;
use
tool_cleanupcourses\manager\process_manager
;
use
tool_cleanupcourses\manager\step_manager
;
use
tool_cleanupcourses\manager\trigger_manager
;
use
tool_cleanupcourses\manager\lib_manager
;
use
tool_cleanupcourses\response\step_response
;
use
tool_cleanupcourses\response\trigger_response
;
...
...
@@ -56,7 +59,7 @@ class cleanup_processor {
break
;
}
if
(
$response
===
trigger_response
::
trigger
())
{
$this
->
trigger_course
(
$course
->
id
,
trigger_subplugin
::
from_record
(
$trigger
));
process_manager
::
create_process
(
$course
->
id
,
trigger_subplugin
::
from_record
(
$trigger
));
break
;
}
}
...
...
@@ -64,12 +67,35 @@ class cleanup_processor {
}
}
/**
* Calls the process_course() method of each step submodule currently responsible for a given course.
*/
public
function
process_courses
()
{
foreach
(
process_manager
::
get_processes
()
as
$process
)
{
while
(
true
)
{
$step
=
step_manager
::
get_subplugin_by_instance_id
(
$process
->
stepid
);
$lib
=
lib_manager
::
get_step_lib
(
$step
->
subpluginname
);
$course
=
get_course
(
$process
->
courseid
);
$result
=
$lib
->
process_course
(
$course
);
if
(
$result
===
step_response
::
waiting
())
{
break
;
}
elseif
(
$result
===
step_response
::
proceed
())
{
process_manager
::
proceed_process
(
$process
);
}
elseif
(
$result
===
step_response
::
rollback
()){
// TODO: Implement Rollback!
break
;
}
}
}
}
/**
* Returns a record set with all relevant courses.
* Relevant means that there is currently no cleanup process running for this course.
* @return \moodle_recordset with relevant courses.
*/
p
ublic
function
get_course_recordset
()
{
p
rivate
function
get_course_recordset
()
{
global
$DB
;
$sql
=
'SELECT {course}.* from {course} '
.
'left join {tool_cleanupcourses_process} '
.
...
...
@@ -78,19 +104,4 @@ class cleanup_processor {
return
$DB
->
get_recordset_sql
(
$sql
);
}
/**
* Creates a process for the course which is at the respective step the trigger is followed by.
* @param int $courseid id of the course
* @param trigger_subplugin $trigger
*/
private
function
trigger_course
(
$courseid
,
$trigger
)
{
global
$DB
;
if
(
$trigger
->
followedby
!==
null
)
{
$record
=
new
\stdClass
();
$record
->
courseid
=
$courseid
;
$record
->
stepid
=
$trigger
->
followedby
;
$DB
->
insert_record
(
'tool_cleanupcourses_process'
,
$record
);
}
}
}
This diff is collapsed.
Click to expand it.
classes/entity/process.php
0 → 100644
+
67
−
0
View file @
da4ca9a9
<?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/>.
namespace
tool_cleanupcourses\entity
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* Cleanup Course Process class
*
* @package tool_cleanupcourses
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
process
{
/** int id of the process*/
public
$id
;
/** int id of the step instance*/
public
$stepid
;
/** int id of the course*/
public
$courseid
;
public
function
__construct
(
$id
,
$stepid
,
$courseid
)
{
$this
->
id
=
$id
;
$this
->
stepid
=
$stepid
;
$this
->
courseid
=
$courseid
;
}
/**
* Creates a Cleanup Course Process from a db record.
* @param $record
* @return process
*/
public
static
function
from_record
(
$record
)
{
if
(
!
object_property_exists
(
$record
,
'id'
))
{
return
null
;
}
if
(
!
object_property_exists
(
$record
,
'stepid'
))
{
return
null
;
}
if
(
!
object_property_exists
(
$record
,
'courseid'
))
{
return
null
;
}
$instance
=
new
self
(
$record
->
id
,
$record
->
stepid
,
$record
->
courseid
);
return
$instance
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
classes/manager/process_manager.php
0 → 100644
+
80
−
0
View file @
da4ca9a9
<?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 for Cleanup Course Processes
*
* @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
tool_cleanupcourses
\entity\process
;
use
tool_cleanupcourses\entity\trigger_subplugin
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
class
process_manager
{
/**
* Creates a process for the course which is at the respective step the trigger is followed by.
* @param int $courseid id of the course
* @param trigger_subplugin $trigger
*/
public
static
function
create_process
(
$courseid
,
$trigger
)
{
global
$DB
;
if
(
$trigger
->
followedby
!==
null
)
{
$record
=
new
\stdClass
();
$record
->
courseid
=
$courseid
;
$record
->
stepid
=
$trigger
->
followedby
;
$DB
->
insert_record
(
'tool_cleanupcourses_process'
,
$record
);
}
}
/**
* Creates a process for the course which is at the respective step the trigger is followed by.
* @return process[]
*/
public
static
function
get_processes
()
{
global
$DB
;
$records
=
$DB
->
get_records
(
'tool_cleanupcourses_process'
);
$processes
=
array
();
foreach
(
$records
as
$record
)
{
$processes
[]
=
process
::
from_record
(
$record
);
}
return
$processes
;
}
/**
* Proceeds the process to the next step.
* @param process $process
*/
public
static
function
proceed_process
(
&
$process
)
{
global
$DB
;
$step
=
step_manager
::
get_step_instance
(
$process
->
stepid
);
if
(
$step
->
followedby
!==
null
)
{
$process
->
stepid
=
$step
->
followedby
;
$DB
->
update_record
(
'tool_cleanupcourses_process'
,
$process
);
}
else
{
if
(
get_course
(
$process
->
courseid
))
{
debugging
(
'Course should no longer exist!!!!'
);
}
$DB
->
delete_records
(
'tool_cleanupcourses_process'
,
$process
);
}
}
}
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