Club System
This commit is contained in:
26
app/Console/Commands/DeleteRejectedEntries.php
Normal file
26
app/Console/Commands/DeleteRejectedEntries.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Signature('entries:purge-rejected {--days=7}')]
|
||||
#[Description('Soft Delete rejected entries older than X days')]
|
||||
class DeleteRejectedEntries extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$days = (int) $this->option('days');
|
||||
$count = Entry::where('state', 'rejected')
|
||||
->where('rejected_at', '<', now()->subDays($days))
|
||||
->delete();
|
||||
|
||||
$this->info("Deleted {$count} entries");
|
||||
}
|
||||
}
|
||||
75
app/Console/Commands/ImportDatFile.php
Normal file
75
app/Console/Commands/ImportDatFile.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
#[Signature('hashes:import-dat {file}')]
|
||||
#[Description('Import a hashes DAT file like No-Intro/Redump')]
|
||||
class ImportDatFile extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$file = $this->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.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('entries', function (Blueprint $table) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::statement("ALTER TABLE entries MODIFY state ENUM('draft','pending','published','locked','rejected','hidden') NOT NULL DEFAULT 'draft'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('entries', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::connection('hashes')->create('dat_reference', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::connection('hashes')->dropIfExists('dat_reference');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::connection('hashes')->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');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user