From 5c5cb858a61f641869df64beecd29f5960096f87 Mon Sep 17 00:00:00 2001 From: lukeyouell <> Date: Tue, 12 Mar 2019 15:59:10 +0000 Subject: [PATCH 1/2] reinstated the enabled setting --- CHANGELOG.md | 5 +++++ README.md | 1 + src/models/Settings.php | 6 ++++++ src/services/SentryService.php | 5 +++++ src/templates/settings.twig | 12 +++++++++++- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cb7afa..91fcefc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## 1.5.1 - 2019-03-12 + +### Added +- Reinstated the `enabled` setting [#17](https://github.com/lukeyouell/craft-sentry/issues/17) + ## 1.5.0 - 2019-02-14 ### Added diff --git a/README.md b/README.md index 538f279..eb84bed 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Here’s what that config file might look like along with a list of all of the p true, 'clientDsn' => '$SENTRY_DSN', // NOT getenv('SENTRY_DSN') 'environment' => '$SENTRY_ENVIRONMENT', // NOT getenv('SENTRY_ENVIRONMENT') 'excludedCodes' => '400, 404, 429', // Comma-separated list diff --git a/src/models/Settings.php b/src/models/Settings.php index cb4f804..f0c25a3 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -12,6 +12,11 @@ class Settings extends Model // Public Properties // ========================================================================= + /** + * @var boolean + */ + public $enabled = true; + /** * @var string */ @@ -33,6 +38,7 @@ class Settings extends Model public function rules() { return [ + ['enabled', 'boolean'], [['clientDsn', 'environment', 'excludedCodes'], 'string'], [['clientDsn', 'environment'], 'required'], ]; diff --git a/src/services/SentryService.php b/src/services/SentryService.php index 3497cc0..9ccba96 100644 --- a/src/services/SentryService.php +++ b/src/services/SentryService.php @@ -40,6 +40,11 @@ public function init() public function handleException($exception) { + if (!$this->settings->enabled) { + Craft::info('Exception not reported to Sentry as the plugin is disabled.', $this->plugin->handle); + return; + } + if (!$this->settings->clientDsn) { Craft::error('Failed to report exception due to missing client key (DSN)', $this->plugin->handle); return; diff --git a/src/templates/settings.twig b/src/templates/settings.twig index dcaede3..8481ba0 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -10,8 +10,18 @@ {% from _self import configWarning %} -{{ forms.autosuggestField({ +{{ forms.lightswitchField({ first: true, + label: "Enabled"|t(plugin.handle), + instructions: "If disabled, the plugin will not report exceptions to Sentry."|t(plugin.handle), + id: 'enabled', + name: 'enabled', + on: settings.enabled, + disabled: 'enabled' in overrides, + warning: 'enabled' in overrides ? configWarning(plugin, 'enabled') +}) }} + +{{ forms.autosuggestField({ required: true, label: "Client Key (DSN)"|t(plugin.handle), instructions: "To send data to Sentry you will need to configure an SDK with a client key which can be found in your [project settings](https://sentry.io/settings/) underneath 'Client Keys (DSN)'."|t(plugin.handle), From d8b5ee9a991c757d4ab9d7b082c05095b6115f54 Mon Sep 17 00:00:00 2001 From: lukeyouell <> Date: Tue, 12 Mar 2019 15:59:16 +0000 Subject: [PATCH 2/2] 1.5.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5bc754..132d391 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "lukeyouell/craft-sentry", "description": "Error tracking that helps developers monitor and fix crashes in real time. Iterate continuously. Boost efficiency. Improve user experience.", "type": "craft-plugin", - "version": "1.5.0", + "version": "1.5.1", "keywords": [ "craft", "cms",