| | |
| | | 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')) { |
| | |
| | | public function execute(Operation $operation, Progress $progress): Result |
| | | { |
| | | // 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}"); |
| | | } |
| | | |
| | |
| | | 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), |
| | |
| | | } |
| | | |
| | | // 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); |
| | | } |
| | | |
| | |
| | | */ |
| | | 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); |
| | | |
| | |
| | | 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'); |
| | | |
| | |
| | | */ |
| | | 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); |
| | | |
| | |
| | | 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'); |
| | | |