diff --git a/app/Console/Commands/DeleteRejectedEntries.php b/app/Console/Commands/DeleteRejectedEntries.php new file mode 100644 index 0000000..c65582f --- /dev/null +++ b/app/Console/Commands/DeleteRejectedEntries.php @@ -0,0 +1,26 @@ +option('days'); + $count = Entry::where('state', 'rejected') + ->where('rejected_at', '<', now()->subDays($days)) + ->delete(); + + $this->info("Deleted {$count} entries"); + } +} diff --git a/app/Console/Commands/ImportDatFile.php b/app/Console/Commands/ImportDatFile.php new file mode 100644 index 0000000..dc7a32c --- /dev/null +++ b/app/Console/Commands/ImportDatFile.php @@ -0,0 +1,75 @@ +argument('file'); + + if(!file_exists($file)) { + $this->error('File not found'); + return; + } + + $reader = new \XMLReader(); + $reader->open($file); + + $this->info("Importing..."); + + $count = 0; + $insertBuffer = []; + $datReferenceId = null; + + while ($reader->read()) { + if($reader->nodeType == \XMLReader::ELEMENT) { + if( $reader->name == 'header' ){ + $node = new \SimpleXMLElement($reader->readOuterXml()); + $name = (string) ($node->name . ' v.' . $node->version . ' (' . $node->homepage . ')'); + DB::connection('hashes')->table('dat_reference')->insert([['name' => $name ]]); + $datReferenceId = DB::connection('hashes')->table('dat_reference')->where('name', $name)->value('id'); + } + + if( $reader->name == 'game' ){ + if( !$datReferenceId ){ + $this->error("No dat reference found"); + return; + } + $node = new \SimpleXMLElement($reader->readOuterXml()); + foreach ($node->rom as $rom) { + $insertBuffer[] = [ + 'filename' => $rom['name'], + 'crc32' => $rom['crc'], + 'sha1' => $rom['sha1'], + 'dat_reference_id' => $datReferenceId, + ]; + $count++; + + if( count($insertBuffer) >= 1000 ){ + DB::connection('hashes')->table('hashes')->insert($insertBuffer); + $insertBuffer = []; + } + } + } + } + } + + if( count($insertBuffer) >= 0 ){ + DB::connection('hashes')->table('hashes')->insert($insertBuffer); + } + + $reader->close(); + $this->info("{$count} ROMs hashes imported."); + } +} diff --git a/database/migrations/2026_05_27_192635_add_fields_for_queue_to_entries.php b/database/migrations/2026_05_27_192635_add_fields_for_queue_to_entries.php new file mode 100644 index 0000000..29469c5 --- /dev/null +++ b/database/migrations/2026_05_27_192635_add_fields_for_queue_to_entries.php @@ -0,0 +1,31 @@ +softDeletes(); + $table->text("staff_comment")->nullable()->after("state"); + $table->timestamp("rejected_at")->nullable()->after("staff_comment"); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('entries', function (Blueprint $table) { + $table->dropSoftDeletes(); + $table->dropColumn(['staff_comment', 'rejected_at']); + }); + } +}; diff --git a/database/migrations/2026_05_27_193235_add_rejected_state_to_entries.php b/database/migrations/2026_05_27_193235_add_rejected_state_to_entries.php new file mode 100644 index 0000000..c9ee39c --- /dev/null +++ b/database/migrations/2026_05_27_193235_add_rejected_state_to_entries.php @@ -0,0 +1,26 @@ +create('dat_reference', function (Blueprint $table) { + $table->id(); + $table->string('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::connection('hashes')->dropIfExists('dat_reference'); + } +}; diff --git a/database/migrations/hashes/2026_06_01_162839_create_hashes_table.php b/database/migrations/hashes/2026_06_01_162839_create_hashes_table.php new file mode 100644 index 0000000..10b8deb --- /dev/null +++ b/database/migrations/hashes/2026_06_01_162839_create_hashes_table.php @@ -0,0 +1,30 @@ +create('hashes', function (Blueprint $table) { + $table->id(); + $table->string('filename')->nullable(); + $table->string('crc32')->nullable()->index(); + $table->string('sha1')->nullable()->index(); + $table->foreignId('dat_reference_id')->constrained('dat_reference')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::connection('hashes')->dropIfExists('hashes'); + } +};