mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
- enhanced setup:dev script
- refactored shared token creation
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Folder;
|
||||
use App\Models\Page;
|
||||
use App\Models\Share;
|
||||
use App\Services\SetupService;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
@@ -26,6 +28,8 @@ class SetupDevEnvironment extends Command
|
||||
*/
|
||||
protected $description = 'Set up development environment';
|
||||
|
||||
private $setup;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
@@ -35,7 +39,7 @@ class SetupDevEnvironment extends Command
|
||||
{
|
||||
parent::__construct();
|
||||
$this->faker = Faker\Factory::create();
|
||||
$this->setup = app()->make(SetupService::class);
|
||||
$this->setup = resolve(SetupService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,10 +54,21 @@ class SetupDevEnvironment extends Command
|
||||
$this->info('Creating system directories...');
|
||||
$this->setup->create_directories();
|
||||
|
||||
$this->info('Migrating Databases...');
|
||||
$this->migrate_and_generate();
|
||||
$this->store_data();
|
||||
$this->seed_default_content();
|
||||
|
||||
$this->info('Storing default settings and content...');
|
||||
$this->store_default_settings();
|
||||
$this->setup->seed_default_pages();
|
||||
$this->setup->seed_default_settings('Extended');
|
||||
|
||||
$this->info('Creating default admin...');
|
||||
$this->create_admin();
|
||||
|
||||
$this->info('Creating default admin content...');
|
||||
$this->create_admin_default_content();
|
||||
|
||||
$this->info('Clearing application cache...');
|
||||
$this->clear_cache();
|
||||
|
||||
$this->info('Everything is done, congratulations! 🥳🥳🥳');
|
||||
@@ -66,15 +81,15 @@ class SetupDevEnvironment extends Command
|
||||
{
|
||||
$user = User::forceCreate([
|
||||
'role' => 'admin',
|
||||
'email' => 'john@doe.com',
|
||||
'password' => Hash::make('secret'),
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'password' => Hash::make('vuefilemanager'),
|
||||
]);
|
||||
|
||||
$user
|
||||
->settings()
|
||||
->create([
|
||||
'storage_capacity' => 5,
|
||||
'name' => 'John Doe',
|
||||
'name' => 'Jane Doe',
|
||||
'address' => $this->faker->address,
|
||||
'state' => $this->faker->state,
|
||||
'city' => $this->faker->city,
|
||||
@@ -85,27 +100,167 @@ class SetupDevEnvironment extends Command
|
||||
]);
|
||||
|
||||
// Show user credentials
|
||||
$this->info('Default admin account created. Email: john@doe.com and Password: secret');
|
||||
$this->info('Default admin account created. Email: howdy@hi5ve.digital and Password: vuefilemanager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed default content to database
|
||||
* Create default admin content
|
||||
*/
|
||||
private function seed_default_content(): void
|
||||
private function create_admin_default_content(): void
|
||||
{
|
||||
collect(config('content.content'))
|
||||
->each(function ($content) {
|
||||
Setting::updateOrCreate($content);
|
||||
});
|
||||
$user = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
// 1.
|
||||
$shared_folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => 'Shared Folder',
|
||||
]);
|
||||
|
||||
Share::factory(Share::class)
|
||||
->create([
|
||||
'type' => 'folder',
|
||||
'item_id' => $shared_folder->id,
|
||||
'permission' => 'editor',
|
||||
'is_protected' => false,
|
||||
'password' => null,
|
||||
'expire_in' => null,
|
||||
]);
|
||||
|
||||
$peters_files = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $shared_folder->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Peter's Files",
|
||||
]);
|
||||
|
||||
// 2.
|
||||
$random_pics = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => 'Random Pics',
|
||||
]);
|
||||
|
||||
$nature = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $random_pics->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Nature",
|
||||
]);
|
||||
|
||||
$apartments = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $random_pics->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Apartments",
|
||||
]);
|
||||
|
||||
// 3.
|
||||
$playable_media = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => 'Playable Media',
|
||||
]);
|
||||
|
||||
$video = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $playable_media->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Video",
|
||||
]);
|
||||
|
||||
$audio = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $playable_media->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Audio",
|
||||
]);
|
||||
|
||||
// 4.
|
||||
$multi_level = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => 'Multi Level Folder',
|
||||
]);
|
||||
|
||||
$first_level = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $multi_level->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "First Level",
|
||||
]);
|
||||
|
||||
$second_level = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $first_level->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Second Level",
|
||||
]);
|
||||
|
||||
$third_level = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $second_level->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => "Third Level",
|
||||
]);
|
||||
|
||||
// 5.
|
||||
$documents = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => 'Documents',
|
||||
]);
|
||||
|
||||
Share::factory(Share::class)
|
||||
->create([
|
||||
'type' => 'folder',
|
||||
'item_id' => $documents->id,
|
||||
'permission' => 'editor',
|
||||
'is_protected' => false,
|
||||
'password' => null,
|
||||
'expire_in' => null,
|
||||
]);
|
||||
|
||||
// 6.
|
||||
$videohive = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
'name' => 'Videohive by MakingCG',
|
||||
]);
|
||||
|
||||
$user
|
||||
->favouriteFolders()
|
||||
->sync([
|
||||
$shared_folder->id,
|
||||
$random_pics->id,
|
||||
$documents->id,
|
||||
$peters_files->id,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store main app settings into database
|
||||
*/
|
||||
private function store_data(): void
|
||||
private function store_default_settings(): void
|
||||
{
|
||||
// Get options
|
||||
$settings = collect([
|
||||
collect([
|
||||
[
|
||||
'name' => 'setup_wizard_database',
|
||||
'value' => 1,
|
||||
@@ -162,11 +317,11 @@ class SetupDevEnvironment extends Command
|
||||
'name' => 'purchase_code',
|
||||
'value' => '26b889eb-3602-4bf2-beb3-3sc378fcf484',
|
||||
]
|
||||
]);
|
||||
|
||||
// Store options
|
||||
$settings->each(function ($col) {
|
||||
Setting::updateOrCreate(['name' => $col['name']], $col);
|
||||
])->each(function ($col) {
|
||||
Setting::forceCreate([
|
||||
'name' => $col['name'],
|
||||
'value' => $col['value']
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -175,17 +330,15 @@ class SetupDevEnvironment extends Command
|
||||
*/
|
||||
private function migrate_and_generate(): void
|
||||
{
|
||||
// Generate app key
|
||||
$this->call('key:generate', [
|
||||
'--force' => true
|
||||
]);
|
||||
|
||||
// Migrate database
|
||||
$this->call('migrate:fresh', [
|
||||
'--force' => true
|
||||
]);
|
||||
|
||||
$this->setup->seed_default_pages();
|
||||
// Generate app key
|
||||
$this->call('key:generate', [
|
||||
'--force' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user