エラーの発生するプラグイン(.pl形式)があると、プラグインによる object_types の追加が処理されないことがある

Description

エラーが発生すると $mt->log が呼ばれ、その中で $mt->init_schema() されるためそこで schema が初期化されてしまい、その後で読み込まれるプラグインによる object_types が処理されない。

修正案

以下のような感じで修正できそう。

diff --git a/lib/MT.pm b/lib/MT.pm index 90bb81b16..30a4ce1a2 100644 --- a/lib/MT.pm +++ b/lib/MT.pm @@ -1405,23 +1405,6 @@ sub init_plugins { $timer->mark( "Loaded plugin " . $sig ) if $timer; if ($@) { $Plugins{$plugin_sig}{error} = $@; - - # Issue MT log within another eval block in the - # event that the plugin error is happening before - # the database has been initialized... - eval { - require MT::Log; - $mt->log( - { message => $mt->translate( - "Plugin error: [_1] [_2]", $plugin, - $Plugins{$plugin_sig}{error} - ), - class => 'system', - category => 'plugin', - level => MT::Log::ERROR() - } - ); - }; return; } else { @@ -1484,6 +1467,7 @@ sub init_plugins { } my @loaded_plugins; + my @errors; foreach my $PluginPath (@$PluginPaths) { my $plugin_lastdir = $PluginPath; $plugin_lastdir =~ s![\\/]$!!; @@ -1502,6 +1486,7 @@ sub init_plugins { if ($plugin_full_path =~ /\.pl$/) { my $obj = __load_plugin( $mt, $timer, $PluginSwitch, $use_plugins, $plugin_full_path, $plugin ); push @loaded_plugins, $obj if $obj; + push @errors, [$plugin_full_path, $Plugins{$plugin}{error}] if $Plugins{$plugin}{error}; } next; } @@ -1539,8 +1524,10 @@ sub init_plugins { = File::Spec->catfile( $plugin_full_path, $plugin ); if ( -f $plugin_file ) { - my $obj = __load_plugin( $mt, $timer, $PluginSwitch, $use_plugins, $plugin_file, $plugin_dir . '/' . $plugin ); + my $sig = $plugin_dir . '/' . $plugin; + my $obj = __load_plugin( $mt, $timer, $PluginSwitch, $use_plugins, $plugin_file, $sig ); push @loaded_plugins, $obj if $obj; + push @errors, [$plugin_full_path, $Plugins{$sig}{error}] if $Plugins{$sig}{error}; } } } @@ -1593,6 +1580,25 @@ sub init_plugins { $plugin->init_callbacks; } + # $mt->log calls init_schema internally, so $mt->log it must be called after $plugin->init_callbacks all plugins that do not cause errors + for my $error (@errors) { + # Issue MT log within another eval block in the + # event that the plugin error is happening before + # the database has been initialized... + eval { + require MT::Log; + $mt->log( + { message => $mt->translate( + "Plugin error: [_1] [_2]", @$error, + ), + class => 'system', + category => 'plugin', + level => MT::Log::ERROR() + } + ); + } or last; + } + # Reset the Text_filters hash in case it was preloaded by plugins by # calling all_text_filters (Markdown in particular does this). # Upon calling all_text_filters again, it will be properly loaded by

Environment

None

Checklists

None

Activity

Show:

Kenichi IshigakiJune 20, 2023 at 12:46 AM

ありがとうございます。マージしました。

Reiko SatoJune 20, 2023 at 12:36 AM


上記の手順通りの動作になる事を確認

Kenichi IshigakiJune 9, 2023 at 2:17 AM

https://github.com/movabletype/movabletype/pull/2654 で対応しました。以下の手順でご確認おねがいします。

  • 適当なMT環境を用意する

  • 以下のプラグインを plugins/Broken/Broken.pl として保存する

    package Broken; die "Broken"; 1;
  • https://github.com/movabletype/mt-plugin-MFAhttps://github.com/movabletype/mt-plugin-MFA-TOTP もREADMEの指示通りにインストールする(確実を期すなら PluginPath 環境変数で MFA 専用のプラグインディレクトリを追加して Broken プラグインよりも確実にあとに読み込まれるようにする)

  • MT にアクセスしてアップグレードを走らせる

  • MTF-TOTP プラグインが正しく動作することを確認する

Kenichi IshigakiJune 7, 2023 at 1:48 AM

ありがとうございます。https://github.com/movabletype/movabletype/pull/2654/commits/c19d62ca619a9e5658037daa328f4ec9e5fd3cad で該当行を削除しました。

Keita SugamaJune 7, 2023 at 1:38 AM

確認しました。概ね良さそうです。

一点、テスト中の下記の変数が未使用のようです。

https://github.com/movabletype/movabletype/pull/2654/files#diff-8d6651416997471ecd1f4df4f8f40e96fdbad7432d3f89608d6e38874fea257eR21

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Smart Checklist

Created April 17, 2023 at 6:40 AM
Updated June 20, 2023 at 12:46 AM
Resolved June 20, 2023 at 12:46 AM

Flag notifications