Improve uploads/deletions

This commit is contained in:
René Preuß
2021-07-21 19:27:28 +02:00
parent d2767b326b
commit 53cff7d805
8 changed files with 170 additions and 62 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Bunny\Filesystem;
use Illuminate\Support\Str;
class Sort
{
public static function unique(&$directories): array
{
$relevant = [];
// sort all requested files
uksort($directories, function (string $a, string $b) {
$a = count(explode('/', $a));
$b = count(explode('/', $b));
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});
// filter all child files and directories
foreach ($directories as $path => $request) {
if (!Str::startsWith($path, array_keys($relevant))) {
$relevant[$path] = $request;
}
}
return $relevant;
}
private static function isParentDeleted(array $parents, string $file): bool
{
return Str::startsWith($file, $parents);
}
}