From 235ce5716edc2f7cbe80fdccf26eac7269587839 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 08 Jun 2026 04:38:18 +0000
Subject: [PATCH] =FavouritesManager.php and FavouritesRoutes.php fixes. Moving all logic to FavouritesManager.php. Still some left to do

---
 inc/managers/queue/executors/ContentTermExecutor.php |   51 ++++++++++++++++++++++++---------------------------
 1 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/inc/managers/queue/executors/ContentTermExecutor.php b/inc/managers/queue/executors/ContentTermExecutor.php
index 9703cbe..67d1cfe 100644
--- a/inc/managers/queue/executors/ContentTermExecutor.php
+++ b/inc/managers/queue/executors/ContentTermExecutor.php
@@ -8,7 +8,7 @@
 use JVBase\managers\queue\Result;
 use JVBase\managers\RoleManager;
 use JVBase\meta\Meta;
-use JVBase\utility\Features;
+use JVBase\registrar\Registrar;
 use Exception;
 
 if (!defined('ABSPATH')) {
@@ -34,11 +34,12 @@
 
 	public function execute(Operation $operation, Progress $progress): Result
 	{
+		error_log('Executing Content Term.... ');
 		// Extract taxonomy from operation type (e.g., "shop_update" -> "shop")
-		$parts = explode('_', $operation->type);
-		$taxonomy = $parts[0] ?? '';
-
-		if (!$taxonomy || !isset(JVB_TAXONOMY[$taxonomy])) {
+		$data= $operation->requestData;
+		$taxonomy = $data['taxonomy']??false;
+		$registrar = $taxonomy? Registrar::getInstance($taxonomy) : false;
+		if (!$taxonomy || !$registrar) {
 			return Result::fail("Invalid taxonomy: {$taxonomy}");
 		}
 
@@ -73,7 +74,7 @@
 			unset($data['term_id']);
 
 			// Filter to only allowed fields
-			$allowed = jvbGetFields($taxonomy, 'term');
+			$allowed = Registrar::getFieldsFor($taxonomy);
 			$setData = array_filter(
 				$data,
 				fn($key) => array_key_exists($key, $allowed),
@@ -88,12 +89,6 @@
 			$results = $meta->setAll($setData);
 
 			if ($results) {
-				// Clear cache
-				JVB()->cache()->for($taxonomy)->delete("term_{$termID}_meta");
-
-				// Trigger any post-update actions (e.g., thumbnail generation)
-				do_action(BASE . "{$taxonomy}_updated", $termID, $userID, $setData);
-
 				return Result::success([
 					'updated_fields' => array_keys($setData),
 					'term_id' => $termID
@@ -130,7 +125,8 @@
 		}
 
 		// Check if tracking enabled
-		if (!Features::forTaxonomy($taxonomy)->has('track_changes')) {
+		$registrar = Registrar::getInstance($taxonomy);
+		if ($registrar && !$registrar->hasFeature('track_changes')) {
 			return Result::fail('Member tracking not enabled for ' . $taxonomy);
 		}
 
@@ -175,15 +171,18 @@
 	 */
 	protected function addMember(int $userID, int $termID, string $taxonomy): Result
 	{
-		$config = JVB_TAXONOMY[$taxonomy] ?? [];
-		$content = $config['for_content'] ?? [];
+		$registrar = Registrar::getInstance($taxonomy);
+		if (!$registrar) {
+			return Result::fail('No content registered');
+		}
 
-		if (empty($content)) {
+		$forContent = $registrar->registrar->for;
+		if (empty($forContent)) {
 			return Result::fail('No content types configured for ' . $taxonomy);
 		}
 
 		// Get table name (e.g., "history_artist_shop")
-		$contentType = $content[0]; // Use first content type
+		$contentType = is_array($forContent) ? $forContent[0] : $forContent; // Use first content type
 		$tableName = "history_{$contentType}_{$taxonomy}";
 		$table = CustomTable::for($tableName);
 
@@ -237,9 +236,6 @@
 				throw new Exception('Failed to set taxonomy term: ' . $termResult->get_error_message());
 			}
 
-			// Clear cache
-			JVB()->cache()->for($taxonomy)->delete("{$taxonomy}_{$termID}_members");
-
 			// Notify term managers
 			$this->notifyTermManagers($termID, $userID, $taxonomy, 'member_added');
 
@@ -256,15 +252,19 @@
 	 */
 	protected function removeMember(int $userID, int $termID, string $taxonomy): Result
 	{
-		$config = JVB_TAXONOMY[$taxonomy] ?? [];
-		$content = $config['for_content'] ?? [];
+		$registrar = Registrar::getInstance($taxonomy);
+		if (!$registrar) {
+			return Result::fail('No content registered');
+		}
+		$forContent = $registrar->registrar->for;
 
-		if (empty($content)) {
+		if (empty($forContent)) {
 			return Result::fail('No content types configured for ' . $taxonomy);
 		}
 
 		// Get table name
-		$contentType = $content[0];
+		$contentType = is_array($forContent) ? $forContent[0] : $forContent;
+
 		$tableName = "history_{$contentType}_{$taxonomy}";
 		$table = CustomTable::for($tableName);
 
@@ -298,9 +298,6 @@
 				throw new Exception('Failed to remove taxonomy term: ' . $termResult->get_error_message());
 			}
 
-			// Clear cache
-			JVB()->cache()->for($taxonomy)->delete("{$taxonomy}_{$termID}_members");
-
 			// Notify term managers
 			$this->notifyTermManagers($termID, $userID, $taxonomy, 'member_removed');
 

--
Gitblit v1.10.0