Apply fixes from StyleCI
This commit is contained in:
committed by
StyleCI Bot
parent
20f46adbc4
commit
9596d88b48
@@ -15,17 +15,16 @@ use App\Models\Rank;
|
||||
use App\Models\Subfleet;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use PDOException;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
/**
|
||||
* Class Importer
|
||||
* TODO: Batch import
|
||||
* @package App\Console\Services
|
||||
*/
|
||||
class Importer
|
||||
{
|
||||
@@ -36,6 +35,7 @@ class Importer
|
||||
|
||||
/**
|
||||
* Hold the PDO connection to the old database
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
private $conn;
|
||||
@@ -47,6 +47,7 @@ class Importer
|
||||
|
||||
/**
|
||||
* Hold the instance of the console logger
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
private $log;
|
||||
@@ -54,12 +55,12 @@ class Importer
|
||||
/**
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
const BATCH_READ_ROWS = 300;
|
||||
const SUBFLEET_NAME = 'Imported Aircraft';
|
||||
const SUBFLEET_NAME = 'Imported Aircraft';
|
||||
|
||||
/**
|
||||
* Importer constructor.
|
||||
*
|
||||
* @param $db_creds
|
||||
*/
|
||||
public function __construct($db_creds)
|
||||
@@ -67,14 +68,14 @@ class Importer
|
||||
// Setup the logger
|
||||
$this->log = new ConsoleOutput();
|
||||
|
||||
# The db credentials
|
||||
// The db credentials
|
||||
$this->creds = array_merge([
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 3306,
|
||||
'name' => '',
|
||||
'user' => '',
|
||||
'pass' => '',
|
||||
'table_prefix' => 'phpvms_'
|
||||
'table_prefix' => 'phpvms_',
|
||||
], $db_creds);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ class Importer
|
||||
{
|
||||
$this->reconnect();
|
||||
|
||||
# Import all the different parts
|
||||
// Import all the different parts
|
||||
$this->importRanks();
|
||||
$this->importAirlines();
|
||||
$this->importAircraft();
|
||||
@@ -95,7 +96,7 @@ class Importer
|
||||
$this->importFlights();
|
||||
$this->importPireps();
|
||||
|
||||
# Finish up
|
||||
// Finish up
|
||||
$this->findLastPireps();
|
||||
$this->recalculateRanks();
|
||||
}
|
||||
@@ -108,7 +109,7 @@ class Importer
|
||||
$dsn = 'mysql:'.implode(';', [
|
||||
'host='.$this->creds['host'],
|
||||
'port='.$this->creds['port'],
|
||||
'dbname='.$this->creds['name']
|
||||
'dbname='.$this->creds['name'],
|
||||
]);
|
||||
|
||||
$this->info('Connection string: '.$dsn);
|
||||
@@ -152,7 +153,9 @@ class Importer
|
||||
|
||||
/**
|
||||
* Return the table name with the prefix
|
||||
*
|
||||
* @param $table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function tableName($table)
|
||||
@@ -165,8 +168,8 @@ class Importer
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function saveModel($model)
|
||||
@@ -186,6 +189,7 @@ class Importer
|
||||
|
||||
/**
|
||||
* Create a new mapping between an old ID and the new one
|
||||
*
|
||||
* @param $entity
|
||||
* @param $old_id
|
||||
* @param $new_id
|
||||
@@ -201,8 +205,10 @@ class Importer
|
||||
|
||||
/**
|
||||
* Return the ID for a mapping
|
||||
*
|
||||
* @param $entity
|
||||
* @param $old_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function getMapping($entity, $old_id)
|
||||
@@ -221,6 +227,7 @@ class Importer
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function parseDate($date)
|
||||
@@ -232,7 +239,9 @@ class Importer
|
||||
|
||||
/**
|
||||
* Take a decimal duration and convert it to minutes
|
||||
*
|
||||
* @param $duration
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
protected function convertDuration($duration)
|
||||
@@ -242,7 +251,7 @@ class Importer
|
||||
} elseif (strpos($duration, ':')) {
|
||||
$delim = ':';
|
||||
} else {
|
||||
# no delimiter, assume it's just a straight hour
|
||||
// no delimiter, assume it's just a straight hour
|
||||
return (int) $duration * 60;
|
||||
}
|
||||
|
||||
@@ -255,6 +264,7 @@ class Importer
|
||||
|
||||
/**
|
||||
* @param $table
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTotalRows($table)
|
||||
@@ -271,8 +281,10 @@ class Importer
|
||||
|
||||
/**
|
||||
* Read all the rows in a table, but read them in a batched manner
|
||||
*
|
||||
* @param string $table The name of the table
|
||||
* @param null $read_rows Number of rows to read
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
protected function readRows($table, $read_rows = null)
|
||||
@@ -318,6 +330,7 @@ class Importer
|
||||
|
||||
/**
|
||||
* Return the subfleet
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getSubfleet()
|
||||
@@ -332,10 +345,8 @@ class Importer
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* All the individual importers, done on a per-table basis
|
||||
* Some tables get saved locally for tables that use FK refs
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -356,7 +367,7 @@ class Importer
|
||||
$this->addMapping('ranks', $row->rank, $rank->id);
|
||||
|
||||
if ($rank->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +393,7 @@ class Importer
|
||||
$this->addMapping('airlines', $row->code, $airline->id);
|
||||
|
||||
if ($airline->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,13 +417,13 @@ class Importer
|
||||
['name' => $row->fullname, 'registration' => $row->registration],
|
||||
['icao' => $row->icao,
|
||||
'subfleet_id' => $subfleet->id,
|
||||
'active' => $row->enabled
|
||||
'active' => $row->enabled,
|
||||
]);
|
||||
|
||||
$this->addMapping('aircraft', $row->id, $aircraft->id);
|
||||
|
||||
if ($aircraft->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +455,7 @@ class Importer
|
||||
);
|
||||
|
||||
if ($airport->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,7 +494,7 @@ class Importer
|
||||
$attrs
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
#$this->error($e);
|
||||
//$this->error($e);
|
||||
}
|
||||
|
||||
$this->addMapping('flights', $row->id, $flight->id);
|
||||
@@ -491,7 +502,7 @@ class Importer
|
||||
// TODO: deserialize route_details into ACARS table
|
||||
|
||||
if ($flight->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,7 +524,7 @@ class Importer
|
||||
$aircraft_id = $this->getMapping('aircraft', $row->aircraft);
|
||||
|
||||
$attrs = [
|
||||
#'id' => $pirep_id,
|
||||
//'id' => $pirep_id,
|
||||
'user_id' => $user_id,
|
||||
'airline_id' => $airline_id,
|
||||
'aircraft_id' => $aircraft_id,
|
||||
@@ -527,24 +538,24 @@ class Importer
|
||||
'updated_at' => $this->parseDate($row->modifieddate),
|
||||
];
|
||||
|
||||
# Set the distance
|
||||
// Set the distance
|
||||
$distance = round($row->distance ?: 0, 2);
|
||||
$attrs['distance'] = $distance;
|
||||
$attrs['planned_distance'] = $distance;
|
||||
|
||||
# Set the flight time properly
|
||||
// Set the flight time properly
|
||||
$duration = $this->convertDuration($row->flighttime_stamp);
|
||||
$attrs['flight_time'] = $duration;
|
||||
$attrs['planned_flight_time'] = $duration;
|
||||
|
||||
# Set how it was filed
|
||||
// Set how it was filed
|
||||
if (strtoupper($row->source) === 'MANUAL') {
|
||||
$attrs['source'] = PirepSource::MANUAL;
|
||||
} else {
|
||||
$attrs['source'] = PirepSource::ACARS;
|
||||
}
|
||||
|
||||
# Set the flight type
|
||||
// Set the flight type
|
||||
$row->flighttype = strtoupper($row->flighttype);
|
||||
if ($row->flighttype === 'P') {
|
||||
$attrs['flight_type'] = FlightType::SCHED_PAX;
|
||||
@@ -554,7 +565,7 @@ class Importer
|
||||
$attrs['flight_type'] = FlightType::CHARTER_PAX_ONLY;
|
||||
}
|
||||
|
||||
# Set the flight level of the PIREP is set
|
||||
// Set the flight level of the PIREP is set
|
||||
if (property_exists($row, 'flightlevel')) {
|
||||
$attrs['level'] = $row->flightlevel;
|
||||
} else {
|
||||
@@ -568,18 +579,18 @@ class Importer
|
||||
|
||||
$source = strtoupper($row->source);
|
||||
if ($source === 'SMARTCARS') {
|
||||
# TODO: Parse smartcars log into the acars table
|
||||
// TODO: Parse smartcars log into the acars table
|
||||
} elseif ($source === 'KACARS') {
|
||||
# TODO: Parse kACARS log into acars table
|
||||
// TODO: Parse kACARS log into acars table
|
||||
} elseif ($source === 'XACARS') {
|
||||
# TODO: Parse XACARS log into acars table
|
||||
// TODO: Parse XACARS log into acars table
|
||||
}
|
||||
|
||||
# TODO: Add extra fields in as PIREP fields
|
||||
// TODO: Add extra fields in as PIREP fields
|
||||
$this->addMapping('pireps', $row->pirepid, $pirep->id);
|
||||
|
||||
if ($pirep->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,7 +603,7 @@ class Importer
|
||||
|
||||
$count = 0;
|
||||
foreach ($this->readRows('pilots', 50) as $row) {
|
||||
# TODO: What to do about pilot ids
|
||||
// TODO: What to do about pilot ids
|
||||
|
||||
$name = $row->firstname.' '.$row->lastname;
|
||||
|
||||
@@ -624,7 +635,7 @@ class Importer
|
||||
$this->addMapping('users', $row->pilotid, $user->id);
|
||||
|
||||
if ($user->wasRecentlyCreated) {
|
||||
++$count;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,7 +659,9 @@ class Importer
|
||||
|
||||
/**
|
||||
* Get the user's new state from their original state
|
||||
*
|
||||
* @param $state
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getUserState($state)
|
||||
@@ -662,21 +675,20 @@ class Importer
|
||||
'ACTIVE' => 0,
|
||||
'INACTIVE' => 1,
|
||||
'BANNED' => 2,
|
||||
'ON_LEAVE' => 3
|
||||
'ON_LEAVE' => 3,
|
||||
];
|
||||
|
||||
// Decide which state they will be in accordance with v7
|
||||
if ($state === $phpvms_classic_states['ACTIVE']) {
|
||||
return UserState::ACTIVE;
|
||||
} elseif ($state === $phpvms_classic_states['INACTIVE']) {
|
||||
# TODO: Make an inactive state?
|
||||
// TODO: Make an inactive state?
|
||||
return UserState::REJECTED;
|
||||
} elseif ($state === $phpvms_classic_states['BANNED']) {
|
||||
return UserState::SUSPENDED;
|
||||
} elseif ($state === $phpvms_classic_states['ON_LEAVE']) {
|
||||
return UserState::ON_LEAVE;
|
||||
} else {
|
||||
$this->error('Unknown status: '.$state);
|
||||
}
|
||||
$this->error('Unknown status: '.$state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user