From 772462eeca3002a1d52508aeba485aab2b4742ad Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 03 Mar 2026 19:06:19 +0000
Subject: [PATCH] =MAJOR OVERHAUL. Likely should have made a new branch ages ago. Key changes: Registrar.php is the base for custom post types, taxonomies, and user roles. Replaces JVB_CONTENT, JVB_TAXONOMY, and JVB_USER constants, eliminates most of Features.php (except for JVB_SITE, JVB_MEMBERSHIP), and has built in sanitizing and validation via sub-classes. Also started a major overhaul of the Schema output. Created a shit ton of property traits and classes to help sanitize and ensure proper data for different schema types. Still a bunch to do, but better to be starting committing changes here on this other branch.
---
inc/managers/queue/executors/ContentExecutor.php | 56 +++++++++++++++++++++++---------------------------------
1 files changed, 23 insertions(+), 33 deletions(-)
diff --git a/inc/managers/queue/executors/ContentExecutor.php b/inc/managers/queue/executors/ContentExecutor.php
index 7d4db57..e8b6e72 100644
--- a/inc/managers/queue/executors/ContentExecutor.php
+++ b/inc/managers/queue/executors/ContentExecutor.php
@@ -3,7 +3,7 @@
use JVBase\managers\queue\{Executor, Operation, Progress, Result, Storage};
use JVBase\meta\Meta;
-use JVBase\utility\Features;
+use JVBase\registrar\Registrar;
use Exception;
if (!defined('ABSPATH')) {
@@ -76,9 +76,11 @@
$results = [];
$errors = [];
+ $success = [];
$timelineParents = [];
$timelineStatus = [];
$timelineSharedFields = [];
+ $newPostsMap = [];
foreach ($posts as $id => $postData) {
try {
@@ -94,16 +96,14 @@
]);
if (!$newId || is_wp_error($newId)) {
+ $errors[$id] = 'Could not create post';
$progress->failItem($id, 'Could not create post');
continue;
}
+ $newPostsMap[$id] = $newId;
$this->savePostFields($newId, $postData);
- $results[$id] = [
- 'success' => true,
- 'new_id' => $newId,
- 'processed_fields' => array_keys($postData)
- ];
+ $success[$newId] = array_keys($postData);
$progress->advance();
continue;
}
@@ -116,12 +116,12 @@
}
$this->savePostFields((int)$id, $postData);
-
-
- if (Features::forContent($content)->has('is_timeline')) {
+ $registrar = Registrar::getInstance($content);
+ if ($registrar && $registrar->hasFeature('is_timeline')) {
$post = get_post((int)$id);
$parentId = $post->post_parent > 0 ? $post->post_parent : $post->ID;
- $sharedFields = array_keys(array_filter(JVB_CONTENT[$content]['fields'], function ($field) {
+ $fields = $registrar->getFields();
+ $sharedFields = array_keys(array_filter($fields, function ($field) {
return !array_key_exists('for_all', $field) || !$field['for_all'];
}));
@@ -142,19 +142,12 @@
}
}
}
- $results[$id] = [
- 'success' => true,
- 'processed_fields' => array_keys($postData)
- ];
- $progress->advance();
+ $success[$id] = array_keys($postData);
+ $progress->advance();
} catch (Exception $e) {
$progress->failItem($id, $e->getMessage());
$errors[$id] = $e->getMessage();
- $results[$id] = [
- 'success' => false,
- 'error' => $e->getMessage()
- ];
}
}
@@ -188,15 +181,13 @@
$outcome = count($errors) === count($posts) ? 'failed' : 'partial';
}
-
-
-
return new Result(
outcome: $outcome,
result: [
- 'posts' => $results,
+ 'posts' => $success,
'errors' => $errors,
- 'updated_count' => count(array_filter($results, fn($r) => $r['success'] ?? false)),
+ 'new_posts' => $newPostsMap,
+ 'updated_count' => count($success),
'failed_count' => count($errors)
]
);
@@ -205,7 +196,7 @@
private function savePostFields(int $postId, array $postData): bool
{
$content = $postData['content'] ?? '';
- $fields = jvbGetFields($content);
+ $fields = Registrar::getFieldsFor($content);
$allowedFields = array_filter($postData, function ($key) use ($fields) {
return array_key_exists($key, $fields);
@@ -215,9 +206,9 @@
return true;
}
- $meta = Meta::forPost($postId);
- $meta->setAll($allowedFields);
- return true;
+ return Meta::forPost($postId)
+ ->setAll($allowedFields)
+ ->save();
}
// ─────────────────────────────────────────────────────────────
@@ -318,7 +309,7 @@
foreach ($posts as $index => $post) {
$meta = Meta::forPost($post->ID);
if ($index === 0) {
- $meta->set('timeline', '', false);
+ $meta->set('timeline', '');
$previousPost = $post;
continue; // Parent has no timeline
}
@@ -329,7 +320,7 @@
if ($timeline) {
$termId = $this->getOrCreateTerm($timeline, 'timeline');
if ($termId) {
- $success = $meta->set('timeline', $termId, false);
+ $success = $meta->set('timeline', $termId);
}
}
}
@@ -337,7 +328,7 @@
if ($lastKey === $index) {
$latestTimestamp = strtotime($post->post_date);
}
-
+ $meta->save();
$previousPost = $post;
}
@@ -458,8 +449,7 @@
}
foreach ($children as $child) {
- $childMeta = Meta::forPost($child);
- $result = $childMeta->setAll($values, false);
+ Meta::forPost($child)->setAll($values)->save(false);
}
}
}
--
Gitblit v1.10.0