|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FlexiPeeHP; |
|
4
|
|
|
|
|
5
|
|
|
require_once '../testing/bootstrap.php'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Obtain structure for given evidence |
|
9
|
|
|
* |
|
10
|
|
|
* @param string $evidence |
|
11
|
|
|
* @param FlexiBeeRO $syncer Class to read from FlexiBee |
|
12
|
|
|
* @return array Evidence structure |
|
13
|
|
|
*/ |
|
14
|
|
|
function getColumnsInfo($evidence, FlexiBeeRO $syncer) |
|
15
|
|
|
{ |
|
16
|
|
|
$useKeywords = []; |
|
17
|
|
|
$flexinfo = $syncer->performRequest($evidence.'/properties.json'); |
|
18
|
|
|
if (count($flexinfo) && array_key_exists('properties', $flexinfo)) { |
|
19
|
|
|
foreach ($flexinfo['properties']['property'] as $evidenceProperty) { |
|
20
|
|
|
$key = $evidenceProperty['propertyName']; |
|
21
|
|
|
$useKeywords[$key] = $evidenceProperty; |
|
22
|
|
|
$useKeywords[$key]['name'] = $evidenceProperty['name']; |
|
23
|
|
|
$useKeywords[$key]['type'] = $evidenceProperty['type']; |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
return $useKeywords; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
function controlData($data, $fbColumns, $fbRelations) |
|
30
|
|
|
{ |
|
31
|
|
|
$controlResult = []; |
|
32
|
|
|
if (count($fbColumns)) { |
|
33
|
|
|
foreach ($data as $key => $value) { |
|
34
|
|
|
if ($key == 'external-ids') { |
|
35
|
|
|
continue; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (strstr($key, '@')) { |
|
39
|
|
|
$baseKey = substr($key, 0, strrpos($key, '@')); |
|
40
|
|
|
if (!array_key_exists($baseKey, $fbColumns)) { |
|
41
|
|
|
$controlResult[$key][] = sprintf('unknown column property %s', |
|
42
|
|
|
$key); |
|
43
|
|
|
} |
|
44
|
|
|
continue; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!array_key_exists($key, $fbColumns)) { |
|
48
|
|
|
if (is_array($fbRelations) && !array_key_exists($key, |
|
49
|
|
|
$fbRelations)) { |
|
50
|
|
|
$controlResult[$key][] = sprintf('unknown column %s', $key); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
return $controlResult; |
|
56
|
|
|
} |
|
57
|
|
|
$syncer = new EvidenceList(); |
|
58
|
|
|
|
|
59
|
|
|
$evidencies = $syncer->getColumnsFromFlexibee(['evidencePath', 'evidenceName']); |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$controlResult = []; |
|
63
|
|
|
foreach ($evidencies['evidences']['evidence'] as $evidenceID => $evidence) { |
|
64
|
|
|
$evlist[$evidence['evidencePath']] = $evidence['evidenceName']; |
|
65
|
|
|
|
|
66
|
|
|
$syncer->setEvidence($evidence['evidencePath']); |
|
67
|
|
|
$firstRecord = $syncer->getFlexiData(null, ['limit' => 1]); |
|
68
|
|
|
if (count($firstRecord) && isset($firstRecord[0]) && count($firstRecord[0])) { |
|
69
|
|
|
$controlled = controlData($firstRecord[0], $syncer->getColumnsInfo(), |
|
70
|
|
|
$syncer->getRelationsInfo()); |
|
71
|
|
|
if (count($controlled)) { |
|
72
|
|
|
$controlResult[$evidence['evidencePath']] = $controlled; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
echo json_encode($controlResult, JSON_PRETTY_PRINT); |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
|