Préparer la version 1.0.0-rc.4
This commit is contained in:
parent
0a482afe9d
commit
6e3beea211
38 changed files with 388 additions and 56 deletions
|
|
@ -21,12 +21,13 @@ final class PrivateMediaService
|
|||
return dirname(__DIR__, 2) . '/public/media/animals/' . $animalId;
|
||||
}
|
||||
|
||||
public static function ensure(string $dir): void
|
||||
public static function ensure(string $dir, bool $public = false): void
|
||||
{
|
||||
if (!is_dir($dir) && !mkdir($dir, 0700, true) && !is_dir($dir)) {
|
||||
$mode = $public ? 0755 : 0700;
|
||||
if (!is_dir($dir) && !mkdir($dir, $mode, true) && !is_dir($dir)) {
|
||||
throw new RuntimeException(t('service.image.directory_failed'));
|
||||
}
|
||||
@chmod($dir, 0700);
|
||||
@chmod($dir, $mode);
|
||||
}
|
||||
|
||||
public static function moveVisibility(int $animalId, string $filename, bool $toPublic): void
|
||||
|
|
@ -45,7 +46,7 @@ final class PrivateMediaService
|
|||
}
|
||||
throw new RuntimeException(t('service.private_media.not_found'));
|
||||
}
|
||||
self::ensure($to);
|
||||
self::ensure($to, $toPublic);
|
||||
if (!rename($source, $target)) {
|
||||
throw new RuntimeException(t('service.private_media.move_failed'));
|
||||
}
|
||||
|
|
@ -55,6 +56,19 @@ final class PrivateMediaService
|
|||
public static function migrateLegacy(): void
|
||||
{
|
||||
$db = DB::pdo();
|
||||
$public = $db
|
||||
->query('SELECT animal_id,filename FROM animal_photos WHERE is_public=1')
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($public as $row) {
|
||||
$dir = self::publicDir((int) $row['animal_id']);
|
||||
if (is_dir($dir)) {
|
||||
@chmod($dir, 0755);
|
||||
}
|
||||
$file = $dir . '/' . basename((string) $row['filename']);
|
||||
if (is_file($file)) {
|
||||
@chmod($file, 0644);
|
||||
}
|
||||
}
|
||||
$private = $db
|
||||
->query('SELECT animal_id,filename FROM animal_photos WHERE is_public=0')
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
|
|
|||
Loading…
Reference in a new issue