Skip to content

Commit

Permalink
Remove model lookup code
Browse files Browse the repository at this point in the history
  • Loading branch information
bochoven committed Jan 20, 2020
1 parent 23ad351 commit 1378b48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 65 deletions.
64 changes: 0 additions & 64 deletions helpers/warranty_helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use munkireport\lib\Request;

/**
* Unfortunately we have to scrape the page as Apple discontinued the json api
*
Expand Down Expand Up @@ -29,14 +27,6 @@ function check_warranty_status(&$warranty_model)
}
$warranty_model->purchase_date = date('Y-m-d', $report['reg_timestamp']);
$warranty_model->end_date = date('Y-m-d', strtotime('+10 year'));

Machine_model::updateOrCreate(
['serial_number' => $warranty_model->serial_number],
[
'serial_number' => $warranty_model->serial_number,
'machine_desc' => 'VMware virtual machine',
]
);

return;
}
Expand All @@ -60,26 +50,6 @@ function check_warranty_status(&$warranty_model)
}


// Get machine model from apple (only when not set or failed)
try {
$machine = Machine_model::select('machine_desc')
->where('serial_number', $warranty_model->serial_number)
->firstOrFail();
} catch (\Throwable $th) {
return;
}
// dd(model_description_lookup($warranty_model->serial_number));
$lookup_failed = array('model_lookup_failed', 'unknown_model');
if (! $machine or ! $machine['machine_desc'] or in_array($machine['machine_desc'], $lookup_failed)) {
Machine_model::updateOrCreate(
['serial_number' => $warranty_model->serial_number],
[
'serial_number' => $warranty_model->serial_number,
'machine_desc' => model_description_lookup($warranty_model->serial_number),
]
);
}

return $error;
}

Expand Down Expand Up @@ -120,37 +90,3 @@ function formatted_manufactured_date($year, $week)
$strtime = sprintf('%sW%02s1', $year, $week);
return date('Y-m-d', strtotime($strtime));
}

function model_description_lookup($serial)
{
if (strpos($serial, 'VMWV') === 0) {
return 'VMware virtual machine';
}

$options = [
'query' => [
'page' => 'categorydata',
'serialnumber' => $serial
]
];

$client = new Request();
$result = $client->get('http://km.support.apple.com/kb/index', $options);

if ( ! $result) {
return 'model_lookup_failed';
}

try {
$categorydata = json_decode($result);
if(isset($categorydata->name)){
return $categorydata->name;
}
else{
return 'unknown_model';
}
} catch (Exception $e) {
return 'model_lookup_failed';
}

}
5 changes: 4 additions & 1 deletion warranty_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public function process()
if (! in_array("gsx", conf('modules'))) {
alert("warranty: current status: $this->status");

// Load warranty helper
require_once(__DIR__ . '/helpers/warranty_helper.php');

switch ($this->status) {
case 'Supported':
// If not expired, return;
Expand Down Expand Up @@ -132,7 +135,7 @@ public function process()
// Unknown status
alert('warranty: unknown status: '.$this->status, 'warning');
}
$this->check_status($force = true);
//$this->check_status($force = true);

alert(sprintf("warranty: new status: %s", $this->status));
}
Expand Down

0 comments on commit 1378b48

Please sign in to comment.