From a6413da67a4579866f0fd0323ddb23a7b6b9654a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 18 Sep 2026 17:00:53 +0000
Subject: [PATCH] =Cleaning up the Integrations setup a bit, started the Helcim integration work too

---
 inc/integrations/Integrations.php |   47 +++++++++++++++++++++++------------------------
 1 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/inc/integrations/Integrations.php b/inc/integrations/Integrations.php
index f055894..d6ff18f 100644
--- a/inc/integrations/Integrations.php
+++ b/inc/integrations/Integrations.php
@@ -3,6 +3,7 @@
 
 use Exception;
 use JVBase\managers\Cache;
+use JVBase\managers\queue\Queue;
 use JVBase\managers\UploadManager;
 use JVBase\registrar\Registrar;
 use WP_Error;
@@ -59,6 +60,7 @@
 		$this->userID = $userID;
 		$this->cache = Cache::for('integrations_' . $this->cacheName);
 
+
 		$this->getPostTypes();
 		$this->getTaxonomies();
 		$this->getUsers();
@@ -176,7 +178,7 @@
 
 			return $this->response(false, 'Failed to save credentials to database');
 
-		} catch (\Exception $e) {
+		} catch (Exception $e) {
 			// Revert to old credentials on any error
 			$old = Auth::getInstance()->getCredentials(
 				$this->service_name,
@@ -245,7 +247,7 @@
 	public function testConnection(bool $force = false): bool
 	{
 		if (!$this->isSetUp()) {
-			return false;
+			return true;
 		}
 		$this->ensureInitialized();
 
@@ -253,16 +255,9 @@
 			return false;
 		}
 
-		// Cache test results to avoid excessive API calls
-		$cacheKey = "connection_test_$this->service_name" . ($this->userID ? "_$this->userID" : '');
-		$cached = $this->cache->get($cacheKey);
-
-		if ($cached !== false && !$force) {
-			return (bool)$cached;
-		}
 
 		try {
-			if ($this->isOAuthService && !$this->hasOAuthCredentials()){
+			if (!$this->hasOAuthCredentials()){
 				//If this is an OAuth service, we might only be saving the app credentials first
 				$result = true;
 			} else {
@@ -270,11 +265,9 @@
 			}
 
 			$this->updateLastTestedTime();
-			$this->cache->set($cacheKey, $result, 300); // Cache for 5 minutes
 			return $result;
 		} catch (Exception $e) {
-			$this->logError('Connection test failed', ['error' => $e->getMessage()]);
-			$this->cache->set($cacheKey, false, 60); // Cache failure for 1 minute
+			$this->logError('testConnection', $e->getMessage());
 			return false;
 		}
 	}
@@ -337,7 +330,7 @@
 		array $data,
 		array $options = []
 	):bool {
-		$queue = JVB()->queue();
+		$queue = Queue::getInstance();
 
 		$queued =  $queue->queueOperation(
 			$type,
@@ -400,8 +393,11 @@
 
 
 		if (!empty($this->syncPostTypes)) {
-			$this->addSavePost();
-			add_action('transition_post_status', [$this, 'handlePostStatusTransition'], 10, 3);
+			if (method_exists($this, 'addSavePost')) {
+				$this->addSavePost();
+			}
+
+//			add_action('transition_post_status', [$this, 'handlePostStatusTransition'], 10, 3);
 
 			if ($this->canSync['delete']) {
 				add_action('before_delete_post', [$this, 'handleDeletePost'], 10, 1);
@@ -472,7 +468,7 @@
 				'message' => 'Connection established successfully'
 			];
 
-		} catch (\Exception $e) {
+		} catch (Exception $e) {
 			return [
 				'success' => false,
 				'message' => 'Error: ' . $e->getMessage()
@@ -489,10 +485,7 @@
 
 	public function hasOAuthCredentials(?int $userID = null): bool
 	{
-		if ($userID !== $this->userID) {
-			$this->switchUser($userID);
-		}
-		return $this->hasOAuth && $this->hasValidOAuth();
+		return false;
 	}
 
 
@@ -546,7 +539,7 @@
 
 	public static function hasExtraOptions():bool
 	{
-		return static::getInstance()::$hasExtraOptions;
+		return self::$hasExtraOptions;
 	}
 
 	/**
@@ -606,8 +599,8 @@
 		if ($jpegVersion !== '' && is_int($jpegVersion)) {
 			return $jpegVersion;
 		}
-		$uploader = new UploadManager();
-		$converted = $uploader->convertImageTo($imgID, 'jpeg', 80, false);
+		$uploader = UploadManager::getInstance();
+		$converted = $uploader->convertImageTo($imgID, 'jpeg');
 		if ($converted && !is_wp_error($converted)) {
 			update_post_meta($imgID, BASE . 'jpeg_version', $converted['attachment_id']);
 			return $converted['attachment_id'];
@@ -619,6 +612,7 @@
 
 	/**
 	 * Used by JVBase\registrar\helpers\AddIntegrationFields.php
+	 * @param string|null $content_type
 	 * @return array
 	 */
 	public function getAdditionalFields(?string $content_type = null):array
@@ -631,4 +625,9 @@
 		return $this->icon;
 	}
 
+	public function getUserID():?int
+	{
+		return $this->userID;
+	}
+
 }

--
Gitblit v1.10.0