parent
2441d5f556
commit
17c494e5f9
|
@ -134,6 +134,12 @@ class MigrateGoogleTakeout extends Command
|
||||||
|
|
||||||
protected function migrateFolder(Folder $folder): void
|
protected function migrateFolder(Folder $folder): void
|
||||||
{
|
{
|
||||||
|
// Check for .nomedia
|
||||||
|
if ($folder->nodeExists('.nomedia')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all nodes in this folder
|
||||||
$nodes = $folder->getDirectoryListing();
|
$nodes = $folder->getDirectoryListing();
|
||||||
$path = $folder->getPath();
|
$path = $folder->getPath();
|
||||||
$this->output->writeln("Scanning folder {$path}");
|
$this->output->writeln("Scanning folder {$path}");
|
||||||
|
@ -229,9 +235,7 @@ class MigrateGoogleTakeout extends Command
|
||||||
|
|
||||||
// Write EXIF metadata
|
// Write EXIF metadata
|
||||||
try {
|
try {
|
||||||
$localPath = $file->getStorage()->getLocalFile($file->getInternalPath());
|
Exif::setFileExif($file, $txf);
|
||||||
Exif::setExif($localPath, $txf);
|
|
||||||
$file->touch();
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->output->writeln("<error>Error while writing EXIF metadata for {$path}: {$e->getMessage()}</error>");
|
$this->output->writeln("<error>Error while writing EXIF metadata for {$path}: {$e->getMessage()}</error>");
|
||||||
|
|
||||||
|
|
|
@ -250,23 +250,12 @@ class ImageController extends ApiBase
|
||||||
return new JSONResponse(['message' => "Cannot edit file {$name} (blacklisted type {$mime})"], Http::STATUS_PRECONDITION_FAILED);
|
return new JSONResponse(['message' => "Cannot edit file {$name} (blacklisted type {$mime})"], Http::STATUS_PRECONDITION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get original file from body
|
|
||||||
$path = $file->getStorage()->getLocalFile($file->getInternalPath());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Exif::setExif($path, $raw);
|
Exif::setFileExif($file, $raw);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
|
return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update remote file if not local
|
|
||||||
if (!$file->getStorage()->isLocal()) {
|
|
||||||
$file->putContent(fopen($path, 'r')); // closes the handler
|
|
||||||
}
|
|
||||||
|
|
||||||
// Touch the file, triggering a reprocess through the hook
|
|
||||||
$file->touch();
|
|
||||||
|
|
||||||
return new JSONResponse([], Http::STATUS_OK);
|
return new JSONResponse([], Http::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
lib/Exif.php
19
lib/Exif.php
|
@ -261,7 +261,7 @@ class Exif
|
||||||
*
|
*
|
||||||
* @throws \Exception on failure
|
* @throws \Exception on failure
|
||||||
*/
|
*/
|
||||||
public static function setExif(string &$path, array &$data)
|
public static function setExif(string $path, array $data)
|
||||||
{
|
{
|
||||||
$data['SourceFile'] = $path;
|
$data['SourceFile'] = $path;
|
||||||
$raw = json_encode([$data]);
|
$raw = json_encode([$data]);
|
||||||
|
@ -286,6 +286,23 @@ class Exif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function setFileExif(File $file, array $data)
|
||||||
|
{
|
||||||
|
// Get path to local file so we can skip reading
|
||||||
|
$path = $file->getStorage()->getLocalFile($file->getInternalPath());
|
||||||
|
|
||||||
|
// Set exif data
|
||||||
|
self::setExif($path, $data);
|
||||||
|
|
||||||
|
// Update remote file if not local
|
||||||
|
if (!$file->getStorage()->isLocal()) {
|
||||||
|
$file->putContent(fopen($path, 'r')); // closes the handler
|
||||||
|
}
|
||||||
|
|
||||||
|
// Touch the file, triggering a reprocess through the hook
|
||||||
|
$file->touch();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getBinaryExifProp(string $path, string $prop)
|
public static function getBinaryExifProp(string $path, string $prop)
|
||||||
{
|
{
|
||||||
$pipes = [];
|
$pipes = [];
|
||||||
|
|
Loading…
Reference in New Issue