Skip to content

A self-hosted media server and file management system

ok data stays and is unique in order of uuid and then composite

aminnausin646bfe5846cb
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index 69895450..1f0a2c5f 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -15,7 +15,7 @@ use App\Models\Folder;
use App\Models\Metadata;
use App\Models\Series;
use App\Models\Video;
-
+use Illuminate\Support\Facades\DB;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Ramsey\Uuid\Uuid;
@@ -169,7 +169,12 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique
Folder::insert($folderTransactions);
Series::upsert($seriesTransactions, 'composite_id', ['folder_id']);
Video::insert($videoTransactions);
- Metadata::upsert($metadataTransactions, 'composite_id', ['video_id']);
+ // Metadata::upsert($metadataTransactions, ['composite_id', 'uuid'], ['video_id']);
+ // Iterate through the metadata transactions and call upsertMetadata
+ foreach ($metadataTransactions as $data) {
+ $this->upsertMetadata($data);
+ }
+
// // One day logging should be put in the database
@@ -503,4 +508,27 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique
// throw new Exception('Failed to create the temporary file with metadata.');
// }
// }
+
+
+
+ // Define the custom function to handle the upsert logic
+ function upsertMetadata($data)
+ {
+ // Attempt to update by UUID first
+ $metadata = DB::table('metadata')->where('uuid', $data['uuid'])->first();
+
+ if ($metadata) {
+ DB::table('metadata')->where('uuid', $data['uuid'])->update($data);
+ } else {
+ // If UUID not found, try to update by composite_id
+ $metadata = DB::table('metadata')->where('composite_id', $data['composite_id'])->first();
+
+ if ($metadata) {
+ DB::table('metadata')->where('composite_id', $data['composite_id'])->update($data);
+ } else {
+ // If neither found, insert a new record
+ DB::table('metadata')->insert($data);
+ }
+ }
+ }
}
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index 75091d95..1eff8186 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -62,10 +62,7 @@ class VerifyFiles implements ShouldQueue
$metadata = Metadata::where('uuid', $uuid)->orWhere('composite_id', $compositeId)->first();
if (!$metadata) {
- dump('Create metadata');
$metadata = Metadata::create(['uuid' => $uuid, 'composite_id' => $compositeId, 'video_id' => $video->id]);
- } else {
- dump($metadata->id);
}
if (is_null($metadata->uuid)) {
diff --git a/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php b/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php
index d00fe76e..562aa33d 100644
--- a/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php
+++ b/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php
@@ -12,7 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('videos', function (Blueprint $table) {
- $table->uuid('uuid')->after('folder_id')->nullable();
+ $table->uuid('uuid')->after('folder_id')->unique()->nullable();
});
}
diff --git a/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php b/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php
index 69807525..c3897fae 100644
--- a/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php
+++ b/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php
@@ -12,7 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('metadata', function (Blueprint $table) {
- $table->uuid('uuid')->after('composite_id')->nullable();
+ $table->uuid('uuid')->after('composite_id')->unique()->nullable();
});
}