Commit 42d92d0c authored by Yassine Doghri's avatar Yassine Doghri
Browse files

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
parent f21ca576
Loading
Loading
Loading
Loading
Loading
+33 −23
Original line number Diff line number Diff line
@@ -116,9 +116,11 @@ 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) {
@@ -127,6 +129,8 @@ class SettingsController extends BaseController
                        }
                    }
                }
            }

            $podcast->cover->saveSizes();
            if ($podcast->banner_id !== null) {
                $podcast->banner->saveSizes();
@@ -139,7 +143,8 @@ class SettingsController extends BaseController
            }
        }

        $personsImages = glob(media_path('/persons/*_*{jpg,png,webp}'), GLOB_BRACE);
        foreach ($imageExt as $ext) {
            $personsImages = glob(media_path("/persons/*_*{$ext}"));
            if ($personsImages) {
                foreach ($personsImages as $personsImage) {
                    if (is_file($personsImage)) {
@@ -147,6 +152,7 @@ class SettingsController extends BaseController
                    }
                }
            }
        }

        $persons = (new PersonModel())->findAll();
        foreach ($persons as $person) {
@@ -176,11 +182,12 @@ 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);
                foreach ($imageExt as $ext) {
                    $podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{$ext}"));

                    if ($podcastImages) {
                        foreach ($podcastImages as $podcastImage) {
@@ -190,9 +197,11 @@ class SettingsController extends BaseController
                        }
                    }
                }
            }

            // Delete all person image sizes to recreate them
            $personsImages = glob(media_path('/persons/*_*{jpg,png,webp}'), GLOB_BRACE);
            foreach ($imageExt as $ext) {
                $personsImages = glob(media_path("/persons/*_*{$ext}"));
                if ($personsImages) {
                    foreach ($personsImages as $personsImage) {
                        if (is_file($personsImage)) {
@@ -200,6 +209,7 @@ class SettingsController extends BaseController
                        }
                    }
                }
            }

            $allImages = (new MediaModel('image'))->getAllOfType();
            foreach ($allImages as $image) {
@@ -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 {