<?php

declare(strict_types=1);

$file = dirname(__DIR__) . '/vendor/minifranske/fs-media-gallery/Classes/Controller/MediaAlbumController.php';

echo "Fix sending incorrect variable to Fluid template - 20260714\n\n";

if (file_exists($file)) {
    $content = file_get_contents($file);

    $oldLine = '\'mediaAlbum\' => $mediaAlbum,';
    $newLine = '\'mediaAlbum\' => $mediaAlbumObject,';

    if (strpos($content, $oldLine) !== false) {
        $content = str_replace($oldLine, $newLine, $content);
        file_put_contents($file, $content);
        echo "\n-> [SUCCESS] Patch fs_media_gallery applied!\n\n";
    } else {
        echo "\n-> [INFO] Patch fs_media_gallery not applied or row not found.\n\n";
    }
} else {
    echo "\n-> [ERROR] Unable to find fs-media-gallery file.\n\n";
}