/** * API method * Returns a list of missing derivatives (not generated yet) * @param mixed[] $params * @option string types (optional) * @option int[] ids * @option int max_urls * @option int prev_page (optional) */ function ws_getMissingDerivatives($params, &$service) { global $conf; if (empty($params['types'])) { $types = array_keys(ImageStdParams::get_defined_type_map()); } else { $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']); if (count($types) == 0) { return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types"); } } $max_urls = $params['max_urls']; $query = 'SELECT MAX(id)+1, COUNT(*) FROM ' . IMAGES_TABLE . ';'; list($max_id, $image_count) = pwg_db_fetch_row(pwg_query($query)); if (0 == $image_count) { return array(); } $start_id = $params['prev_page']; if ($start_id <= 0) { $start_id = $max_id; } $uid = '&b=' . time(); $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; $conf['derivative_url_style'] = 2; //script $qlimit = min(5000, ceil(max($image_count / 500, $max_urls / count($types)))); $where_clauses = ws_std_image_sql_filter($params, ''); $where_clauses[] = 'id<start_id'; if (!empty($params['ids'])) { $where_clauses[] = 'id IN (' . implode(',', $params['ids']) . ')'; } $query_model = ' SELECT id, path, representative_ext, width, height, rotation FROM ' . IMAGES_TABLE . ' WHERE ' . implode(' AND ', $where_clauses) . ' ORDER BY id DESC LIMIT ' . $qlimit . ' ;'; $urls = array(); do { $result = pwg_query(str_replace('start_id', $start_id, $query_model)); $is_last = pwg_db_num_rows($result) < $qlimit; while ($row = pwg_db_fetch_assoc($result)) { $start_id = $row['id']; $src_image = new SrcImage($row); if ($src_image->is_mimetype()) { continue; } foreach ($types as $type) { $derivative = new DerivativeImage($type, $src_image); if ($type != $derivative->get_type()) { continue; } if (@filemtime($derivative->get_path()) === false) { $urls[] = $derivative->get_url() . $uid; } } if (count($urls) >= $max_urls and !$is_last) { break; } } if ($is_last) { $start_id = 0; } } while (count($urls) < $max_urls and $start_id); $ret = array(); if ($start_id) { $ret['next_page'] = $start_id; } $ret['urls'] = $urls; return $ret; }
FROM ' . IMAGES_TABLE . ' WHERE id < start_id ORDER BY id DESC LIMIT ' . $qlimit; $urls = array(); do { $result = pwg_query(str_replace('start_id', $start_id, $query_model)); $is_last = pwg_db_num_rows($result) < $qlimit; while ($row = pwg_db_fetch_assoc($result)) { $start_id = $row['id']; $src_image = new SrcImage($row); if ($src_image->is_mimetype()) { continue; } $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $conf['GThumb']['height']), $src_image); if (@filemtime($derivative->get_path()) === false) { $urls[] = $derivative->get_url() . $uid; } if (count($urls) >= $max_urls && !$is_last) { break; } } if ($is_last) { $start_id = 0; } } while (count($urls) < $max_urls && $start_id); $ret = array(); if ($start_id) { $ret['next_page'] = $start_id; } $ret['urls'] = $urls;