onlyMissing = $onlyMissing; } public function toggle() { return $this->set(!$this->get()); } public function get() { return get_option("_ACTIONWEAR_LAST_RESYNCED_PRODUCTS", 0); } public function validate($v): bool { return is_bool($v); } public function set($value) { global $wpdb; if (!$this->validate($value)) throw new \Exception("Only boolean values are accepted to this setting"); @set_time_limit(300); try { Product::generateImages(); } catch (\Throwable $e) { Log::write("Resync: generateImages failed: " . $e->getMessage(), Log::ERROR, Log::CONTEXT_PRODUCT_CREATION); } if (!$this->onlyMissing) $wpdb->query("UPDATE {$wpdb->prefix}actionwear_products SET wc_created = 0;"); $query = "SELECT sku FROM " . $wpdb->prefix . "actionwear_products WHERE wc_to_create = 1 "; if ($this->onlyMissing) { $query .= "AND wc_created = 0"; } $skus = $wpdb->get_col($query); $jobCount = 0; if (empty($skus)) { Log::write("Resync: No SKUs found with wc_to_create=1" . ($this->onlyMissing ? " AND wc_created=0" : ""), Log::WARNING, Log::CONTEXT_CRONJOB); } else { Log::write("Resync: Queuing " . count($skus) . " product_import jobs (onlyMissing=" . ($this->onlyMissing ? "true" : "false") . ")", Log::INFO, Log::CONTEXT_CRONJOB); $jobCount = JobQueue::batchPushProductImport($skus); } update_option("_ACTIONWEAR_LAST_RESYNCED_PRODUCTS", time()); return $jobCount; } } }