From c0028163dc9fe32d62d3e200b1dd00c3c070d38a Mon Sep 17 00:00:00 2001 From: Adam Milward Date: Wed, 6 Sep 2023 15:25:48 +0100 Subject: [PATCH] add environment variables to settings --- composer.json | 2 +- src/models/Settings.php | 19 +++++++++++++++++++ src/services/EventbriteEvents.php | 8 ++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index fb1862d..14e2f0c 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "adigital/eventbrite", "description": "Integration with Eventbrite API", "type": "craft-plugin", - "version": "2.0.1", + "version": "2.0.2", "keywords": [ "craft", "cms", diff --git a/src/models/Settings.php b/src/models/Settings.php index d04d4c6..1d1c3c5 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -63,4 +63,23 @@ public function rules() : array ['organisationId', 'default', 'value' => ''], ]; } + + public function authToken(): string + { + if (substr($this->authToken, 0, 1) === '$') { + $f = getenv(substr($this->authToken, 1)) ?: ''; + return $f; + } else { + return $this->authToken; + } + } + + public function organisationId(): string + { + if (substr($this->organisationId, 0, 1) === '$') { + return getenv(substr($this->organisationId, 1)) ?: ''; + } else { + return $this->organisationId; + } + } } diff --git a/src/services/EventbriteEvents.php b/src/services/EventbriteEvents.php index b063007..bc86b41 100644 --- a/src/services/EventbriteEvents.php +++ b/src/services/EventbriteEvents.php @@ -46,7 +46,7 @@ class EventbriteEvents extends Component public function getOrganisationEvents($expansions = null, $time_filter = "current_future", $unlistedEvents = false, $status = "live") : array { $settings = Eventbrite::$plugin->getSettings(); - $organisationId = $settings->organisationId; + $organisationId = $settings->organisationId(); $method = "/v3/organizations/" . $organisationId . "/events/?status=" . $status . "&time_filter=" . $time_filter; if (!empty($expansions)) @@ -143,7 +143,7 @@ public function getEvent($eventId, $expansions = null, $fullDescription = true, $event = $this->curlWrap($method); $otherEventIds = array_column(json_decode(Eventbrite::$plugin->nonAdminSettings->get()->one()->otherEventIds), 0); - if (($unlistedEvent === false && $event['listed'] === false) || ($event['organization_id'] != Eventbrite::$plugin->getSettings()->organisationId && !array_search($eventId, $otherEventIds))) + if (($unlistedEvent === false && $event['listed'] === false) || ($event['organization_id'] != Eventbrite::$plugin->getSettings()->organisationId() && !array_search($eventId, $otherEventIds))) { $event = null; } @@ -212,7 +212,7 @@ public function getAllEvents($expansions = null, $sort = true, $time_filter = "c public function getOrganizationVenues() : array { $settings = Eventbrite::$plugin->getSettings(); - $organisationId = $settings->organisationId; + $organisationId = $settings->organisationId(); $method = "/v3/organizations/" . $organisationId . "/venues/"; $organisationVenues = $this->curlWrap($method); @@ -338,7 +338,7 @@ private function buildEventMethodQueryString($startOfQueryString, $expansions) : private function curlWrap($method, $request = null) : mixed { $settings = Eventbrite::$plugin->getSettings(); - $authToken = $settings->authToken; + $authToken = $settings->authToken(); $host = 'www.eventbriteapi.com'; $headers = [ 'Host: '.$host,