-
Notifications
You must be signed in to change notification settings - Fork 20
/
helper.php
65 lines (59 loc) · 1.89 KB
/
helper.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
<?php
use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\prosemirror\parser\SyntaxTreeBuilder;
use dokuwiki\plugin\sentry\Event;
/**
* DokuWiki Plugin prosemirror (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
class helper_plugin_prosemirror extends Plugin
{
/**
* Decode json and parse the data back into DokuWiki Syntax
*
* @param string $unparsedJSON the json produced by Prosemirror
*
* @return null|string DokuWiki syntax or null on error
*/
public function getSyntaxFromProsemirrorData($unparsedJSON)
{
$prosemirrorData = json_decode($unparsedJSON, true);
if ($prosemirrorData === null) {
$errorMsg = 'Error decoding prosemirror json ' . json_last_error_msg();
throw new RuntimeException($errorMsg);
}
$rootNode = SyntaxTreeBuilder::parseDataIntoTree($prosemirrorData);
$syntax = $rootNode->toSyntax();
return $syntax;
}
/**
* Try to log an error to sentry if the sentry plugin exists
*
* @param Throwable $exception
* @param array $extraData associative array for sentries `extra` field
*
* @return bool true if the exception has been logged to sentry, false otherwise
*/
public function tryToLogErrorToSentry(Throwable $exception, array $extraData = [])
{
global $ID;
/** @var helper_plugin_sentry $sentry */
$sentry = plugin_load('helper', 'sentry');
if (!$sentry) {
return false;
}
$sentryEvent = new Event([
'extra' => $extraData,
'tags' => [
'plugin' => 'prosemirror',
'id' => $ID,
],
]);
$sentryEvent->addException($exception);
$sentry->logEvent($sentryEvent);
return true;
}
}
// vim:ts=4:sw=4:et: