-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanifests_processor.php
70 lines (59 loc) · 2.02 KB
/
manifests_processor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use munkireport\processors\Processor;
class Manifests_processor extends Processor
{
/**
* Process data sent by postflight
*
* @param string data
* @author joncrain
**/
function run($json)
{
// Check if data was uploaded
if (!$json) {
throw new Exception("Error Processing Request: No json data found", 1);
}
// Delete previous set
Manifests_model::where('serial_number', $this->serial_number)->delete();
// Process json into object thingy
$data = json_decode($json, true);
// Get fillable items
$fillable = [
'serial_number' => $this->serial_number,
'manifest_name' => '',
'catalogs' => '',
'included_manifests' => '',
'managed_installs' => '',
'managed_uninstalls' => '',
'optional_installs' => '',
'managed_updates' => '',
'featured_items' => '',
'condition_check' => '',
'conditional_items' => '',
'display_name' => '',
];
$save_array = [];
foreach ($data as $manifest_name => $manifest_array) {
// Get an instance of the fillable array
$temp = $fillable;
// Add name to temp
$temp['manifest_name'] = $manifest_name;
foreach ($manifest_array as $key => $value) {
// conditional items need more processing
if ($key == 'conditional_items') {
// encode as JSON for processing later
$temp[$key] = json_encode($value);
} else if ($key == 'display_name' || $key == 'condition_check') {
$temp[$key] = $value;
} else if (array_key_exists($key, $temp)) {
$temp[$key] = implode(", ", $value);
}
}
$save_array[] = $temp;
}
Manifests_model::insertChunked(
$save_array
);
}
}