From d38d825e3484d822ea3c1f0fb1df37ecf386b18a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 04 Jan 2026 19:54:16 +0000
Subject: [PATCH] =TaxonomyCreator.js debugging

---
 inc/integrations/Integrations.php |   49 +++++++++++++------------------------------------
 1 files changed, 13 insertions(+), 36 deletions(-)

diff --git a/inc/integrations/Integrations.php b/inc/integrations/Integrations.php
index b1958bc..ff053aa 100644
--- a/inc/integrations/Integrations.php
+++ b/inc/integrations/Integrations.php
@@ -430,7 +430,6 @@
 		} else {
 			$result =  $this->$method();
 		}
-		error_log('Action result: '.print_r($result, true));
 		if (is_wp_error($result)) {
 			return [
 				'success' => false,
@@ -651,9 +650,7 @@
 		}
 
 		try {
-			error_log('Credentials to save: '.print_r($this->credentials, true));
 			if ($this->isOAuthService && !$this->hasOAuthCredentials()){
-				error_log('Just saving credentials, we don\'t have OAuth setup yet...');
 				//If this is an OAuth service, we might only be saving the app credentials first
 				$result = true;
 			} else {
@@ -762,10 +759,7 @@
 	): array|WP_Error
 	{
 		if (!$this->is_healthy) {
-			$this->logDebug('Skipping request - integration is unhealthy', [
-				'consecutive_errors' => $this->error_stats['consecutive_errors'],
-				'last_success' => $this->error_stats['last_success']
-			]);
+			return new WP_Error('unhealthy', 'Connection marked unhealthy. Skipping fetch');
 		}
 		$this->ensureInitialized();
 		if (!$this->isSetUp()){
@@ -786,15 +780,15 @@
 
 		while ($attempt < $this->maxRetries) {
 			try {
-				$this->logDebug('[Integrations] Making request to '.$this->service_name);
+//				$this->logDebug('[Integrations] Making request to '.$this->service_name);
 				$result = $this->executeRequest($method, $endpoint, $data, $baseKey, $options);
 				if (!$result) {
 					return new WP_Error('Request Error');
 				}
 				$this->recordRequest($method, $endpoint);
-				$this->logDebug('[Integrations]', [
-					'response' => $result
-				]);
+//				$this->logDebug('[Integrations]', [
+//					'response' => $result
+//				]);
 				// Reset error stats on success
 				$this->resetErrorStats();
 				return $result;
@@ -843,7 +837,7 @@
 			return null;
 		}
 
-		$this->logDebug("$method request to: $url: ".print_r($args, true));
+//		$this->logDebug("$method request to: $url: ".print_r($args, true));
 
 		// Make the request
 		$response = match($method) {
@@ -874,9 +868,9 @@
 			if ($retry_count === 0) {
 				$retry_count++;
 
-				$this->logDebug('Got 401, attempting token refresh...');
+//				$this->logDebug('Got 401, attempting token refresh...');
 				if ($this->refreshOAuthToken()) {
-					$this->logDebug('Token refreshed successfully, retrying request...');
+//					$this->logDebug('Token refreshed successfully, retrying request...');
 
 					// Rebuild request args with new token
 					$args = $this->buildRequestArgs($method, $data, $options);
@@ -932,7 +926,8 @@
 		if (!$force && $ttl > 0) {
 			$cached = $this->cache->get($cacheKey);
 			if ($cached !== false) {
-				$this->logDebug("Cache hit for: $cacheKey");
+
+//				$this->logDebug("Cache hit for: $cacheKey");
 				return $cached;
 			}
 		}
@@ -1390,7 +1385,7 @@
 					// Only attempt refresh once per request
 					if (!$this->token_refresh_attempted) {
 						$this->token_refresh_attempted = true;
-						$this->logDebug('OAuth token expired, attempting refresh');
+//						$this->logDebug('OAuth token expired, attempting refresh');
 
 						if (!$this->refreshOAuthToken()) {
 							$this->logError('Failed to refresh expired OAuth token - stopping execution');
@@ -1399,14 +1394,14 @@
 						}
 					} else {
 						// Already attempted refresh in this request
-						$this->logDebug('Token refresh already attempted, skipping');
+//						$this->logDebug('Token refresh already attempted, skipping');
 						return;
 					}
 				}
 				// Check if we should proactively refresh (before expiry)
 				elseif ($this->shouldRefreshToken() && !$this->token_refresh_attempted) {
 					$this->token_refresh_attempted = true;
-					$this->logDebug('OAuth token should be refreshed proactively');
+//					$this->logDebug('OAuth token should be refreshed proactively');
 					if (!$this->refreshOAuthToken()) {
 						$this->logError('Failed to proactively refresh OAuth token');
 						// Not critical - token is still valid, so continue
@@ -2141,45 +2136,36 @@
 	 */
 	public function handleSavePost(int $postID, WP_Post $post, bool $update): void
 	{
-		error_log('Testing For Save Post');
 		if (jvbNoSaveIt($postID, $post)) {
-			error_log('Excluded by jvbNoSaveIt');
 			return;
 		}
 		if (empty($this->syncPostTypes)) {
-			error_log('No Syncable post types');
 			return;
 		}
 
 		$config = JVB_CONTENT[jvbNoBase($post->post_type)]??null;
 		if (!$config) {
-			error_log('No Config set');
 			return;
 		}
 
 		$settings = $config['integrations'][$this->service_name]??null;
 		if (!$settings) {
-			error_log('No settings');
 			return;
 		}
 
 		$fields = $this->getSyncFields($postID, 'post', ['schedule_'.$this->service_name]);
-		error_log('Fields to check: '.print_r($fields, true));
 		if (!$fields['share_to_'.$this->service_name]) {
 			return;
 		}
 
 		$isShared = isset($fields["_{$this->service_name}_item_id"]);
 		if ($update && $isShared && !$fields['_keep_synced_'.$this->service_name]) {
-			error_log('Do not keep synced, not syncing with '.$this->service_name);
 			return;
 		}
 
 		if ($post->post_status !== 'publish' && !$isShared) {
-			error_log('Not published and not already shared');
 			return;
 		}
-		error_log('Sending to integration for processing...');
 		$this->handleTheSavePost($postID, $post, $update, $settings);
 	}
 
@@ -2652,11 +2638,6 @@
 		];
 		$this->is_healthy = true;
 		$this->saveErrorStats();
-
-		$this->logDebug('Integration health manually reset', [
-			'reset_by' => get_current_user_id(),
-			'reset_time' => time()
-		]);
 	}
 
 	/**
@@ -2791,9 +2772,6 @@
 
 		// Check for duplicate processing (idempotency)
 		if ($this->isWebhookProcessed($payload)) {
-			$this->logDebug('Webhook already processed', [
-				'webhook_id' => $this->extractWebhookId($payload)
-			]);
 			return true; // Return true to prevent retries
 		}
 
@@ -3206,7 +3184,6 @@
 		// Verify nonce
 		$nonce_field = 'jvb_integration_nonce_' . $service;
 		$nonce_action = 'jvb_integration_save_' . $service;
-		error_log('handleAdminPost: '.print_r($_POST, true));
 		if (!isset($_POST[$nonce_field]) || !wp_verify_nonce($_POST[$nonce_field], $nonce_action)) {
 			wp_die('Security check failed');
 		}

--
Gitblit v1.10.0