From 2127b1bdd73ecd2423e443992da4b442f5a3c1a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 04 Feb 2026 21:19:25 +0000
Subject: [PATCH] =Major overhaul of MetaManager.php -> Meta.php and RestRouteManager.php -> Rest.php. Seems to work for JakeVan
---
inc/managers/queue/executors/UploadExecutor.php | 82 +++++++++++++++++++++++------------------
1 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/inc/managers/queue/executors/UploadExecutor.php b/inc/managers/queue/executors/UploadExecutor.php
index 7461cfd..c92fee3 100644
--- a/inc/managers/queue/executors/UploadExecutor.php
+++ b/inc/managers/queue/executors/UploadExecutor.php
@@ -3,7 +3,7 @@
use JVBase\managers\queue\{Executor, Operation, Progress, Result};
use JVBase\managers\UploadManager;
-use JVBase\meta\MetaManager;
+use JVBase\meta\Meta;
use Exception;
use JVBase\utility\Features;
@@ -14,7 +14,7 @@
/**
* Executor for upload-related queue operations.
* Handles: image_upload, video_upload, document_upload,
- * update_metadata, temporary_cleanup, attach_upload_to_content, process_upload_groups
+ * update_image_meta, temporary_cleanup, attach_upload_to_content, process_upload_groups
*/
final class UploadExecutor implements Executor
{
@@ -22,7 +22,7 @@
'image_upload',
'video_upload',
'document_upload',
- 'update_metadata',
+ 'update_image_meta',
'temporary_cleanup',
'attach_upload_to_content',
'process_upload_groups'
@@ -41,7 +41,7 @@
'image_upload' => $this->processFileUpload($operation, $data, 'image', $progress),
'video_upload' => $this->processFileUpload($operation, $data, 'video', $progress),
'document_upload' => $this->processFileUpload($operation, $data, 'document', $progress),
- 'update_metadata' => $this->processMetadataUpdate($operation, $data, $progress),
+ 'update_image_meta' => $this->processMetaUpdate($operation, $data, $progress),
'temporary_cleanup' => $this->processTemporaryCleanup($operation, $data, $progress),
'attach_upload_to_content'=> $this->processAttachToContent($operation, $data, $progress),
'process_upload_groups' => $this->processUploadGroups($operation, $data, $progress),
@@ -176,29 +176,39 @@
/**
* Process metadata updates for attachments
*/
- private function processMetadataUpdate(Operation $operation, array $data, Progress $progress): Result
+ private function processMetaUpdate(Operation $operation, array $data, Progress $progress): Result
{
$updatedCount = 0;
$errors = [];
foreach ($data as $uploadId => $info) {
- if (!is_array($info) || empty($info['depends_on'])) {
+ if (!is_array($info)) {
continue;
}
try {
- // Get the dependency operation to find attachment ID
- $depOp = JVB()->queue()->get($info['depends_on']);
- if (!$depOp || !$depOp->result) {
- $errors[] = "Dependency {$info['depends_on']} not found or has no result";
+ if (array_key_exists('depends_on', $info)) {
+ // Get the dependency operation to find attachment ID
+ $depOp = JVB()->queue()->get($info['depends_on']);
+ if (!$depOp || !$depOp->result) {
+ $errors[] = "Dependency {$info['depends_on']} not found or has no result";
+ continue;
+ }
+ $attachmentId = $this->findAttachmentByUploadId($uploadId, $depOp->result);
+ if (!$attachmentId) {
+ $errors[] = "No attachment found for upload ID: {$uploadId}";
+ continue;
+ }
+ } else {
+ $attachmentId = $info['attachmentId']??false;
+ }
+
+ if (!$attachmentId) {
+ $errors[] = "No attachment found for: ".print_r($info, true);
continue;
}
- $attachmentId = $this->findAttachmentByUploadId($uploadId, $depOp->result);
- if (!$attachmentId) {
- $errors[] = "No attachment found for upload ID: {$uploadId}";
- continue;
- }
+
$this->applyMeta($attachmentId, $info);
$updatedCount++;
@@ -356,11 +366,11 @@
}
if (!empty($gallery_attachment_ids)) {
- $meta = new MetaManager($newPostID, 'post');
+ $meta = Meta::forPost($newPostID);
$fields = jvbGetFields($content, 'post');
foreach($fields as $name => $config) {
if ($config['type'] === 'gallery') {
- $meta->updateValue($name, implode(',', $gallery_attachment_ids));
+ $meta->set($name, implode(',', $gallery_attachment_ids));
break;
}
}
@@ -484,21 +494,21 @@
private function applyMeta(int $attachmentId, array $metadata): void
{
- if (!empty($metadata['title'])) {
+ if (!empty($metadata['image-title'])) {
wp_update_post([
'ID' => $attachmentId,
- 'post_title' => sanitize_text_field($metadata['title']),
+ 'post_title' => sanitize_text_field($metadata['image-title']),
]);
}
- if (!empty($metadata['alt'])) {
- update_post_meta($attachmentId, '_wp_attachment_image_alt', sanitize_text_field($metadata['alt']));
+ if (!empty($metadata['image-alt-text'])) {
+ update_post_meta($attachmentId, '_wp_attachment_image_alt', sanitize_text_field($metadata['image-alt-text']));
}
- if (!empty($metadata['caption'])) {
+ if (!empty($metadata['image-caption'])) {
wp_update_post([
'ID' => $attachmentId,
- 'post_excerpt' => sanitize_textarea_field($metadata['caption']),
+ 'post_excerpt' => sanitize_textarea_field($metadata['image-caption']),
]);
}
}
@@ -532,11 +542,11 @@
return;
}
- $existing = $meta->getValue($data['field_name']);
+ $existing = $meta->get($data['field_name']);
$existingIds = !empty($existing) ? explode(',', $existing) : [];
$allIds = array_unique(array_merge($existingIds, $attachmentIds));
- $meta->updateValue($data['field_name'], implode(',', $allIds));
+ $meta->set($data['field_name'], implode(',', $allIds));
}
private function updateFieldValue(array $data, array $results): void
@@ -551,25 +561,25 @@
return;
}
- $existing = $meta->getValue($data['field_name']);
+ $existing = $meta->get($data['field_name']);
$existingIds = !empty($existing) ? explode(',', $existing) : [];
$allIds = array_unique(array_merge($existingIds, $attachmentIds));
- $meta->updateValue($data['field_name'], implode(',', $allIds));
+ $meta->set($data['field_name'], implode(',', $allIds));
}
- private function getMetaManager(array $data): ?MetaManager
+ private function getMetaManager(array $data): ?Meta
{
if (!empty($data['post_id'])) {
- return new MetaManager($data['post_id'], 'post');
+ return Meta::forPost($data['post_id']);
}
if (!empty($data['term_id'])) {
- return new MetaManager($data['term_id'], 'term');
+ return Meta::forTerm($data['term_id']);
}
if (!empty($data['user'])) {
$link = (int)get_user_meta($data['user'], BASE . 'link', true);
if ($link) {
- return new MetaManager($link, 'post');
+ return Meta::forPost($link);
}
}
return null;
@@ -616,14 +626,14 @@
if (str_starts_with($mimeType, 'image/')) {
set_post_thumbnail($postId, $attachmentId);
} elseif (str_starts_with($mimeType, 'video/')) {
- $meta = new MetaManager($postId, 'post');
- $meta->updateValue('video', $attachmentId);
+ $meta = Meta::forPost($postId);
+ $meta->set('video', $attachmentId);
} else {
- $meta = new MetaManager($postId, 'post');
- $existing = $meta->getValue('documents');
+ $meta = Meta::forPost($postId);
+ $existing = $meta->get('documents');
$existingIds = !empty($existing) ? explode(',', $existing) : [];
$existingIds[] = $attachmentId;
- $meta->updateValue('documents', implode(',', $existingIds));
+ $meta->set('documents', implode(',', $existingIds));
}
}
--
Gitblit v1.10.0