1515use Magento \Backend \App \Action \Context ;
1616use Cloudinary \Asset \Media ;
1717use Cloudinary \Cloudinary \Core \Image \Transformation ;
18+ use Psr \Log \LoggerInterface ;
1819
1920class UpdateAdminImage extends Action
2021{
@@ -28,6 +29,7 @@ class UpdateAdminImage extends Action
2829 protected $ resultFactory ;
2930 protected $ configurationBuilder ;
3031 protected $ transformation ;
32+ protected $ logger ;
3133 private $ _authorised ;
3234
3335
@@ -41,6 +43,7 @@ class UpdateAdminImage extends Action
4143 * @param ResultRawFactory $resultFactory
4244 * @param ConfigurationBuilder $configurationBuilder
4345 * @param Transformation $transformation
46+ * @param LoggerInterface $logger
4447 */
4548 public function __construct (
4649 Context $ context ,
@@ -51,7 +54,8 @@ public function __construct(
5154 UrlInterface $ urlInterface ,
5255 ResultRawFactory $ resultFactory ,
5356 ConfigurationBuilder $ configurationBuilder ,
54- Transformation $ transformation
57+ Transformation $ transformation ,
58+ LoggerInterface $ logger
5559 ) {
5660 parent ::__construct ($ context );
5761 $ this ->imageFactory = $ imageFactory ;
@@ -62,6 +66,7 @@ public function __construct(
6266 $ this ->resultFactory = $ resultFactory ;
6367 $ this ->configurationBuilder = $ configurationBuilder ;
6468 $ this ->transformation = $ transformation ;
69+ $ this ->logger = $ logger ;
6570 }
6671
6772 protected function _isAllowed ()
@@ -89,6 +94,7 @@ public function execute()
8994
9095 if ($ this ->configuration ->isEnabled ()) {
9196 try {
97+
9298 // Validate URL
9399 if (!$ remoteImageUrl ) {
94100 throw new \InvalidArgumentException ('Missing remote_image parameter ' );
@@ -114,11 +120,13 @@ public function execute()
114120
115121 } catch (\Exception $ e ) {
116122 // Return original URL on error for graceful fallback
117- error_log (sprintf (
118- 'Cloudinary UpdateAdminImage error: %s for image: %s ' ,
119- $ e ->getMessage (),
120- $ remoteImageUrl
121- ));
123+ $ this ->logger ->error (
124+ 'Cloudinary UpdateAdminImage error: ' . $ e ->getMessage (),
125+ [
126+ 'image_url ' => $ remoteImageUrl ,
127+ 'exception ' => $ e
128+ ]
129+ );
122130 }
123131 }
124132
0 commit comments