| 1 | <?php |
||||
| 2 | use dokuwiki\plugin\struct\meta\AccessTable; |
||||
|
1 ignored issue
–
show
|
|||||
| 3 | use dokuwiki\plugin\struct\meta\StructException; |
||||
|
1 ignored issue
–
show
The type
dokuwiki\plugin\struct\meta\StructException was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 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 |
||||
|
1 ignored issue
–
show
The type
DokuWiki_Plugin was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 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 | $timestamp = $data['createdAt']; |
|||
| 25 | 2 | $checkinID = $data['id']; |
|||
| 26 | 2 | $locationName = $data['venue']['name']; |
|||
| 27 | |||||
| 28 | 2 | $tzSign = $data['timeZoneOffset'] >= 0 ? '+' : '-'; |
|||
| 29 | 2 | $offsetInHours = $data['timeZoneOffset'] / 60; |
|||
| 30 | 2 | $tz = $tzSign . str_pad($offsetInHours * 100, 4, '0', STR_PAD_LEFT); |
|||
| 31 | 2 | $dateTime = new DateTime('now', new DateTimeZone($tz)); |
|||
| 32 | 2 | $dateTime->setTimestamp($timestamp); |
|||
| 33 | 2 | $date = $dateTime->format('Y-m-d'); |
|||
| 34 | 2 | $time = $dateTime->format(DateTime::ATOM); |
|||
| 35 | |||||
| 36 | $lookupData = [ |
||||
| 37 | 2 | 'date' => $date, |
|||
| 38 | 2 | 'time' => $time, |
|||
| 39 | 2 | 'checkinid' => $checkinID, |
|||
| 40 | 2 | 'locname' => $locationName, |
|||
| 41 | ]; |
||||
| 42 | 2 | if (!empty($data['shout'])) { |
|||
| 43 | 1 | $lookupData['shout'] = $data['shout']; |
|||
| 44 | } |
||||
| 45 | 2 | return $lookupData; |
|||
| 46 | } |
||||
| 47 | |||||
| 48 | /** |
||||
| 49 | * @param array $data associative array in the form of [columnname => columnvalue] |
||||
| 50 | */ |
||||
| 51 | public function saveDataToLookup(array $data) |
||||
| 52 | { |
||||
| 53 | $access = AccessTable::byTableName('swarm', 0, 0); |
||||
| 54 | if (!$access->getSchema()->isEditable()) { |
||||
| 55 | throw new StructException('lookup save error: no permission for schema'); |
||||
| 56 | } |
||||
| 57 | $validator = $access->getValidator($data); |
||||
| 58 | if (!$validator->validate()) { |
||||
| 59 | throw new StructException("Validation failed:\n%s", implode("\n", $validator->getErrors())); |
||||
| 60 | } |
||||
| 61 | if (!$validator->saveData()) { |
||||
| 62 | throw new StructException('No data saved'); |
||||
| 63 | } |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | /** |
||||
| 67 | * Deletes a checkin from the lookup |
||||
| 68 | * |
||||
| 69 | * @param string $checkinid |
||||
| 70 | */ |
||||
| 71 | public function deleteCheckinFromLookup($checkinid) |
||||
| 72 | { |
||||
| 73 | $tablename = 'swarm'; |
||||
| 74 | |||||
| 75 | /** @var remote_plugin_struct $remote */ |
||||
| 76 | $remote = plugin_load('remote', 'struct'); |
||||
|
1 ignored issue
–
show
The function
plugin_load was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 77 | $rows = $remote->getAggregationData( |
||||
| 78 | [$tablename], |
||||
| 79 | ['%rowid%'], |
||||
| 80 | [['logic'=> 'and', 'condition' => "checkinid = $checkinid"]] |
||||
| 81 | ); |
||||
| 82 | |||||
| 83 | $pids = array_column($rows, '%rowid%'); |
||||
| 84 | |||||
| 85 | if (empty($pids)) { |
||||
| 86 | return; |
||||
| 87 | } |
||||
| 88 | foreach ($pids as $pid) { // should only be a single entry |
||||
| 89 | $schemadata = AccessTable::byTableName($tablename, $pid); |
||||
| 90 | if (!$schemadata->getSchema()->isEditable()) { |
||||
| 91 | throw new StructException('lookup delete error: no permission for schema'); |
||||
| 92 | } |
||||
| 93 | $schemadata->clearData(); |
||||
| 94 | } |
||||
| 95 | } |
||||
| 96 | } |
||||
| 97 |
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