Jake Vanderwerf
2026-01-29 e6672fe38ce5d99f3b3f026154f777aded7361de
inc/managers/queue/executors/UploadExecutor.php
@@ -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++;
@@ -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']),
         ]);
      }
   }