Skip to content
Snippets Groups Projects
Commit 273af1ee authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Deprovision processor can now trigger for courses

parent 2ce278e9
Branches
Tags
No related merge requests found
......@@ -24,8 +24,6 @@
*/
namespace local_course_deprovision;
use local_course_deprovision\trigger\startdatedelay;
defined('MOODLE_INTERNAL') || die;
class deprovision_processor {
......@@ -43,15 +41,35 @@ class deprovision_processor {
$extendedclass = "local_course_deprovision\\trigger\\$class";
$triggerclasses[$class] = new $extendedclass();
}
$recordset = $DB->get_recordset_select('course', null);
$recordset = $DB->get_recordset_sql('SELECT {course}.* from {course} '.
'left join {local_coursedeprov_process} '.
'ON {course}.id = {local_coursedeprov_process}.courseid '.
'WHERE {local_coursedeprov_process}.courseid is null');
while ($recordset->valid()) {
$course = $recordset->current();
/* @var $trigger trigger\base */
/* @var $trigger trigger\base -> Implementation of the subplugin trigger interface */
foreach ($triggerclasses as $id => $trigger) {
$trigger->check_course($course);
$response = $trigger->check_course($course);
if ($response == TriggerResponse::next()) {
continue;
}
if ($response == TriggerResponse::exclude()) {
break;
}
if ($response == TriggerResponse::trigger()) {
$this->trigger_course($course->id);
}
}
$recordset->next();
}
}
private function trigger_course($courseid) {
global $DB;
$record = new \stdClass();
$record->courseid = $courseid;
$record->subplugin_id = 3;
$DB->insert_record('local_coursedeprov_process', $record);
}
}
......@@ -28,8 +28,7 @@ defined('MOODLE_INTERNAL') || die();
class SubpluginResponse {
const NOTTRIGGERED = 'nottriggered';
const TRIGGERED = 'triggered';
const PROCEED = 'proceed';
const WAITING = 'waiting';
private $value;
......@@ -43,23 +42,16 @@ class SubpluginResponse {
}
/**
* Creates a SubpluginResponse telling that the subplugin does not want to process the course.
* Creates a SubpluginResponse telling that the subplugin finished processing the course.
*/
public function nottriggered() {
return new SubpluginResponse(self::NOTTRIGGERED);
}
/**
* Creates a SubpluginResponse telling that the subplugin processed the course and marked it for further processing.
*/
public function triggered() {
return new SubpluginResponse(self::TRIGGERED);
public static function proceed() {
return new SubpluginResponse(self::PROCEED);
}
/**
* Creates a SubpluginResponse telling that the subplugin is still processing the course.
*/
public function waiting() {
public static function waiting() {
return new SubpluginResponse(self::WAITING);
}
......
<?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/>.
/**
* Possible Responses of a Trigger Subplugin
*
* @package local
* @subpackage course_deprovision
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_course_deprovision;
defined('MOODLE_INTERNAL') || die();
class TriggerResponse {
const NEXT = 'next';
const EXCLUDE = 'exclude';
const TRIGGER = 'trigger';
private $value;
/**
* Creates an instance of a TriggerResponse
* @param string $responsetype code of the response
*/
private function __construct($responsetype) {
$this->value = $responsetype;
}
/**
* Creates a TriggerResponse telling that the subplugin does not want to process the course.
* This means that the course can be passed to the next trigger.
* @return TriggerResponse
*/
public static function next() {
return new TriggerResponse(self::NEXT);
}
/**
* Creates a TriggerResponse telling that the subplugin wants to exlude the course from deprovision.
* @return TriggerResponse
*/
public static function exclude() {
return new TriggerResponse(self::EXCLUDE);
}
/**
* Creates a TriggerResponse telling that the subplugin wants to trigger the deprovision process for the course.
* @return TriggerResponse
*/
public static function trigger() {
return new TriggerResponse(self::TRIGGER);
}
}
......@@ -33,7 +33,7 @@ interface base {
/**
* Checks the course and returns a repsonse, which tells if the course should be further processed.
* @param $course object to be processed.
* @return SubpluginResponse
* @return TriggerResponse
*/
public function check_course($course);
......
......@@ -25,8 +25,11 @@
*/
namespace local_course_deprovision\trigger;
use local_course_deprovision\TriggerResponse;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../lib.php');
require_once(__DIR__.'/../../classes/triggerresponse.php');
/**
* Class which implements the basic methods necessary for a course deprovision trigger subplugin
......@@ -38,10 +41,10 @@ class startdatedelay implements base {
/**
* Checks the course and returns a repsonse, which tells if the course should be further processed.
* @param $course object to be processed.
* @return SubpluginResponse
* @return TriggerResponse
*/
public function check_course($course) {
return true;
return TriggerResponse::trigger();
}
}
......@@ -24,5 +24,5 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2017040901;
$plugin->version = 2017040904;
$plugin->component = 'local_course_deprovision';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment