1
|
|
|
<?php |
2
|
|
|
use dokuwiki\plugin\struct\meta\AccessTable; |
|
|
|
|
3
|
|
|
use dokuwiki\plugin\struct\meta\StructException; |
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* DokuWiki Plugin swarmzapierstructwebhook (Helper Component) |
7
|
|
|
* |
8
|
|
|
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html |
9
|
|
|
* @author Michael Große <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
class helper_plugin_swarmzapierstructwebhook extends DokuWiki_Plugin |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Extract the data to be saved from the payload |
17
|
|
|
* |
18
|
|
|
* @param array $data |
19
|
|
|
* |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
2 |
|
public function extractDataFromPayload(array $data) |
23
|
|
|
{ |
24
|
2 |
|
$checkinID = $data['id']; |
25
|
2 |
|
$locationName = $data['venue']['name']; |
26
|
|
|
|
27
|
2 |
|
$dateTime = $this->getDateTimeInstance($data['createdAt'], $data['timeZoneOffset']); |
28
|
|
|
|
29
|
|
|
$lookupData = [ |
30
|
2 |
|
'date' => $dateTime->format('Y-m-d'), |
31
|
2 |
|
'time' => $dateTime->format(DateTime::ATOM), |
32
|
2 |
|
'checkinid' => $checkinID, |
33
|
2 |
|
'locname' => $locationName, |
34
|
|
|
]; |
35
|
2 |
|
if (!empty($data['shout'])) { |
36
|
1 |
|
$lookupData['shout'] = $data['shout']; |
37
|
|
|
} |
38
|
2 |
|
return $lookupData; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Transforms a timestamp and the timezone offset as provided in the payload into an DateTimeInterface instance |
43
|
|
|
* |
44
|
|
|
* @param int $timestamp |
45
|
|
|
* @param int $payloadTimezoneOffset offset to UTC in minutes |
46
|
|
|
* |
47
|
|
|
* @return DateTimeInterface |
48
|
|
|
*/ |
49
|
2 |
|
protected function getDateTimeInstance($timestamp, $payloadTimezoneOffset) |
50
|
|
|
{ |
51
|
2 |
|
$tzSign = $payloadTimezoneOffset >= 0 ? '+' : '-'; |
52
|
2 |
|
$offsetInHours = $payloadTimezoneOffset / 60; |
53
|
2 |
|
$tz = $tzSign . str_pad($offsetInHours * 100, 4, '0', STR_PAD_LEFT); |
54
|
2 |
|
$dateTime = new DateTime('now', new DateTimeZone($tz)); |
55
|
2 |
|
$dateTime->setTimestamp($timestamp); |
56
|
2 |
|
return $dateTime; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $data associative array in the form of [columnname => columnvalue] |
61
|
|
|
*/ |
62
|
|
|
public function saveDataToLookup(array $data) |
63
|
|
|
{ |
64
|
|
|
$access = AccessTable::byTableName('swarm', 0, 0); |
65
|
|
|
if (!$access->getSchema()->isEditable()) { |
66
|
|
|
throw new StructException('lookup save error: no permission for schema'); |
67
|
|
|
} |
68
|
|
|
$validator = $access->getValidator($data); |
69
|
|
|
if (!$validator->validate()) { |
70
|
|
|
throw new StructException("Validation failed:\n%s", implode("\n", $validator->getErrors())); |
71
|
|
|
} |
72
|
|
|
if (!$validator->saveData()) { |
73
|
|
|
throw new StructException('No data saved'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Deletes a checkin from the lookup |
79
|
|
|
* |
80
|
|
|
* @param string $checkinid |
81
|
|
|
*/ |
82
|
|
|
public function deleteCheckinFromLookup($checkinid) |
83
|
|
|
{ |
84
|
|
|
$tablename = 'swarm'; |
85
|
|
|
|
86
|
|
|
/** @var remote_plugin_struct $remote */ |
87
|
|
|
$remote = plugin_load('remote', 'struct'); |
|
|
|
|
88
|
|
|
$rows = $remote->getAggregationData( |
89
|
|
|
[$tablename], |
90
|
|
|
['%rowid%'], |
91
|
|
|
[['logic'=> 'and', 'condition' => "checkinid = $checkinid"]] |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$pids = array_column($rows, '%rowid%'); |
95
|
|
|
|
96
|
|
|
if (empty($pids)) { |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
foreach ($pids as $pid) { // should only be a single entry |
100
|
|
|
$schemadata = AccessTable::byTableName($tablename, $pid); |
101
|
|
|
if (!$schemadata->getSchema()->isEditable()) { |
102
|
|
|
throw new StructException('lookup delete error: no permission for schema'); |
103
|
|
|
} |
104
|
|
|
$schemadata->clearData(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths