Add logs & cloudinary in admin

This commit is contained in:
Clement Desmidt 2017-07-27 11:26:08 +02:00
parent fcfb0bde14
commit e534ffe8dd

View File

@ -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'];
try {
$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()));
}
}
}