From 57b7b8407805ddc01e6a60a086187d5842e05923 Mon Sep 17 00:00:00 2001 From: Esdras Caleb Oliveira Silva Date: Fri, 12 Jul 2024 16:45:12 -0300 Subject: [PATCH] tested and ok --- classes/helper.php | 36 +++++++++++++++++++++++++++++++++--- db/upgrade.php | 13 +++++++++++++ lang/en/tool_sentry.php | 6 +++--- settings.php | 5 +++-- version.php | 2 +- 5 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 db/upgrade.php diff --git a/classes/helper.php b/classes/helper.php index 797731a..f989f01 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -43,11 +43,41 @@ class helper { * @param \core\event\base $event The event. * @return void */ - public static function init(\core\event\base $event) { + public static function init(\core\event\base $event=null) { $config = get_config('tool_sentry'); if ($config->activate) { unset($config->activate); - \Sentry\init((array)$config); + unset($config->dns); + unset($config->version); + if ($config->ignore_exceptions=="") { + unset($config->ignore_exceptions); + } + if ($config->ignore_transactions=="") { + unset($config->ignore_transactions); + } + if ($config->in_app_exclude=="") { + unset($config->in_app_exclude); + } + if ($config->in_app_include=="") { + unset($config->in_app_include); + } + $config->enable_tracing = boolval($config->enable_tracing); + $config->attach_stacktrace = boolval($config->attach_stacktrace); + $config->send_default_pii = boolval($config->send_default_pii); + $config = (array) $config; + + foreach ($config as $name => $value) { + if(is_numeric($value)){ + if(strpos($value,'.')) { + $config[$name] = floatval($value); + } + else{ + $config[$name] = intval($value); + } + } + } + + \Sentry\init($config); } } @@ -57,7 +87,7 @@ public static function init(\core\event\base $event) { * @param \core\event\base $event The event. * @return void */ - public static function geterros(\core\event\base $event) { + public static function geterros(\core\event\base $event=null) { $config = get_config('tool_sentry'); if ($config->activate) { \Sentry\captureLastError(); diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..efb0f2a --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,13 @@ +get_manager(); // Loads ddl manager and xmldb classes. + + if ($oldversion < 2024071200) { + $DB->delete_records("mdl_config_plugins",[ 'plugin'=>'tool_sentry','name'=>'dns']); + } + + return true; +} \ No newline at end of file diff --git a/lang/en/tool_sentry.php b/lang/en/tool_sentry.php index b826c2b..3a40362 100644 --- a/lang/en/tool_sentry.php +++ b/lang/en/tool_sentry.php @@ -31,8 +31,8 @@ $string['sentry_options_desc'] = "This Change the way the options are sent to sentry"; $string['activate'] = "Activate Sentry Plugin"; $string['activate_desc'] = "Activate Sentry to send information to the configured dns"; -$string['dns'] = "Sentry Server DNS"; -$string['dns_desc'] = "Sentry server address with auth token"; +$string['dsn'] = "Sentry Server DSN"; +$string['dsn_desc'] = "Sentry server address with auth token"; $string['privacy:metadata'] = 'The plugin does not store any personal data. However, it send the IP of a user that had an error to the sentry server configured in it.'; $string['release'] = "Sentry Release"; $string['release_desc'] = "Sets the release. If not set, the SDK will try to automatically configure a release out of the box but it's a better idea to manually set it to guarantee that the release is in sync with your deploy integrations."; @@ -69,6 +69,6 @@ $string['ignore_transactions'] = "Ignore Transactions"; $string['ignore_transactions_desc'] = "A list of strings that match transaction names that shouldn't be sent to Sentry."; $string['in_app_include'] = "In App Include"; -$string['ignore_transactions_desc'] = "A list of string prefixes of module names that belong to the app. This option takes precedence over in-app-exclude."; +$string['in_app_include_desc'] = "A list of string prefixes of module names that belong to the app. This option takes precedence over in-app-exclude."; $string['in_app_exclude'] = "In App Exnclude"; $string['in_app_exclude_desc'] = "A list of string prefixes of module names that do not belong to the app, but rather to third-party packages. Modules considered not part of the app will be hidden from stack traces by default."; diff --git a/settings.php b/settings.php index e491293..10c9f57 100644 --- a/settings.php +++ b/settings.php @@ -34,8 +34,8 @@ get_string('options_desc', 'tool_sentry'))); $page->add(new admin_setting_configcheckbox('tool_sentry/activate', get_string('activate', 'tool_sentry'), get_string('activate_desc', 'tool_sentry'), 1)); - $page->add(new admin_setting_configtext('tool_sentry/dns', get_string('dns', 'tool_sentry'), - get_string('dns_desc', 'tool_sentry'), 'https://USERCODE@CLIENTCODE.ingest.sentry.io/CLIENTCODE')); + $page->add(new admin_setting_configtext('tool_sentry/dsn', get_string('dsn', 'tool_sentry'), + get_string('dsn_desc', 'tool_sentry'), 'https://USERCODE@CLIENTCODE.ingest.sentry.io/CLIENTCODE')); $page->add(new admin_setting_heading('tool_sentry/sentry_options', get_string('sentry_options', 'tool_sentry'), get_string('sentry_options_desc', 'tool_sentry'))); $page->add(new admin_setting_configtext('tool_sentry/release', get_string('release', 'tool_sentry'), @@ -111,3 +111,4 @@ } } +\tool_sentry\helper::geterros(); \ No newline at end of file diff --git a/version.php b/version.php index 6a7d582..cb742da 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); // Plugin version. -$plugin->version = 2024071010; +$plugin->version = 2024071210; // Required Moodle version. $plugin->requires = 2018051718; // Requires this Moodle version - at least 3.5 (new messsage system).