| | |
| | | namespace JVBase\managers; |
| | | |
| | | use Exception; |
| | | use JVBase\Instance; |
| | | use JVBase\managers\queue\Queue; |
| | | use WP_Error; |
| | | use WP_Post; |
| | | use WP_Query; |
| | |
| | | |
| | | class TaxonomyRelationships |
| | | { |
| | | use Instance; |
| | | protected Cache $cache; |
| | | protected CustomTable $relationships; |
| | | |
| | | public function __construct() |
| | | private function __construct() |
| | | { |
| | | $this->defineTables(); |
| | | |
| | | $this->cache = Cache::for('term_relationship', WEEK_IN_SECONDS); |
| | | $this->cache->connect('terms'); |
| | | $this->cache = Cache::for('term_relationship', 'term', WEEK_IN_SECONDS); |
| | | |
| | | // Ensure the table exists |
| | | // $this->create_table_if_not_exists(); |
| | |
| | | add_filter(BASE.'handle_bulk_operation', [$this, 'processOperation'], 10, 3); |
| | | } |
| | | |
| | | |
| | | // Update relationships for a post |
| | | |
| | | /** |
| | | * @param int $post_id |
| | | * |
| | | * @return void |
| | | */ |
| | | /** |
| | | * Update relationships for a post |
| | | * @param int $post_id |
| | | * @param WP_Post $post |
| | | * @return void |
| | | */ |
| | | public function updatePostRelationships(int $post_id, WP_Post $post):void |
| | | { |
| | | // Skip autosaves and revisions |
| | |
| | | { |
| | | |
| | | $term_posts = $this->cache->remember( |
| | | $this->cache->generateKey(['term' => $term_id, 'taxonomy' => $taxonomy]), |
| | | ['id' => $term_id, 'taxonomy' => $taxonomy], |
| | | function () use ($term_id, $taxonomy) { |
| | | global $wpdb; |
| | | return $wpdb->get_col($wpdb->prepare( |
| | |
| | | |
| | | |
| | | $related_term_posts = $this->cache->remember( |
| | | $this->cache->generateKey(['term' => $related_term_id, 'taxonomy' => $related_taxonomy]), |
| | | ['id' => $related_term_id, 'taxonomy' => $related_taxonomy], |
| | | function () use($related_term_id, $related_taxonomy) { |
| | | global $wpdb; |
| | | return $wpdb->get_col($wpdb->prepare( |
| | |
| | | |
| | | |
| | | // Queue the operation |
| | | $queue = JVB()->queue(); |
| | | $queue = Queue::getInstance(); |
| | | |
| | | $queue->queueOperation( |
| | | 'taxonomy_relationships', |