From 0848a19608d4deda3b1afe1dccfe2241d80a76e8 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 31 Jul 2010 12:20:23 +0000 Subject: [PATCH] MDL-23502 make sure there are not multiple instances of manual enrol plugin --- enrol/manual/lib.php | 19 ++++++++++++++++++- lib/enrollib.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 6af7d608b50..46f20e5cbca 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -145,13 +145,30 @@ class enrol_manual_plugin extends enrol_plugin { /** * Add new instance of enrol plugin with default settings. * @param object $course - * @return int id of new instance + * @return int id of new instance, null if can not be created */ public function add_default_instance($course) { $fields = array('status'=>$this->get_config('status'), 'enrolperiod'=>$this->get_config('enrolperiod', 0), 'roleid'=>$this->get_config('roleid', 0)); return $this->add_instance($course, $fields); } + /** + * Add new instance of enrol plugin. + * @param object $course + * @param array instance fields + * @return int id of new instance, null if can not be created + */ + public function add_instance($course, array $fields = NULL) { + global $DB; + + if ($DB->record_exists('enrol', array('courseid'=>$course->id, 'enrol'=>'manual'))) { + // only one instance allowed, sorry + return NULL; + } + + return parent::add_instance($course, $fields); + } + public function cron() { // TODO: deal with $CFG->longtimenosee } diff --git a/lib/enrollib.php b/lib/enrollib.php index 276bcadc020..1e2caf72435 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -1169,7 +1169,7 @@ abstract class enrol_plugin { * Add new instance of enrol plugin. * @param object $course * @param array instance fields - * @return int id of new instance + * @return int id of new instance, null if can not be created */ public function add_instance($course, array $fields = NULL) { global $DB;