From 0113d2e9c9ff34a6ffb10707cc76d34b67a0c367 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 19 Jan 2026 16:29:41 +0000
Subject: [PATCH] =Refactored window.getTemplate into a full templating class window.jvbTemplates. Refactored CRUD.js, UploadManager.js, FormController.js, PopulateForm.js with that in mind
---
inc/integrations/Integrations.php | 64 ++++++++++++++-----------------
1 files changed, 29 insertions(+), 35 deletions(-)
diff --git a/inc/integrations/Integrations.php b/inc/integrations/Integrations.php
index 12b73ec..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 {
@@ -761,6 +758,9 @@
array $options = []
): array|WP_Error
{
+ if (!$this->is_healthy) {
+ return new WP_Error('unhealthy', 'Connection marked unhealthy. Skipping fetch');
+ }
$this->ensureInitialized();
if (!$this->isSetUp()){
$this->logError('Connection not setup for '.$this->service_name, [
@@ -780,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;
@@ -837,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) {
@@ -868,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);
@@ -926,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;
}
}
@@ -1384,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');
@@ -1393,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
@@ -1920,7 +1921,6 @@
return false;
}
- // Build refresh request data
$request_data = [
'client_id' => $this->credentials['client_id'],
'client_secret' => $this->credentials['client_secret'],
@@ -1928,12 +1928,24 @@
'grant_type' => 'refresh_token'
];
- // Use centralized OAuth request method
$response = $this->makeOAuthRequest('POST', $this->oauth['token'], $request_data);
if (is_wp_error($response)) {
+ $error_message = $response->get_error_message();
+
+ if (str_contains($error_message, 'invalid_grant')) {
+ $this->logError('OAuth refresh token is invalid - user must re-authorize', [
+ 'error' => $error_message
+ ], 'critical');
+
+ // Mark unhealthy immediately
+ $this->error_stats['consecutive_errors'] = $this->error_threshold;
+ $this->is_healthy = false;
+ $this->saveErrorStats();
+ }
+
$this->logError('Failed to refresh OAuth token for '.$this->service_name, [
- 'error' => $response->get_error_message()
+ 'error' => $error_message
]);
return false;
}
@@ -2124,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);
}
@@ -2635,11 +2638,6 @@
];
$this->is_healthy = true;
$this->saveErrorStats();
-
- $this->logDebug('Integration health manually reset', [
- 'reset_by' => get_current_user_id(),
- 'reset_time' => time()
- ]);
}
/**
@@ -2774,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
}
@@ -3189,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