forked from munkireport/users
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers_processor.php
executable file
·38 lines (31 loc) · 1004 Bytes
/
users_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
<?php
use CFPropertyList\CFPropertyList;
use munkireport\processors\Processor;
class Users_processor extends Processor
{
/**
* Process data sent by postflight
*
* @param string data
* @author tuxudo
**/
public function run($plist)
{
// Check if we have data
if ( ! $plist){
throw new Exception("Error Processing Request: No property list found", 1);
}
// Delete previous set
Users_model::where('serial_number', $this->serial_number)->delete();
$parser = new CFPropertyList();
$parser->parse($plist, CFPropertyList::FORMAT_XML);
// Get fillable items
$fillable = array_fill_keys((new Users_model)->getFillable(), null);
$fillable['serial_number'] = $this->serial_number;
$save_list = [];
foreach ($parser->toArray() as $user) {
$save_list[] = array_replace($fillable, $user);
}
Users_model::insertChunked($save_list);
}
}