From 140fc09851b60752d5e81f278e422a990b5b74a0 Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Mon, 22 Feb 2021 20:30:04 +0530 Subject: [PATCH] Add error handler on resizing image and prevent hard fail --- CRM/Mosaico/Utils.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/CRM/Mosaico/Utils.php b/CRM/Mosaico/Utils.php index 3159aedd6..1a2ca1ae2 100644 --- a/CRM/Mosaico/Utils.php +++ b/CRM/Mosaico/Utils.php @@ -274,14 +274,21 @@ public static function processUpload() { $size = filesize($file_path); $thumbnail_path = $config['BASE_DIR'] . $config[ 'THUMBNAILS_DIR' ] . $file_name; - Civi::service('mosaico_graphics')->createResizedImage($file_path, $thumbnail_path, $config['THUMBNAIL_WIDTH'], $config['THUMBNAIL_HEIGHT']); - - $file = [ - "name" => $file_name, - "url" => $config['BASE_URL'] . $config['UPLOADS_DIR'] . $file_name, - "size" => $size, - "thumbnailUrl" => $config['BASE_URL'] . $config['THUMBNAILS_URL'] . $file_name, - ]; + try { + Civi::service('mosaico_graphics')->createResizedImage($file_path, $thumbnail_path, $config['THUMBNAIL_WIDTH'], $config['THUMBNAIL_HEIGHT']); + $file = [ + "name" => $file_name, + "url" => $config['BASE_URL'] . $config['UPLOADS_DIR'] . $file_name, + "size" => $size, + "thumbnailUrl" => $config['BASE_URL'] . $config['THUMBNAILS_URL'] . $file_name, + ]; + } + catch (\Exception $e) { + CRM_Core_Error::debug_log_message($e->getMessage()); + $file = [ + 'error' => $e->getMessage(), + ]; + } $files[] = $file; }