Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM: Cache-Directory kann programmatisch geändert werden #5236

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions redaxo/src/addons/media_manager/lib/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class rex_media_manager
/** @var bool */
private $notFound = false;

/** @var string|null */
private static $cacheDirectory;

/** @var list<class-string<rex_effect_abstract>> */
private static $effects = [];

Expand Down Expand Up @@ -175,6 +178,14 @@ public function effectsFromType($type)
return $effects;
}

/**
* Set base cache directory for generated images.
*/
public static function setCacheDirectory(string $path): void
{
self::$cacheDirectory = rtrim($path, '/\\').DIRECTORY_SEPARATOR;
}

/**
* @param string $path
*/
Expand Down Expand Up @@ -293,14 +304,18 @@ public static function deleteCacheByType($typeId)
*/
public static function deleteCache($filename = null, $type = null)
{
if (null === $filename) {
rex_file::delete(rex_path::addonCache('media_manager', 'types.cache'));
}

$filename = ($filename ?: '').'*';

if (!$type) {
$type = '*';
}

$counter = 0;
$folder = rex_path::addonCache('media_manager');
$folder = self::$cacheDirectory ?? rex_path::addonCache('media_manager');

$glob = glob($folder.$type.'/'.$filename, GLOB_NOSORT);
if ($glob) {
Expand Down Expand Up @@ -467,7 +482,7 @@ public static function init()

if ('' != $rexMediaManagerFile && '' != $rexMediaManagerType) {
$mediaPath = rex_path::media($rexMediaManagerFile);
$cachePath = rex_path::addonCache('media_manager');
$cachePath = self::$cacheDirectory ?? rex_path::addonCache('media_manager');

$media = new rex_managed_media($mediaPath);
$mediaManager = new self($media);
Expand Down