□Ktai Entryで壊れた添付画像ファイルがあると処理が止まるのを回避
□Ktai Entryで壊れた添付画像ファイルがあると処理が止まるのを回避
WordPressを使っている人で外部からのメール投稿をするときに便利なKtaiEntryですが、ときどき写メを投稿しても投稿できないことがあって、気がつかなくていらいらすることがたまにある。
写メが投稿できない場合として、PHPのmemory_limitが足りないのかとかと思ったが、増やしても減らしてもたまに発生するのでおかしいなぁとあれこれ調べていたら、どうもKtai Entryそのものの処理が何かおかしいことがわかった。
> May 17 14:51:18 yebisu apache2: PHP Warning: imagecreatefromstring(): Empty string or invalid image in /home/liveon/html/wp-content/plugins/ktai-entry/inc/post.php on line 895
> May 17 14:51:18 yebisu apache2: PHP Fatal error: Call to undefined method KtaiEntry_Post::log_error() in /home/liveon/html/wp-content/plugins/ktai-entry/inc/post.php on line 801
添付画像を画像ファイルに変換できないときにはPHPはWarningレベルなのでいいのだけど、そのあとの処理で定義されていないlog_error()を呼ぼうとしてFatalになってしまっている。
あれこれするのも面倒なので、とりあえず池田さんが直してくれるまでの措置として、以下のようにlog_error()を呼ばないようにした。
> private function upload_images($rotations, $post_id = 0, $post_time) {
> if (count($this->contents->images) < 1) { > return array();
> }
> if (! function_exists('imagecreatefromstring')) {
> $this->log_error(__('GD not available.', 'ktai_entry_log'));
> return array();
> }
> $attachments = array();
> foreach ($this->contents->images as $count => $img) {
> if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) {
> $this->log_error(@$uploads['error']);
> return array();
> }
> $filename = $this->unique_filename($uploads['path'], $img['name'], $post_time);
> $new_file = $uploads['path'] . '/' . $filename;
> $this->base->debug_print(sprintf(__('Saving file: %s', 'ktai_entry_log'), $new_file));
> $result = $this->save_image($new_file, $img['s_type'], $img['body'], @$rotations[$count]);
> if (is_ke_error($result)) {
> // 2012.05.17 T.Kabu BUG?
> // $this->log_error($result->getMessage());
> return $attachments;
> }
こうすると、画像は投稿に添付されないけど、投稿そのものの処理は進むようになったからよしとしよう。
池田さん、改修してくれると嬉しいなー。
Pingback: Ktai EntryからWordPressへメール投稿できなくなったとき | どうにもならない経営者の息子