diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php new file mode 100644 index 000000000000..7ec35be26304 --- /dev/null +++ b/app/Console/Commands/ImportMigrations.php @@ -0,0 +1,115 @@ +faker = Factory::create(); + + parent::__construct(); + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $path = $this->option('path') ?? storage_path('migrations/import'); + + $directory = new \DirectoryIterator($path); + + foreach ($directory as $file) { + if ($file->getExtension() === 'zip') { + $this->info('Started processing: ' . $file->getBasename() . ' at ' . now()); + StartMigration::dispatch('migrations/import/' . $file->getFilename(), $this->getUser(), $this->getUser()->companies()->first()); + } + } + } + + private function getUser(): User + { + $user = factory(\App\Models\User::class)->create([ + 'email' => $this->faker->email, + 'confirmation_code' => $this->createDbHash(config('database.default')) + ]); + + $account = $this->getAccount(); + $company = $this->getCompany($account); + + $company_token = CompanyToken::create([ + 'user_id' => $user->id, + 'company_id' => $company->id, + 'account_id' => $account->id, + 'name' => 'test token', + 'token' => \Illuminate\Support\Str::random(64), + ]); + + $user->companies()->attach($company->id, [ + 'account_id' => $account->id, + 'is_owner' => 1, + 'is_admin' => 1, + 'is_locked' => 0, + 'notifications' => CompanySettings::notificationDefaults(), + 'permissions' => '', + 'settings' => null, + ]); + + return $user; + } + + private function getAccount(): Account + { + return factory(\App\Models\Account::class)->create(); + } + + private function getCompany(Account $account): Company + { + $company = factory(Company::class)->create([ + 'account_id' => $account->id, + ]); + + $account->default_company_id = $company->id; + $account->save(); + + return $company; + } +} diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index 4e7e83fcd2a3..d281402688be 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -44,7 +44,7 @@ class StartMigration implements ShouldQueue */ public function __construct($filepath, User $user, Company $company) { - $this->filepath = base_path("public/storage/$filepath"); + $this->filepath = base_path("storage/$filepath"); $this->user = $user; $this->company = $company; }