Skip to content

Commit

Permalink
Upate machine_processor
Browse files Browse the repository at this point in the history
Simplify logic
  • Loading branch information
bochoven committed Jan 20, 2020
1 parent b8d53e6 commit 99f8296
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions machine_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ public function run($plist)
$mylist['buildversion'] = preg_replace('/[^A-Za-z0-9]/', '', $mylist['buildversion']);
}

// Try to retrieve machine and add model
// Retrieve machine record (if existing)
try {
$machine = Machine_model::select()
->where('serial_number', $this->serial_number)
->firstOrFail();
if ($this->should_run_model_description_lookup($machine)){
require_once(__DIR__ . '/helpers/model_lookup_helper.php');
$mylist['machine_desc'] = machine_model_lookup($this->serial_number);
$machine->fill($mylist);
}
} catch (\Throwable $th) {
$machine = new Machine_model();
}

// Check if we need to retrieve model from Apple
if ($this->should_run_model_description_lookup($machine)){
require_once(__DIR__ . '/helpers/model_lookup_helper.php');
$mylist['machine_desc'] = machine_model_lookup($this->serial_number);
Machine_model::create($mylist);
}
}

$machine->fill($mylist)->save();
}

function should_run_model_description_lookup($machine)
Expand Down

0 comments on commit 99f8296

Please sign in to comment.