From 42d92d0c8dfe0c567c28f5bfdda129890fa4c2ec Mon Sep 17 00:00:00 2001
From: Yassine Doghri <yassine@doghri.fr>
Date: Sat, 29 Jan 2022 15:32:38 +0000
Subject: [PATCH] fix(housekeeping): replace the use of GLOB_BRACE with looping
 over file extensions

The GLOB_BRACE flag is not available on non GNU systems, such as Solaris or Alpine Linux.

fixes #154
---
 .../Admin/Controllers/SettingsController.php  | 56 +++++++++++--------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/modules/Admin/Controllers/SettingsController.php b/modules/Admin/Controllers/SettingsController.php
index 1f1355f026..90fc4d1049 100644
--- a/modules/Admin/Controllers/SettingsController.php
+++ b/modules/Admin/Controllers/SettingsController.php
@@ -116,17 +116,21 @@ class SettingsController extends BaseController
         helper('media');
 
         $allPodcasts = (new PodcastModel())->findAll();
+        $imageExt = ['jpg', 'png', 'webp'];
 
         foreach ($allPodcasts as $podcast) {
-            $podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{jpg,png,webp}"), GLOB_BRACE);
+            foreach ($imageExt as $ext) {
+                $podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{$ext}"));
 
-            if ($podcastImages) {
-                foreach ($podcastImages as $podcastImage) {
-                    if (is_file($podcastImage)) {
-                        unlink($podcastImage);
+                if ($podcastImages) {
+                    foreach ($podcastImages as $podcastImage) {
+                        if (is_file($podcastImage)) {
+                            unlink($podcastImage);
+                        }
                     }
                 }
             }
+
             $podcast->cover->saveSizes();
             if ($podcast->banner_id !== null) {
                 $podcast->banner->saveSizes();
@@ -139,11 +143,13 @@ class SettingsController extends BaseController
             }
         }
 
-        $personsImages = glob(media_path('/persons/*_*{jpg,png,webp}'), GLOB_BRACE);
-        if ($personsImages) {
-            foreach ($personsImages as $personsImage) {
-                if (is_file($personsImage)) {
-                    unlink($personsImage);
+        foreach ($imageExt as $ext) {
+            $personsImages = glob(media_path("/persons/*_*{$ext}"));
+            if ($personsImages) {
+                foreach ($personsImages as $personsImage) {
+                    if (is_file($personsImage)) {
+                        unlink($personsImage);
+                    }
                 }
             }
         }
@@ -176,27 +182,31 @@ class SettingsController extends BaseController
         helper('media');
 
         if ($this->request->getPost('rewrite_media') === 'yes') {
-
+            $imageExt = ['jpg', 'png', 'webp'];
             // Delete all podcast image sizes to recreate them
             $allPodcasts = (new PodcastModel())->findAll();
             foreach ($allPodcasts as $podcast) {
-                $podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{jpg,png,webp}"), GLOB_BRACE);
-
-                if ($podcastImages) {
-                    foreach ($podcastImages as $podcastImage) {
-                        if (is_file($podcastImage)) {
-                            unlink($podcastImage);
+                foreach ($imageExt as $ext) {
+                    $podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{$ext}"));
+
+                    if ($podcastImages) {
+                        foreach ($podcastImages as $podcastImage) {
+                            if (is_file($podcastImage)) {
+                                unlink($podcastImage);
+                            }
                         }
                     }
                 }
             }
 
             // Delete all person image sizes to recreate them
-            $personsImages = glob(media_path('/persons/*_*{jpg,png,webp}'), GLOB_BRACE);
-            if ($personsImages) {
-                foreach ($personsImages as $personsImage) {
-                    if (is_file($personsImage)) {
-                        unlink($personsImage);
+            foreach ($imageExt as $ext) {
+                $personsImages = glob(media_path("/persons/*_*{$ext}"));
+                if ($personsImages) {
+                    foreach ($personsImages as $personsImage) {
+                        if (is_file($personsImage)) {
+                            unlink($personsImage);
+                        }
                     }
                 }
             }
@@ -207,7 +217,7 @@ class SettingsController extends BaseController
                     if (str_ends_with($image->file_path, 'banner.jpg') || str_ends_with(
                         $image->file_path,
                         'banner.png'
-                    )) {
+                    ) || str_ends_with($image->file_path, 'banner.jpeg')) {
                         $image->sizes = config('Images')
                             ->podcastBannerSizes;
                     } else {
-- 
GitLab