2019-11-27 22:19:20 +08:00
|
|
|
<?php
|
|
|
|
|
2019-12-13 04:07:35 +08:00
|
|
|
namespace Modules\Importer\Services\Importers;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
use App\Models\Acars;
|
2020-02-24 08:48:28 +08:00
|
|
|
use App\Models\Aircraft;
|
2019-11-27 22:19:20 +08:00
|
|
|
use App\Models\Airline;
|
|
|
|
use App\Models\Airport;
|
|
|
|
use App\Models\Bid;
|
|
|
|
use App\Models\Expense;
|
|
|
|
use App\Models\File;
|
|
|
|
use App\Models\Flight;
|
|
|
|
use App\Models\FlightField;
|
|
|
|
use App\Models\FlightFieldValue;
|
|
|
|
use App\Models\Journal;
|
|
|
|
use App\Models\JournalTransaction;
|
2020-02-26 03:45:23 +08:00
|
|
|
use App\Models\Ledger;
|
2019-11-27 22:19:20 +08:00
|
|
|
use App\Models\News;
|
|
|
|
use App\Models\Pirep;
|
2020-02-24 08:48:28 +08:00
|
|
|
use App\Models\Role;
|
2019-11-27 22:19:20 +08:00
|
|
|
use App\Models\Subfleet;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\UserAward;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-12-13 04:07:35 +08:00
|
|
|
use Modules\Importer\Services\BaseImporter;
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
class ClearDatabase extends BaseImporter
|
2019-11-27 22:19:20 +08:00
|
|
|
{
|
|
|
|
/**
|
2019-12-02 22:57:35 +08:00
|
|
|
* Returns a default manifest just so this step gets run
|
2019-11-27 22:19:20 +08:00
|
|
|
*/
|
2019-12-02 22:57:35 +08:00
|
|
|
public function getManifest(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'importer' => get_class($this),
|
|
|
|
'start' => 0,
|
|
|
|
'end' => 1,
|
|
|
|
'message' => 'Clearing database',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
public function run($start = 0)
|
|
|
|
{
|
|
|
|
$this->cleanupDb();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup the local database of any users and other data that might conflict
|
|
|
|
* before running the importer
|
|
|
|
*/
|
|
|
|
protected function cleanupDb()
|
|
|
|
{
|
|
|
|
$this->info('Running database cleanup/empty before starting');
|
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
DB::statement('SET FOREIGN_KEY_CHECKS=0');
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
Bid::truncate();
|
|
|
|
File::truncate();
|
|
|
|
News::truncate();
|
|
|
|
|
|
|
|
Expense::truncate();
|
|
|
|
JournalTransaction::truncate();
|
|
|
|
Journal::truncate();
|
2020-02-26 03:45:23 +08:00
|
|
|
Ledger::truncate();
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
// Clear flights
|
|
|
|
DB::table('flight_fare')->truncate();
|
|
|
|
DB::table('flight_subfleet')->truncate();
|
|
|
|
FlightField::truncate();
|
|
|
|
FlightFieldValue::truncate();
|
|
|
|
Flight::truncate();
|
|
|
|
Subfleet::truncate();
|
2020-02-24 08:48:28 +08:00
|
|
|
Aircraft::truncate();
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
Airline::truncate();
|
|
|
|
Airport::truncate();
|
|
|
|
Acars::truncate();
|
|
|
|
Pirep::truncate();
|
|
|
|
|
|
|
|
UserAward::truncate();
|
|
|
|
User::truncate();
|
|
|
|
|
2020-02-24 08:48:28 +08:00
|
|
|
// Clear permissions
|
|
|
|
DB::table('permission_role')->truncate();
|
|
|
|
DB::table('permission_user')->truncate();
|
|
|
|
DB::table('role_user')->truncate();
|
|
|
|
|
|
|
|
// Role::truncate();
|
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
DB::statement('SET FOREIGN_KEY_CHECKS=1');
|
2020-02-24 08:48:28 +08:00
|
|
|
|
|
|
|
$this->idMapper->clear();
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|
|
|
|
}
|