Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/Jobs/exportThemes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Jobs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;

class exportThemes implements ShouldQueue
{
use Queueable;

/**
* Create a new job instance.
*/
public function __construct()
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{

Log::info('Exporting themes');

//create a backup of the database
$backupPath = base_path('database/themes.php');

$themes = DB::table('themes')->get()->map(function($theme) {
return (array) $theme;
})->toArray();

File::put($backupPath, "<?php\n\nreturn " . var_export($themes, true) . ";");


Log::info('Themes exported: ' . count($themes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@ public function up(): void
Schema::create('user_auth_provider', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('auth_provider_id')->constrained()->onDelete('cascade');
$table->string('provider_user_id'); // User ID from the external provider
$table->string('provider_email')->nullable(); // Email from the external provider
$table->text('access_token')->nullable(); // OAuth access token if needed
$table->text('refresh_token')->nullable(); // OAuth refresh token if needed
$table->timestamp('token_expires_at')->nullable(); // Token expiration timestamp
$table->json('provider_data')->nullable(); // Additional data from provider
$table->timestamps();

// Ensure a user can only link to a provider once
$table->unique(['user_id', 'auth_provider_id']);
// Ensure provider_user_id is unique per auth_provider_id
$table->unique(['auth_provider_id', 'provider_user_id']);
});
}

Expand All @@ -37,4 +31,4 @@ public function down(): void
{
Schema::dropIfExists('user_auth_provider');
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,32 @@ public function up(): void
$table->boolean('allow_registration')->default(false);
$table->timestamps();
});

Schema::table('user_auth_provider', function (Blueprint $table) {
$table->foreignId('auth_provider_id')->constrained()->onDelete('cascade');

// Ensure a user can only link to a provider once
$table->unique(['user_id', 'auth_provider_id']);
// Ensure provider_user_id is unique per auth_provider_id
$table->unique(['auth_provider_id', 'provider_user_id']);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('user_auth_provider', function (Blueprint $table) {

// Ensure a user can only link to a provider once
$table->dropUnique(['user_id', 'auth_provider_id']);
// Ensure provider_user_id is unique per auth_provider_id
$table->dropUnique(['auth_provider_id', 'provider_user_id']);

$table->dropConstrainedForeignId('auth_provider_id');
});

Schema::dropIfExists('auth_providers');
}
};
6 changes: 1 addition & 5 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ public function run(): void
{
$this->call([
SettingsSeeder::class,
ThemesSeeder::class,
]);

// load themes.sql from the root of the project
$sql = file_get_contents(base_path('themes.sql'));
//run the query, ignore errors
DB::unprepared($sql);
}
}
21 changes: 21 additions & 0 deletions database/seeders/ThemesSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;

class ThemesSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$themes = require __DIR__ . '/../themes.php';

DB::table('themes')->insertOrIgnore($themes);
}
}
147 changes: 147 additions & 0 deletions database/themes.php

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions routes/console.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Jobs\exportThemes;
use Illuminate\Support\Facades\Schedule;
use App\Jobs\cleanExpiredShares;
use App\Jobs\maintainDb;
Expand Down Expand Up @@ -51,3 +52,7 @@
Artisan::command('back-up-database', function () {
backUpDatabase::dispatch();
})->purpose('Back up the database');

Artisan::command('export-themes', function () {
exportThemes::dispatchSync();
})->purpose('Export themes');
Loading