77namespace Burzum \FileStorage \Storage \Listener ;
88
99use Burzum \FileStorage \Storage \StorageUtils ;
10+ use Cake \Console \Shell ;
1011use Cake \Core \Configure ;
1112use Cake \Datasource \EntityInterface ;
13+ use Exception ;
14+ use RuntimeException ;
1215
1316/**
1417 * ImageProcessingTrait
@@ -84,7 +87,7 @@ public function imageProcessor(array $config = [], $renew = false) {
8487 */
8588 public function getImageVersionHash ($ model , $ version ) {
8689 if (empty ($ this ->_imageVersionHashes [$ model ][$ version ])) {
87- throw new \ RuntimeException (sprintf ('Version "%s" for identifier "%s" does not exist! ' , $ version , $ model ));
90+ throw new RuntimeException (sprintf ('Version "%s" for identifier "%s" does not exist! ' , $ version , $ model ));
8891 }
8992 return $ this ->_imageVersionHashes [$ model ][$ version ];
9093 }
@@ -99,11 +102,11 @@ public function getImageVersionHash($model, $version) {
99102 */
100103 protected function _checkImageVersions ($ identifier , array $ versions ) {
101104 if (!isset ($ this ->_imageVersions [$ identifier ])) {
102- throw new \ RuntimeException (sprintf ('No image version config found for identifier "%s"! ' , $ identifier ));
105+ throw new RuntimeException (sprintf ('No image version config found for identifier "%s"! ' , $ identifier ));
103106 }
104107 foreach ($ versions as $ version ) {
105108 if (!isset ($ this ->_imageVersions [$ identifier ][$ version ])) {
106- throw new \ RuntimeException (sprintf ('Invalid version "%s" for identifier "%s"! ' , $ identifier , $ version ));
109+ throw new RuntimeException (sprintf ('Invalid version "%s" for identifier "%s"! ' , $ identifier , $ version ));
107110 }
108111 }
109112 }
@@ -117,18 +120,27 @@ protected function _checkImageVersions($identifier, array $versions) {
117120 * @return array
118121 */
119122 public function createImageVersions (EntityInterface $ entity , array $ versions , array $ options = []) {
120- $ this ->_checkImageVersions ($ entity ->model , $ versions );
123+ $ this ->_checkImageVersions ($ entity ->get ( ' model ' ) , $ versions );
121124
122125 $ options += $ this ->_defaultOutput + [
123126 'overwrite ' => true
124127 ];
125128
126129 $ result = [];
127- $ storage = $ this ->storageAdapter ($ entity ->adapter );
128- foreach ($ this ->_imageVersions [$ entity ->model ] as $ version => $ operations ) {
130+ $ storage = $ this ->storageAdapter ($ entity ->get ('adapter ' ));
131+
132+ foreach ($ this ->_imageVersions [$ entity ->get ('model ' )] as $ version => $ operations ) {
129133 if (!in_array ($ version , $ versions )) {
134+ if ($ this instanceof Shell) {
135+ $ this ->warn (sprintf (
136+ 'Version `%s` for identifier `%s` not found ' ,
137+ $ version ,
138+ $ entity ->get ('model ' )
139+ ));
140+ }
130141 continue ;
131142 }
143+
132144 $ saveOptions = $ options + ['format ' => $ entity ->extension ];
133145 if (isset ($ operations ['_output ' ])) {
134146 $ saveOptions = $ operations ['_output ' ] + $ saveOptions ;
@@ -155,7 +167,7 @@ public function createImageVersions(EntityInterface $entity, array $versions, ar
155167 'path ' => $ path ,
156168 'hash ' => $ this ->getImageVersionHash ($ entity ->model , $ version )
157169 ];
158- } catch (\ Exception $ e ) {
170+ } catch (Exception $ e ) {
159171 $ result [$ version ] = [
160172 'status ' => 'error ' ,
161173 'error ' => $ e ->getMessage (),
@@ -207,7 +219,7 @@ public function removeImageVersions(EntityInterface $entity, array $versions, ar
207219 */
208220 public function getAllVersionsKeysForModel ($ identifier ) {
209221 if (!isset ($ this ->_imageVersions [$ identifier ])) {
210- throw new \ RuntimeException (sprintf ('No image config present for identifier "%s"! ' , $ identifier ));
222+ throw new RuntimeException (sprintf ('No image config present for identifier "%s"! ' , $ identifier ));
211223 }
212224 return array_keys ($ this ->_imageVersions [$ identifier ]);
213225 }
0 commit comments