From e487f075c4ec8ea6121af9414ec666fe30eea314 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Thu, 26 Feb 2015 23:08:38 +1100 Subject: [PATCH] Fixes issue in CodeParser where it tries to use a class that doesn't exist Adds context to filterFields() model override --- modules/backend/widgets/Form.php | 2 +- modules/cms/classes/CodeParser.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 2c97819ba..14a720ba2 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -846,7 +846,7 @@ class Form extends WidgetBase protected function applyFiltersFromModel() { if (method_exists($this->model, 'filterFields')) { - $this->model->filterFields((object) $this->fields); + $this->model->filterFields((object) $this->fields, $this->getContext()); } } diff --git a/modules/cms/classes/CodeParser.php b/modules/cms/classes/CodeParser.php index a566d4972..f381e2f37 100644 --- a/modules/cms/classes/CodeParser.php +++ b/modules/cms/classes/CodeParser.php @@ -155,9 +155,31 @@ class CodeParser require_once $data['filePath']; } + if (!class_exists($className) && ($data = $this->handleCorruptCache())) { + $className = $data['className']; + } + return new $className($page, $layout, $controller); } + /** + * In some rare cases the cache file will not contain the class + * name we expect. When this happens, destroy the corrupt file, + * flush the request cache, and repeat the cycle. + * @return void + */ + protected function handleCorruptCache() + { + $path = $this->getFilePath(); + if (File::isFile($path)) { + File::delete($path); + } + + unset(self::$cache[$this->filePath]); + + return $this->parse(); + } + /** * Evaluates PHP content in order to detect syntax errors. * The method handles PHP errors and throws exceptions.