Jake Vanderwerf
2026-01-25 b38f03c0e7218762d90fa5092696b127f24f36db
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);