@@ -115,23 +115,27 @@ public function downloadImages()
115
115
$ this ->_info ["iteration " ]++;
116
116
$ this ->log ('Iteration # ' . $ this ->_info ["iteration " ]);
117
117
$ this ->migrationTask ->setBatchCount ($ this ->_info ["iteration " ]);
118
- $ this ->saveInfo (array (
118
+ $ this ->saveInfo (
119
+ array (
119
120
"iteration " => $ this ->_info ["iteration " ],
120
121
"resources_count " => 0 ,
121
122
"resources_processed " => 0 ,
122
123
"resources_downloaded " => 0 ,
123
124
"resources_skipped " => 0 ,
124
125
"resources_failed " => 0 ,
125
- ));
126
+ )
127
+ );
126
128
127
129
$ response = $ this ->getResources ($ this ->_info ["next_cursor " ]);
128
130
$ response ->setResourcesCount (count ($ response ->getResources ()));
129
- $ this ->saveInfo (array (
131
+ $ this ->saveInfo (
132
+ array (
130
133
"next_cursor " => $ response ->getNextCursor (),
131
134
"more_expected " => ($ response ->getNextCursor ())? true : false ,
132
135
"resources_count " => $ this ->_info ["resources_count " ] + $ response ->getResourcesCount (),
133
136
"resources_count_total " => $ this ->_info ["resources_count_total " ] + $ response ->getResourcesCount (),
134
- ));
137
+ )
138
+ );
135
139
if ($ response ->getResourcesCount () > 0 ) {
136
140
$ this ->log ('Found ' . $ response ->getResourcesCount () . ' image(s) to sync on this round. ' . (($ response ->getNextCursor ()) ? '*More Rounds Expected* ' : '*Last Round* ' ));
137
141
foreach ($ response ->getResources () as $ i => &$ resource ) {
@@ -174,14 +178,16 @@ public function downloadImages()
174
178
$ res = Cloudinary_Cloudinary_Helper_Data::curlGetContents ($ remoteFileUrl );
175
179
if (!$ res || $ res ->getError () || empty (($ image = $ res ->getBody ()))) {
176
180
throw new Mage_Core_Exception (
177
- __ ('The preview image information is unavailable. Check your connection and try again. ' )
178
- );
181
+ __ ('The preview image information is unavailable. Check your connection and try again. ' )
182
+ );
179
183
}
184
+
180
185
$ this ->log ('=== [Processing] Saving... ' );
181
186
Mage::getSingleton ('core/file_storage_file ' )->saveFile (array ('filename ' => $ localFileName , 'content ' => $ image ), true );
182
187
if (!@file_exists ($ localFilePath )) {
183
188
throw new Mage_Core_Exception (__ ("Image not saved. " ));
184
189
}
190
+
185
191
$ this ->log ('=== [Processing] Saved. ' );
186
192
$ this ->saveInfo (array ("resources_downloaded " => $ this ->_info ["resources_downloaded " ]+1 , "resources_downloaded_total " => $ this ->_info ["resources_downloaded_total " ]+1 ));
187
193
}
@@ -228,13 +234,15 @@ public function downloadImages()
228
234
*/
229
235
private function getResources ($ nextCursor = null )
230
236
{
231
- $ response = $ this ->api ->resources (array (
237
+ $ response = $ this ->api ->resources (
238
+ array (
232
239
"resource_type " => 'image ' ,
233
240
"type " => "upload " ,
234
241
"prefix " => 'media ' . DIRECTORY_SEPARATOR ,
235
242
"max_results " => self ::API_REQUEST_MAX_RESULTS ,
236
243
"next_cursor " => $ nextCursor ,
237
- ));
244
+ )
245
+ );
238
246
$ this ->_rateLimitResetAt = $ response ->rate_limit_reset_at ;
239
247
$ this ->_rateLimitAllowed = $ response ->rate_limit_allowed ;
240
248
$ this ->_rateLimitRemaining = $ response ->rate_limit_remaining ;
@@ -255,6 +263,7 @@ private function log($message, $type = 'notice')
255
263
$ this ->logger ->notice ($ message );
256
264
break ;
257
265
}
266
+
258
267
return $ this ;
259
268
}
260
269
@@ -268,7 +277,7 @@ private function log($message, $type = 'notice')
268
277
private function validateRemoteFileExtensions ($ filePath )
269
278
{
270
279
$ extension = pathinfo ($ filePath , PATHINFO_EXTENSION );
271
- if (!in_array ($ extension , [ 'jpg ' ,'jpeg ' ,'gif ' ,'png ' ] )) {
280
+ if (!in_array ($ extension , array ( 'jpg ' ,'jpeg ' ,'gif ' ,'png ' ) )) {
272
281
throw new Mage_Core_Exception (__ ('Disallowed file type. ' ));
273
282
}
274
283
}
@@ -290,13 +299,14 @@ private function getCredentialsFromEnvironmentVariable($environmentVariable)
290
299
if (Cloudinary::config_get ('private_cdn ' )) {
291
300
$ credentials ["private_cdn " ] = Cloudinary::config_get ('private_cdn ' );
292
301
}
302
+
293
303
return $ credentials ;
294
304
} catch (\Exception $ e ) {
295
305
throw new Mage_Core_Exception (__ (self ::CREDENTIALS_CHECK_FAILED ));
296
306
}
297
307
}
298
308
299
- private function saveInfo (array $ info = [] )
309
+ private function saveInfo (array $ info = array () )
300
310
{
301
311
$ this ->_info = array_merge ($ this ->_info , $ info );
302
312
$ this ->migrationTask ->setInfo ($ this ->_info )->save ();
0 commit comments