From 477ff83eadf4118e8a5531fff7a6b6043e824fd1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 7 Dec 2017 13:30:55 +0100 Subject: [locationinfo] Fix handling of invalid backends, remove dummy-backend in production --- .../locationinfo/inc/coursebackend.inc.php | 40 ++++++++++++++-------- .../coursebackend/coursebackend_davinci.inc.php | 3 ++ .../inc/coursebackend/coursebackend_dummy.inc.php | 2 ++ 3 files changed, 31 insertions(+), 14 deletions(-) (limited to 'modules-available/locationinfo/inc') diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php index bf3e2e1f..7162c885 100644 --- a/modules-available/locationinfo/inc/coursebackend.inc.php +++ b/modules-available/locationinfo/inc/coursebackend.inc.php @@ -47,17 +47,20 @@ abstract class CourseBackend foreach (glob(dirname(__FILE__) . '/coursebackend/coursebackend_*.inc.php', GLOB_NOSORT) as $file) { require_once $file; preg_match('#coursebackend_([^/\.]+)\.inc\.php$#i', $file, $out); - if (!class_exists('coursebackend_' . $out[1])) { - trigger_error("Backend type source unit $file doesn't seem to define class CourseBackend_{$out[1]}", E_USER_ERROR); + $className = 'CourseBackend_' . $out[1]; + if (!class_exists($className)) { + trigger_error("Backend type source unit $file doesn't seem to define class $className", E_USER_ERROR); } + if (!CONFIG_DEBUG && defined("$className::DEBUG") && constant("$className::DEBUG")) + continue; self::$backendTypes[$out[1]] = true; } } /** - * Get all known config module types. + * Get all known backend types. * - * @return array list of modules + * @return array list of backends */ public static function getList() { @@ -65,24 +68,30 @@ abstract class CourseBackend return array_keys(self::$backendTypes); } + public static function exists($backendType) + { + self::loadDb(); + return isset(self::$backendTypes[$backendType]); + } + /** - * Get fresh instance of ConfigModule subclass for given module type. + * Get fresh instance of CourseBackend subclass for given backend type. * - * @param string $moduleType name of module type - * @return \CourseBackend module instance + * @param string $backendType name of module type + * @return \CourseBackend|false module instance */ - public static function getInstance($moduleType) + public static function getInstance($backendType) { self::loadDb(); - if (!isset(self::$backendTypes[$moduleType])) { - error_log('Unknown module type: ' . $moduleType); + if (!isset(self::$backendTypes[$backendType])) { + error_log('Unknown module type: ' . $backendType); return false; } - if (!is_object(self::$backendTypes[$moduleType])) { - $class = "coursebackend_$moduleType"; - self::$backendTypes[$moduleType] = new $class; + if (!is_object(self::$backendTypes[$backendType])) { + $class = "coursebackend_$backendType"; + self::$backendTypes[$backendType] = new $class; } - return self::$backendTypes[$moduleType]; + return self::$backendTypes[$backendType]; } /** @@ -328,6 +337,9 @@ abstract class CourseBackend $xml = new SimpleXMLElement($cleanresponse); } catch (Exception $e) { $this->error = 'Could not parse reply as XML, got ' . get_class($e) . ': ' . $e->getMessage(); + if (CONFIG_DEBUG) { + error_log($cleanresponse); + } return false; } $array = json_decode(json_encode((array)$xml), true); diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php index fac3f296..8843e372 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php @@ -106,6 +106,9 @@ class CourseBackend_Davinci extends CourseBackend } $return = $this->xmlStringToArray($return); if ($return === false) { + if (CONFIG_DEBUG) { + error_log('Room was ' . $roomId); + } continue; } $lessons = $this->getArrayPath($return, '/Lessons/Lesson'); diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php index 24e01070..adff8b1b 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php @@ -4,6 +4,8 @@ class CourseBackend_Dummy extends CourseBackend { private $pw; + const DEBUG = true; + /** * uses json to setCredentials, the json must follow the form given in * getCredentials -- cgit v1.2.3-55-g7522