From e6672fe38ce5d99f3b3f026154f777aded7361de Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 29 Jan 2026 17:36:53 +0000
Subject: [PATCH] =Starting refactor of Meta and Routes to fluent-style

---
 inc/rest/routes/UploadRoutes.php |   31 +++++++++----------------------
 1 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/inc/rest/routes/UploadRoutes.php b/inc/rest/routes/UploadRoutes.php
index 1da0412..c0016bf 100644
--- a/inc/rest/routes/UploadRoutes.php
+++ b/inc/rest/routes/UploadRoutes.php
@@ -57,7 +57,7 @@
 		));
 
 		// Metadata updates
-		$registry->register('update_metadata', new TypeConfig(
+		$registry->register('update_image_meta', new TypeConfig(
 			executor: $executor
 		));
 
@@ -797,23 +797,15 @@
 			}
 			$pending = [];
 			$attachments = array_filter($items, function ($item) {
-				return array_key_exists('attachmentId', $item);
+				return array_key_exists('attachmentId', $item) || array_key_exists('uploadId', $item);
 			});
-			if (count($attachments) !== count($items)) {
-				$pending = array_filter($items, function ($item) {
-					return array_key_exists('uploadId',$item);
-				});
-			}
 
 
 			if (!empty($attachments)) {
-				// Phase 2B: Direct attachment update (images already processed)
-				return $this->updateMeta($attachments, $data['user']);
+				error_log('Attachments: '.print_r($attachments, true));
+				return $this->queueMetaUpdate($attachments, $data['user']);
 			}
-			elseif (!empty($pending)) {
-				// Phase 2A: Queue metadata update with dependency on upload operation
-				return $this->queueMetaUpdate($pending, $data['user']);
-			}
+
 
 			return $this->sendResponse(
 				false,
@@ -849,6 +841,7 @@
 		foreach ($data as $info) {
 			try {
 				$attachment_id = $info['attachmentId'];
+				error_log('Updating attachment ID:'.print_r($attachment_id,true));
 				$ids[] = $attachment_id;
 				unset($info['attachmentId']);
 				// Verify attachment exists and user has permission
@@ -887,22 +880,16 @@
 		$errors = [];
 		$original = count($data);
 		foreach ($data as $uploadID => $info) {
-			if (!array_key_exists('depends_on', $info)) {
-				unset($data[$uploadID]);
-				$errors[$uploadID] = $info;
-				continue;
-			}
-			if (!in_array($info['depends_on'], $depends_on)) {
+			if (array_key_exists('depends_on', $info) && !in_array($info['depends_on'], $depends_on)) {
 				$depends_on[] = $info['depends_on'];
 			}
 		}
 		$operationID = $queue->queueOperation(
-			'update_metadata',
+			'update_image_meta',
 			$user,
 			$data,
 			[
 				'depends_on' => $depends_on,
-				'priority' => 'medium',
 			]
 		);
 
@@ -929,7 +916,7 @@
 			$errors = [];
 			foreach ($operation->depends_on as $dependency) {
 				$operationData = JVB()->queue()->getOperation($dependency);
-				if (!$operationData || $operationData->status !== 'completed') {
+				if (!$operationData || $operationData->state !== 'completed') {
 					throw new Exception('Original upload operation not found or not completed');
 				}
 

--
Gitblit v1.10.0