buildCache(); if(!MultiDB::userFindAndSetDb($this->option('email'))){ $this->info("Could not find a user with that email address"); return; } $user = User::where('email', $this->option('email'))->first(); if(!$user){ $this->info("There was a problem getting the user, did you set the right DB?"); return; } $path = public_path('storage/migrations/import'); $directory = new DirectoryIterator($path); foreach ($directory as $file) { if ($file->getExtension() === 'zip') { $company = $user->companies()->first(); $this->info('Started processing: '.$file->getBasename().' at '.now()); $zip = new ZipArchive(); $archive = $zip->open($file->getRealPath()); try { if (! $archive) { throw new ProcessingMigrationArchiveFailed('Processing migration archive failed. Migration file is possibly corrupted.'); } $filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME); $zip->extractTo(public_path("storage/migrations/{$filename}")); $zip->close(); $import_file = public_path("storage/migrations/$filename/migration.json"); Import::dispatch($import_file, $user->companies()->first(), $user); } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { \Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); if (app()->environment() !== 'production') { info($e->getMessage()); } } } } } }