From c68aefb847b09daa0697de7684d3451e2e68ce1e Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 09 Jul 2026 23:10:23 +0000
Subject: [PATCH] =Refactor of Integrations.php to be a bit more useful with a suite of methods for create, update, delete back and forths for integrations where sharing is enabled. Also considering a single instance with a connect method to connect as the site (no user) vs connecting as an individual user - rather than recreating instances for every user.
---
inc/managers/queue/Queue.php | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/inc/managers/queue/Queue.php b/inc/managers/queue/Queue.php
index 4811116..aee981e 100644
--- a/inc/managers/queue/Queue.php
+++ b/inc/managers/queue/Queue.php
@@ -4,6 +4,7 @@
exit;
}
+use JVBase\managers\CustomTable;
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
@@ -27,6 +28,7 @@
add_action('jvb_process_queue', [$this, 'checkQueue']);
add_action('jvb_queue_maintenance', [$this, 'maintenance']);
+ add_action('jvb_daily_snapshot', [$this->storage, 'snapshotDaily']);
if (!wp_next_scheduled('jvb_process_queue')) {
wp_schedule_event(time(), 'every-minute', 'jvb_process_queue');
@@ -34,6 +36,11 @@
if (!wp_next_scheduled('jvb_queue_maintenance')) {
wp_schedule_event(time(), 'hourly', 'jvb_queue_maintenance');
}
+ if (!wp_next_scheduled('jvb_daily_snapshot')) {
+ // Schedule for next 3am
+ $next3am = strtotime('tomorrow 3am', current_time('timestamp'));
+ wp_schedule_event($next3am, 'daily', 'jvb_daily_snapshot');
+ }
jvb_register_do_once('queue_admin_action_registered', [$this, 'registerAdminAction']);
add_filter(BASE.'admin_action_filter', [$this, 'adminActionFilter'], 10, 3);
@@ -106,7 +113,9 @@
return null;
}
- $existing = $this->storage->findMergeable($incoming->type, $incoming->userId);
+ $criteria = $mergeable->matchCriteria($incoming);
+
+ $existing = $this->storage->findMergeable($incoming->type, $incoming->userId, $criteria);
if (!$existing || !$mergeable->canMerge($existing, $incoming)) {
return null;
}
@@ -334,7 +343,7 @@
// Use provided operation_id or generate one
$op->id = !empty($options['operation_id'])
? $options['operation_id']
- : 'u' . $userId . '_' . uniqid('op_');
+ : self::generateID($userId);
$op->type = $type;
$op->userId = $userId;
@@ -395,7 +404,7 @@
private function runQueueOnShutdown(): void
{
- if (!has_action('shutdown', [$this, 'processQueueOnShutdown'])) {
+ if (!has_action('shutdown', [$this, 'processQueueOnShutdown']) && $this->processor->hasAdequateResources()) {
add_action('shutdown', [$this, 'processQueueOnShutdown'], 100);
}
}
@@ -454,4 +463,9 @@
return $response;
}
}
+
+ public static function generateId(int $userID):string
+ {
+ return 'u' . $userID . '_' . uniqid('op_');
+ }
}
--
Gitblit v1.10.0