forked from dysath/seat-fitting
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request applies code style fixes from an analysis carried out by [StyleCI](https://github.styleci.io). --- For more information, click [here](https://github.styleci.io/analyses/Zn1k5R).
- Loading branch information
Showing
8 changed files
with
125 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,111 @@ | ||
<?php | ||
|
||
|
||
namespace CryptaTech\Seat\Fitting\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Log; | ||
use CryptaTech\Seat\Fitting\Models\Fitting; | ||
use CryptaTech\Seat\Fitting\Models\Doctrine; | ||
use CryptaTech\Seat\Fitting\Models\OldFitting; | ||
use CryptaTech\Seat\Fitting\Models\OldDoctrine; | ||
use Exception; | ||
|
||
/** | ||
* Class UpgradeFits. | ||
* | ||
* @package CryptaTech\Seat\Fitting\Commands | ||
*/ | ||
class UpgradeFits extends Command | ||
{ | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'cryptatech:fittings:upgrade'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'upgrade previous seat-fitting fittings to the new modelling'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
|
||
$this->info("Finding fits to upgrade!"); | ||
|
||
$oldFits = OldFitting::all(); | ||
$c = count($oldFits); | ||
|
||
$this->info("Found " . $c . " fits to process"); | ||
|
||
$bar = $this->getProgressBar($c); | ||
$failedUpgrades = 0; | ||
|
||
$mapping = []; | ||
|
||
foreach ($oldFits as $oldFit) { | ||
try { // If a fit fails then we just add it to a list of errors. | ||
$f = Fitting::createFromEve($oldFit->eftfitting); | ||
$mapping[$oldFit->id] = $f->fitting_id; | ||
} catch (Exception $e) { | ||
Log::error(['fit' => $oldFit->eftfitting, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); | ||
$failedUpgrades += 1; | ||
} | ||
$bar->advance(); | ||
} | ||
|
||
$bar->finish(); | ||
$this->line(''); | ||
|
||
$this->info('Fitting Migration Complete!'); | ||
$this->info('Success: ' . $c - $failedUpgrades); | ||
$this->warn('Failure : ' . $failedUpgrades); | ||
|
||
$this->line(''); | ||
|
||
|
||
$this->info("Updating Doctrine Fitting Mapping!"); | ||
$oldDocs = OldDoctrine::all(); | ||
$bar = $this->getProgressBar(count($oldDocs)); | ||
|
||
foreach( $oldDocs as $oldDoc){ | ||
$newDoc = Doctrine::create([ | ||
'name' => $oldDoc->name, | ||
]); | ||
foreach ($oldDoc->fittings()->get() as $oldFit) { | ||
$newDoc->fittings()->attach($mapping[$oldFit->id]); | ||
} | ||
$bar->advance(); | ||
|
||
} | ||
|
||
$bar->finish(); | ||
$this->line(''); | ||
|
||
$this->info('Doctrine Migration Complete!'); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Get a new progress bar to display based on the | ||
* amount of iterations we expect to use. | ||
* | ||
* @param $iterations | ||
* @return \Symfony\Component\Console\Helper\ProgressBar | ||
*/ | ||
public function getProgressBar($iterations) | ||
{ | ||
|
||
$bar = $this->output->createProgressBar($iterations); | ||
|
||
$bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% %memory:6s%'); | ||
|
||
return $bar; | ||
} | ||
} | ||
<?php | ||
|
||
namespace CryptaTech\Seat\Fitting\Commands; | ||
|
||
use CryptaTech\Seat\Fitting\Models\Doctrine; | ||
use CryptaTech\Seat\Fitting\Models\Fitting; | ||
use CryptaTech\Seat\Fitting\Models\OldDoctrine; | ||
use CryptaTech\Seat\Fitting\Models\OldFitting; | ||
use Exception; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
/** | ||
* Class UpgradeFits. | ||
* | ||
* @package CryptaTech\Seat\Fitting\Commands | ||
*/ | ||
class UpgradeFits extends Command | ||
{ | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'cryptatech:fittings:upgrade'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'upgrade previous seat-fitting fittings to the new modelling'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
|
||
$this->info('Finding fits to upgrade!'); | ||
|
||
$oldFits = OldFitting::all(); | ||
$c = count($oldFits); | ||
|
||
$this->info('Found ' . $c . ' fits to process'); | ||
|
||
$bar = $this->getProgressBar($c); | ||
$failedUpgrades = 0; | ||
|
||
$mapping = []; | ||
|
||
foreach ($oldFits as $oldFit) { | ||
try { // If a fit fails then we just add it to a list of errors. | ||
$f = Fitting::createFromEve($oldFit->eftfitting); | ||
$mapping[$oldFit->id] = $f->fitting_id; | ||
} catch (Exception $e) { | ||
Log::error(['fit' => $oldFit->eftfitting, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); | ||
$failedUpgrades += 1; | ||
} | ||
$bar->advance(); | ||
} | ||
|
||
$bar->finish(); | ||
$this->line(''); | ||
|
||
$this->info('Fitting Migration Complete!'); | ||
$this->info('Success: ' . $c - $failedUpgrades); | ||
$this->warn('Failure : ' . $failedUpgrades); | ||
|
||
$this->line(''); | ||
|
||
$this->info('Updating Doctrine Fitting Mapping!'); | ||
$oldDocs = OldDoctrine::all(); | ||
$bar = $this->getProgressBar(count($oldDocs)); | ||
|
||
foreach($oldDocs as $oldDoc){ | ||
$newDoc = Doctrine::create([ | ||
'name' => $oldDoc->name, | ||
]); | ||
foreach ($oldDoc->fittings()->get() as $oldFit) { | ||
$newDoc->fittings()->attach($mapping[$oldFit->id]); | ||
} | ||
$bar->advance(); | ||
|
||
} | ||
|
||
$bar->finish(); | ||
$this->line(''); | ||
|
||
$this->info('Doctrine Migration Complete!'); | ||
|
||
} | ||
|
||
/** | ||
* Get a new progress bar to display based on the | ||
* amount of iterations we expect to use. | ||
* | ||
* @param $iterations | ||
* @return \Symfony\Component\Console\Helper\ProgressBar | ||
*/ | ||
public function getProgressBar($iterations) | ||
{ | ||
|
||
$bar = $this->output->createProgressBar($iterations); | ||
|
||
$bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% %memory:6s%'); | ||
|
||
return $bar; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters