Skip to content

Commit

Permalink
Merge pull request #37 from MadeHQ/fix-for-multiple-public-id-fields
Browse files Browse the repository at this point in the history
Fix for multiple public id fields
  • Loading branch information
oilee80 authored Feb 8, 2019
2 parents 5e7ffb1 + 16322de commit 77fd9f0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ SilverStripe\ORM\DatabaseAdmin:
File: MadeHQ\Cloudinary\Model\File
Image: MadeHQ\Cloudinary\Model\Image

SilverStripe\Assets\File:
extensions:
- MadeHQ\Cloudinary\Extensions\FileExtension

---
Name: silverstripecloudinary-assetadmin-campaigns
Expand Down
26 changes: 19 additions & 7 deletions src/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Control\{ Controller, Director, HTTPRequest, HTTPResponse };
use SilverStripe\Security\{ Permission, PermissionProvider };
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Versioned\Versioned;
Expand Down Expand Up @@ -156,6 +153,7 @@ public function sync(HTTPRequest $request)
} else {
$data = false;
}

}
}

Expand All @@ -166,14 +164,28 @@ public function sync(HTTPRequest $request)
]
]);
} catch (CloudinaryApiError $e) {
if (Director::isDev()) {
return $this->output([
'status' => 'error',
'description' => sprintf('Error occurred with the Cloudinary API: %s', $e->getMessage()),
'trace' => $e->getTrace(),
], 500);
}
return $this->output([
'status' => 'error',
'description' => sprintf('Error occurred with the Cloudinary API: %s', $e->getMessage()),
'description' => 'Error occurred with the Cloudinary API',
], 500);
} catch (\Exception $e) {
if (Director::isDev()) {
return $this->output([
'status' => 'error',
'description' => sprintf('Unhandled error occurred: %s', $e->getMessage()),
'trace' => $e->getTrace(),
], 500);
}
return $this->output([
'status' => 'error',
'description' => sprintf('Unhandled error occurred: %s', $e->getMessage()),
'description' => 'Unhandled error occurred',
], 500);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Extensions/FileExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace MadeHQ\Cloudinary\Extensions;

use SilverStripe\ORM\DataExtension;

class FileExtension extends DataExtension
{
private static $db = [
'PublicID' => 'Varchar(255)',
];

private static $indexes = [
'PublicID' => [
'type' => 'unique',
],
];
}
7 changes: 0 additions & 7 deletions src/Traits/CloudinaryFileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ trait CloudinaryFileTrait
{
private static $db = [
'LastUpdatedFromCloudinary' => 'DBDatetime',
'PublicID' => 'Varchar(255)',
'SecureURL' => 'Varchar(1000)',
'ResourceType' => 'Varchar',
'Description' => 'Text',
Expand All @@ -30,12 +29,6 @@ trait CloudinaryFileTrait
'RemoteData' => 'Text',
];

private static $indexes = [
'PublicID' => [
'type' => 'unique',
],
];

public static function getOneByPublicId($publicId)
{
return static::get_one(static::class, [
Expand Down

0 comments on commit 77fd9f0

Please sign in to comment.