From d7e7d248cbe41cd7a9ef9c2fb022b6c4831f99a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 31 May 2026 15:22:56 +0000
Subject: [PATCH] =jakevan complete
---
inc/managers/queue/executors/UploadExecutor.php | 68 ++++++++++++++++++++++++++++++---
1 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/inc/managers/queue/executors/UploadExecutor.php b/inc/managers/queue/executors/UploadExecutor.php
index 8187500..5f244d6 100644
--- a/inc/managers/queue/executors/UploadExecutor.php
+++ b/inc/managers/queue/executors/UploadExecutor.php
@@ -8,6 +8,7 @@
use Exception;
use JVBase\registrar\Registrar;
use JVBase\base\Site;
+use WP_Error;
if (!defined('ABSPATH')) {
exit;
@@ -209,7 +210,43 @@
}
if (!empty($data['field_name'])) {
- $this->saveToMeta($data, $uploadResults);
+ if ($data['field_name'] === 'timeline_gallery') {
+ $registrar = Registrar::getInstance($data['content']);
+ if ($registrar) {
+ switch ($registrar->getType()) {
+ case 'post':
+ $meta = Meta::forPost($data['item_id']);
+ break;
+ case 'term':
+ $meta = Meta::forTerm($data['item_id']);
+ break;
+ case 'user':
+ $meta = Meta::forUser($data['item_id']);
+ break;
+ default:
+ $meta = false;
+
+ }
+ if ($meta) {
+ $title = $meta->get('post_title');
+ $current = $meta->get('number');
+ $i = empty($current) ? 1 : $current + 1;
+ foreach ($data['upload_ids'] as $uploadID) {
+ if (!array_key_exists($uploadID, $uploadResults)) {
+ continue;
+ }
+ $imgID = $uploadResults[$uploadID]['attachment_id'] ?? false;
+ if (!$imgID) {
+ continue;
+ }
+ $this->createTimelinePoint($imgID, $data['item_id'], $data['user'], $data['content'], $title, $i);
+ $i++;
+ }
+ }
+ }
+ } else {
+ $this->saveToMeta($data, $uploadResults);
+ }
}
$progress->advance(1);
@@ -220,6 +257,25 @@
);
}
+ protected function createTimelinePoint(int $imgID, int $parentID, int $user, string $postType, string $baseTitle, int $index):int|WP_Error
+ {
+ $title = $baseTitle.' - Treatment #'.$index;
+ $args = [
+ 'post_type' => jvbCheckBase($postType),
+ 'post_author' => $user,
+ 'post_status' => 'draft',
+ 'post_parent' => $parentID,
+ 'post_title' => $title,
+ 'post_name' => sanitize_title($title)
+ ];
+
+ $child = wp_insert_post($args);
+ if ($child && !is_wp_error($child)) {
+ set_post_thumbnail($child, $imgID);
+ }
+ return $child;
+ }
+
/**
* Process metadata updates for attachments
*/
@@ -538,7 +594,7 @@
'post_author' => $user,
'post_status' => 'draft',
'post_title' => $title,
- 'post_slug' => sanitize_title($title),
+ 'post_name' => sanitize_title($title),
'post_excerpt' => $excerpt
];
@@ -582,12 +638,10 @@
foreach($childPosts as $i => $imgID) {
$treatment = $i + 1;
- $args ['post_title'] = $title.' - Treatment #'.$treatment;
- $child = wp_insert_post($args);
- if ($child && !is_wp_error($child)) {
- $createdChildren = $child;
+ $child = $this->createTimelinePoint($imgID, $parent, $args['post_author'], $args['post_type'], $title, $treatment);
+ if ($child && !is_wp_error($child) && $child> 0 ) {
+ $createdChildren[] = $child;
$usedUploads[] = $imgID;
- set_post_thumbnail($child, $imgID);
}
}
}
--
Gitblit v1.10.0