| | |
| | | |
| | | use JVBase\managers\queue\executors\IntegrationExecutor; |
| | | use JVBase\managers\queue\mergers\DefaultMerger; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\managers\queue\TypeConfig; |
| | | use JVBase\meta\Meta; |
| | | use WP_Query; |
| | |
| | | } |
| | | |
| | | trait SyncHelpers { |
| | | use _Base; |
| | | use _Base, SyncDefaults; |
| | | /** |
| | | * Queue types |
| | | * These types match with IntegrationExecutor |
| | |
| | | protected static string $syncCustomer; |
| | | protected static string $import; |
| | | |
| | | protected static array $syncing = ['posts' => [], 'users' => [], 'terms' => []]; |
| | | |
| | | |
| | | protected function setQueueTypes():void |
| | | { |
| | | self::$syncTo = $this->service_name.'_sync_to'; |
| | | self::$deleteFrom = $this->service_name.'_delete_from'; |
| | | self::$syncFrom = $this->service_name.'_sync_from'; |
| | | self::$syncCustomer = $this->service_name.'_sync_customer'; |
| | | //TODO: What is the difference between sync_from and import? |
| | | self::$import = $this->service_name.'import_from'; |
| | | } |
| | |
| | | default => '' |
| | | }; |
| | | } |
| | | public function setServiceItemID(int $itemID, string $id, string $type = 'post'):bool |
| | | { |
| | | |
| | | $result = match($type) { |
| | | 'post' => Meta::forPost($itemID)->set("_{$this->service_name}_item_id", $id), |
| | | 'term','taxonomy' => Meta::forTerm($itemID)->set("_{$this->service_name}_item_id", $id), |
| | | 'user' => Meta::forUser($itemID)->set("_{$this->service_name}_item_id", $id), |
| | | default => false |
| | | }; |
| | | return $result !== false; |
| | | } |
| | | protected function updateItemStatus(int|array $items, string $status = 'pending', string $type = 'post'):void |
| | | { |
| | | if (!is_array($items)) { |
| | |
| | | if (empty($this->syncTaxonomies) && empty($this->syncPostTypes)) { |
| | | return; |
| | | } |
| | | $queue = JVB()->queue(); |
| | | $queue = Queue::getInstance(); |
| | | $executor = new IntegrationExecutor(); |
| | | |
| | | $queue->registry()->register(self::$syncTo, new TypeConfig( |