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
This commit is contained in:
parent
ce8c96b66f
commit
dce3931f20
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue