From e534ffe8dd0868e8ebe342a84cfbb699f3064998 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Thu, 27 Jul 2017 11:26:08 +0200 Subject: [PATCH] :white_check_mark: Add logs & cloudinary in admin --- cloudinary.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cloudinary.php b/cloudinary.php index a16151b..fef999d 100644 --- a/cloudinary.php +++ b/cloudinary.php @@ -20,7 +20,7 @@ class CloudinaryPlugin extends Plugin */ public function onPluginsInitialized() { - if ($this->isAdmin()) { + if (!$this->isAdmin()) { $this->active = false; return; } @@ -43,10 +43,19 @@ class CloudinaryPlugin extends Plugin { $path = $event['image']; - $cloudinary_image = \Cloudinary\Uploader::upload($path); + try { - if (!empty($cloudinary_image)) { - file_put_contents($path, $cloudinary_image['secure_url']); + $cloudinary_image = \Cloudinary\Uploader::upload($path); + + if (!empty($cloudinary_image)) { + file_put_contents($path, $cloudinary_image['secure_url']); + } else { + $this->grav['log']->critical(sprintf('%s has failed its upload to Cloudinary', $path)); + } + + } catch (\Cloudinary\Error $e) { + $this->grav['log']->critical(sprintf('Cloudinary API error : %s', $e->getMessage())); } + } }