From b38f03c0e7218762d90fa5092696b127f24f36db Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 25 Jan 2026 07:07:26 +0000
Subject: [PATCH] =Some logical flaws in Queue.php, Queue.js, ContentExecutor.php, UploadExecutor.php - particularly with timeline ordering, frontend queue updates, etc
---
inc/managers/queue/Queue.php | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/inc/managers/queue/Queue.php b/inc/managers/queue/Queue.php
index 66ceed0..ce213f2 100644
--- a/inc/managers/queue/Queue.php
+++ b/inc/managers/queue/Queue.php
@@ -61,6 +61,36 @@
try {
$incoming = $this->buildOperation($type, $userId, $data, $options);
$mergeable = $this->registry->getMergeable($type);
+ $existingById = $this->storage->find($incoming->id);
+
+ if ($existingById) {
+ // Operation with this ID already exists
+ if (in_array($existingById->state, ['pending', 'scheduled']) && $mergeable) {
+ // Still pending and mergeable, merge into it
+ $merged = $mergeable->merge($existingById, $incoming);
+ $this->storage->save($merged);
+ $this->runQueueOnShutdown();
+
+ return [
+ 'success' => true,
+ 'operation_id' => $merged->id,
+ 'updated_existing' => true,
+ ];
+ } else {
+ // Already processing/completed, or not mergeable - generate new ID
+ $incoming->id = 'u' . $userId . '_' . time() . '_' . uniqid();
+
+ JVB()->error()->log(
+ '[Queue]:add',
+ 'Duplicate ID for non-mergeable operation, generated new ID',
+ [
+ 'type' => $type,
+ 'existing_state' => $existingById->state,
+ ],
+ 'warning'
+ );
+ }
+ }
if ($mergeable) {
$existing = $this->storage->findMergeable($type, $userId);
--
Gitblit v1.10.0