Upgrade to 3.7.1

This commit is contained in:
Bastian Allgeier
2022-07-12 13:33:21 +02:00
parent 7931eb5e47
commit 1ad1eaf387
377 changed files with 63981 additions and 63824 deletions

View File

@@ -19,62 +19,62 @@ use Kirby\Http\Response;
*/
class PluginAssets
{
/**
* Clean old/deprecated assets on every resolve
*
* @param string $pluginName
* @return void
*/
public static function clean(string $pluginName): void
{
if ($plugin = App::instance()->plugin($pluginName)) {
$root = $plugin->root() . '/assets';
$media = $plugin->mediaRoot();
$assets = Dir::index($media, true);
/**
* Clean old/deprecated assets on every resolve
*
* @param string $pluginName
* @return void
*/
public static function clean(string $pluginName): void
{
if ($plugin = App::instance()->plugin($pluginName)) {
$root = $plugin->root() . '/assets';
$media = $plugin->mediaRoot();
$assets = Dir::index($media, true);
foreach ($assets as $asset) {
$original = $root . '/' . $asset;
foreach ($assets as $asset) {
$original = $root . '/' . $asset;
if (file_exists($original) === false) {
$assetRoot = $media . '/' . $asset;
if (file_exists($original) === false) {
$assetRoot = $media . '/' . $asset;
if (is_file($assetRoot) === true) {
F::remove($assetRoot);
} else {
Dir::remove($assetRoot);
}
}
}
}
}
if (is_file($assetRoot) === true) {
F::remove($assetRoot);
} else {
Dir::remove($assetRoot);
}
}
}
}
}
/**
* Create a symlink for a plugin asset and
* return the public URL
*
* @param string $pluginName
* @param string $filename
* @return \Kirby\Cms\Response|null
*/
public static function resolve(string $pluginName, string $filename)
{
if ($plugin = App::instance()->plugin($pluginName)) {
$source = $plugin->root() . '/assets/' . $filename;
/**
* Create a symlink for a plugin asset and
* return the public URL
*
* @param string $pluginName
* @param string $filename
* @return \Kirby\Cms\Response|null
*/
public static function resolve(string $pluginName, string $filename)
{
if ($plugin = App::instance()->plugin($pluginName)) {
$source = $plugin->root() . '/assets/' . $filename;
if (F::exists($source, $plugin->root()) === true) {
// do some spring cleaning for older files
static::clean($pluginName);
if (F::exists($source, $plugin->root()) === true) {
// do some spring cleaning for older files
static::clean($pluginName);
$target = $plugin->mediaRoot() . '/' . $filename;
$target = $plugin->mediaRoot() . '/' . $filename;
// create a symlink if possible
F::link($source, $target, 'symlink');
// create a symlink if possible
F::link($source, $target, 'symlink');
// return the file response
return Response::file($source);
}
}
// return the file response
return Response::file($source);
}
}
return null;
}
return null;
}
}