From dce3931f20822850d40851c2a87fddda3984fa70 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Mon, 31 Aug 2020 14:18:53 +0800 Subject: [PATCH] Clean up uncustomised partials if they are no longer provided. An exception was being thrown in some instances if a partial had been added to the DB that was provided by a plugin that no longer exists, or had been disabled. This will remove any partials provided by non-existent plugins, only if they haven't been subsequently customised by the developer. Fixes https://github.com/octobercms/october/issues/5065 --- modules/system/models/MailPartial.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/system/models/MailPartial.php b/modules/system/models/MailPartial.php index ac1971690..5d003fcf0 100644 --- a/modules/system/models/MailPartial.php +++ b/modules/system/models/MailPartial.php @@ -72,14 +72,24 @@ class MailPartial extends Model */ public static function createPartials() { - $dbPartials = self::lists('code', 'code'); + $partials = MailManager::instance()->listRegisteredPartials(); + $dbPartials = self::lists('is_custom', 'code'); + $newPartials = array_diff_key($partials, $dbPartials); - $definitions = MailManager::instance()->listRegisteredPartials(); - foreach ($definitions as $code => $path) { - if (array_key_exists($code, $dbPartials)) { + /* + * Clean up non-customized partials + */ + foreach ($dbPartials as $code => $isCustom) { + if ($isCustom) { continue; } + if (!array_key_exists($code, $partials)) { + self::whereCode($code)->delete(); + } + } + + foreach ($newPartials as $code => $path) { $partial = new static; $partial->code = $code; $partial->is_custom = 0;