} elseif ($q['action'] == 'pages_delete') { $type = 'pages'; } elseif ($q['action'] == 'facet_delete') { $type = 'facets'; } foreach ($data as $id) { $status = fn_se_send_request("/api/{$type}/delete/json", $private_key, $q['action'] == 'facet_delete' ? array('attribute' => $id) : array('id' => $id)); fn_echo('.'); if ($status == false) { break; } } } elseif ($q['action'] == 'delete_all') { $status = fn_se_send_request('/api/items/delete/json', $private_key, array('all' => true)); } if (fn_se_check_debug()) { fn_print_r('status', $status); } // Change queue item status if ($status == true) { db_query("DELETE FROM ?:se_queue WHERE queue_id = ?i", $q['queue_id']); // Done, cleanup queue $q = fn_se_get_next_queue($q['queue_id']); } else { $next_started_time = TIME - SE_MAX_PROCESSING_TIME + $q['error_count'] * 60; db_query("UPDATE ?:se_queue SET status = 'processing', error_count = error_count + 1, started = ?s WHERE queue_id = ?i", $next_started_time, $q['queue_id']); break; //try later } fn_echo('.'); }
function fn_searchanise_send_search_request($params, $lang_code = CART_LANGUAGE) { $company_id = fn_se_get_company_id(); $api_key = fn_se_get_api_key($company_id, $lang_code); if (empty($api_key)) { return; } $default_params = array('items' => 'true', 'facets' => 'true', 'output' => 'json'); $params = array_merge($default_params, $params); if (empty($params['restrictBy'])) { unset($params['restrictBy']); } if (empty($params['union'])) { unset($params['union']); } $query = http_build_query($params); if (fn_se_check_debug()) { fn_print_r($params); } Registry::set('log_cut', true); if (strlen($query) > SE_MAX_SEARCH_REQUEST_LENGTH && fn_check_curl()) { $received = Http::post(SE_SERVICE_URL . '/search?api_key=' . $api_key, $params, array('timeout' => SE_SEARCH_TIMEOUT)); } else { $params['api_key'] = $api_key; $received = Http::get(SE_SERVICE_URL . '/search', $params, array('timeout' => SE_SEARCH_TIMEOUT)); } if (empty($received)) { return false; } $result = json_decode(trim($received), true); if (fn_se_check_debug()) { fn_print_r($result); } if (isset($result['error'])) { if ($result['error'] == 'NEED_RESYNC_YOUR_CATALOG') { fn_se_queue_import($company_id, $lang_code, false); return false; } elseif ($result['error'] == 'NAVIGATION_DISABLED') { fn_se_set_simple_setting('use_navigation', 'N'); } } if (empty($result) || !is_array($result) || !isset($result['totalItems'])) { return false; } return $result; }