| | |
| | | exit; |
| | | } |
| | | |
| | | use JVBase\registry\TaxonomyRegistrar; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\registrar\Registrar; |
| | | use WP_Error; |
| | | use Exception; |
| | | |
| | |
| | | { |
| | | public function __construct() |
| | | { |
| | | if (!jvbSiteHasTermContent()){ |
| | | if (empty(Registrar::withFeature('is_content', 'term'))){ |
| | | return; |
| | | } |
| | | add_filter(BASE.'handle_bulk_operation', [ $this, 'processOperation' ], 10, 3); |
| | |
| | | // Handle individual taxonomy rebuild |
| | | if (isset($_POST['rebuild_taxonomy']) && wp_verify_nonce($_POST['_wpnonce'], 'rebuild_taxonomy')) { |
| | | $taxonomy = sanitize_text_field($_POST['taxonomy']); |
| | | |
| | | if (isset(JVB_TAXONOMY[$taxonomy]) && (JVB_TAXONOMY[$taxonomy]['is_content'] ?? false)) { |
| | | $registrar = Registrar::getInstance($taxonomy); |
| | | if ($registrar && $registrar->hasFeature('is_content')) { |
| | | $results = $this->rebuildCustomTable($taxonomy); |
| | | // Store results in transient to display after redirect |
| | | set_transient('jvb_rebuild_results_' . $taxonomy, $results, 300); // 5 minutes |
| | |
| | | </tr> |
| | | </thead> |
| | | <tbody> |
| | | <?php foreach (JVB_TAXONOMY as $slug => $config): ?> |
| | | <?php if (!($config['is_content'] ?? false)) continue; ?> |
| | | <?php |
| | | <?php |
| | | $taxonomies = Registrar::withFeature('is_content', 'term'); |
| | | foreach ($taxonomies as $slug): |
| | | $registrar = Registrar::getInstance($slug); |
| | | $taxonomy = BASE . $slug; |
| | | $table_info = $this->getTableInfo($slug); |
| | | $term_count = wp_count_terms($taxonomy, ['hide_empty' => false]); |
| | | ?> |
| | | <tr> |
| | | <td> |
| | | <strong><?= esc_html($config['plural'] ?? ucfirst($slug)) ?></strong><br> |
| | | <strong><?= esc_html($registrar->getPlural()) ?></strong><br> |
| | | <code><?= esc_html($taxonomy) ?></code> |
| | | </td> |
| | | <td> |
| | |
| | | |
| | | <?php foreach ($results['details'] as $taxonomy => $detail): ?> |
| | | <details> |
| | | <summary class="row btw"> |
| | | <summary class="row x-btw"> |
| | | <strong><?= esc_html(ucfirst($taxonomy)) ?></strong> |
| | | <?php if ($detail['errors'] === 0): ?> |
| | | <span style="color: green;">✓ Success</span> |
| | |
| | | */ |
| | | public function rebuildCustomTable(string $taxonomy):array |
| | | { |
| | | global $wpdb; |
| | | |
| | | $results = [ |
| | | 'success' => 0, |
| | | 'errors' => 0, |
| | |
| | | ]; |
| | | |
| | | // Check if this is a content taxonomy |
| | | if (!(JVB_TAXONOMY[$taxonomy]['is_content'] ?? false)) { |
| | | $registrar = Registrar::getInstance($taxonomy); |
| | | if (!$registrar->hasFeature('is_content')) { |
| | | $results['messages'][] = "Taxonomy {$taxonomy} is not a content taxonomy"; |
| | | return $results; |
| | | } |
| | | |
| | | global $wpdb; |
| | | $table = $wpdb->prefix . BASE . 'content_' . $taxonomy; |
| | | |
| | | // Check if table exists |
| | |
| | | $results['total'] = count($terms); |
| | | $results['messages'][] = "Found {$results['total']} terms to process"; |
| | | |
| | | JVB()->queue()->queueOperation( |
| | | Queue::getInstance()->queueOperation( |
| | | 'sync_content_taxonomy_tables', |
| | | 0, |
| | | [ |
| | |
| | | |
| | | public function processOperation(WP_Error $result, object $operation, array $data):WP_Error|array |
| | | { |
| | | switch ($operation->type) { |
| | | case 'sync_content_taxonomy_tables': |
| | | return $this->processContentTaxonomyTableSync($operation, $data); |
| | | default: |
| | | return $result; |
| | | } |
| | | return match ($operation->type) { |
| | | 'sync_content_taxonomy_tables' => $this->processContentTaxonomyTableSync($operation, $data), |
| | | default => $result, |
| | | }; |
| | | } |
| | | |
| | | public function processContentTaxonomyTableSync(object $operation, array $data):array |
| | | { |
| | | //TODO: This won't work currently |
| | | $taxonomy = $data['taxonomy']; |
| | | $registrar = new TaxonomyRegistrar($taxonomy, JVB_TAXONOMY[$taxonomy]); |
| | | $registrar = Registrar::getInstance($taxonomy); |
| | | $results = ['errors' => 0, 'success' => 0]; |
| | | foreach ($data['terms'] as $term) { |
| | | try { |