offset can't be null, and named args

This commit is contained in:
Shish 2023-06-27 15:32:39 +01:00
parent e8aadf8d23
commit e62cdb0979
7 changed files with 14 additions and 15 deletions

View file

@ -149,7 +149,7 @@ class Image
if ($start < 0) { if ($start < 0) {
$start = 0; $start = 0;
} }
if ($limit!=null && $limit < 1) { if ($limit !== null && $limit < 1) {
$limit = 1; $limit = 1;
} }
@ -166,11 +166,11 @@ class Image
/** /**
* Search for an array of images * Search for an array of images
* *
* @param String[] $tags * @param string[] $tags
* @return Image[] * @return Image[]
*/ */
#[Query(name: "posts", type: "[Post!]!", args: ["tags" => "[string!]"])] #[Query(name: "posts", type: "[Post!]!", args: ["tags" => "[string!]"])]
public static function find_images(?int $offset = 0, ?int $limit = null, array $tags=[]): array public static function find_images(int $offset = 0, ?int $limit = null, array $tags=[]): array
{ {
$result = self::find_images_internal($offset, $limit, $tags); $result = self::find_images_internal($offset, $limit, $tags);

View file

@ -212,7 +212,7 @@ class Artists extends Extension
$userIsLogged = !$user->is_anonymous(); $userIsLogged = !$user->is_anonymous();
$userIsAdmin = $user->can(Permissions::ARTISTS_ADMIN); $userIsAdmin = $user->can(Permissions::ARTISTS_ADMIN);
$images = Image::find_images(0, 4, Tag::explode($artist['name'])); $images = Image::find_images(limit: 4, tags: Tag::explode($artist['name']));
$this->theme->show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin); $this->theme->show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin);
/* /*

View file

@ -166,7 +166,7 @@ class Index extends Extension
} }
if ($event->cmd == "search") { if ($event->cmd == "search") {
$query = count($event->args) > 0 ? Tag::explode($event->args[0]) : []; $query = count($event->args) > 0 ? Tag::explode($event->args[0]) : [];
$items = Image::find_images(0, 1000, $query); $items = Image::find_images(limit: 1000, tags: $query);
foreach ($items as $item) { foreach ($items as $item) {
print("{$item->hash}\n"); print("{$item->hash}\n");
} }

View file

@ -357,9 +357,8 @@ class Pools extends Extension
case "import": case "import":
if ($this->have_permission($user, $pool)) { if ($this->have_permission($user, $pool)) {
$images = Image::find_images( $images = Image::find_images(
0, limit: $config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000),
$config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000), tags: Tag::explode($_POST["pool_tag"])
Tag::explode($_POST["pool_tag"])
); );
$this->theme->pool_result($page, $images, $pool); $this->theme->pool_result($page, $images, $pool);
} else { } else {

View file

@ -30,7 +30,7 @@ class RegenThumb extends Extension
} }
if ($event->page_matches("regen_thumb/mass") && $user->can(Permissions::DELETE_IMAGE) && isset($_POST['tags'])) { if ($event->page_matches("regen_thumb/mass") && $user->can(Permissions::DELETE_IMAGE) && isset($_POST['tags'])) {
$tags = Tag::explode(strtolower($_POST['tags']), false); $tags = Tag::explode(strtolower($_POST['tags']), false);
$images = Image::find_images(0, 10000, $tags); $images = Image::find_images(limit: 10000, tags: $tags);
foreach ($images as $image) { foreach ($images as $image) {
$this->regenerate_thumbnail($image); $this->regenerate_thumbnail($image);

View file

@ -42,7 +42,7 @@ class XMLSitemap extends Extension
private function handle_smaller_sitemap() private function handle_smaller_sitemap()
{ {
/* --- Add latest images to sitemap with higher priority --- */ /* --- Add latest images to sitemap with higher priority --- */
$latestimages = Image::find_images(0, 50, []); $latestimages = Image::find_images(limit: 50);
if (empty($latestimages)) { if (empty($latestimages)) {
return; return;
} }
@ -85,7 +85,7 @@ class XMLSitemap extends Extension
$this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */); $this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */);
/* --- Add latest images to sitemap with higher priority --- */ /* --- Add latest images to sitemap with higher priority --- */
$latestimages = Image::find_images(0, 50, []); $latestimages = Image::find_images(limit: 50);
$latestimages_urllist = []; $latestimages_urllist = [];
$latest_image = null; $latest_image = null;
foreach ($latestimages as $arrayid => $image) { foreach ($latestimages as $arrayid => $image) {
@ -107,7 +107,7 @@ class XMLSitemap extends Extension
$this->add_sitemap_queue($other_tags, "monthly", "0.7" /* not sure how to deal with date here */); $this->add_sitemap_queue($other_tags, "monthly", "0.7" /* not sure how to deal with date here */);
/* --- Add all other images to sitemap with lower priority --- */ /* --- Add all other images to sitemap with lower priority --- */
$otherimages = Image::find_images(51, 10000000, []); $otherimages = Image::find_images(offset: 51, limit: 10000000);
$image = null; $image = null;
foreach ($otherimages as $arrayid => $image) { foreach ($otherimages as $arrayid => $image) {
// create url from image id's // create url from image id's

View file

@ -300,7 +300,7 @@ class TagEdit extends Extension
log_info("tag_edit", "Mass editing tags: '$search' -> '$replace'"); log_info("tag_edit", "Mass editing tags: '$search' -> '$replace'");
if (count($search_set) == 1 && count($replace_set) == 1) { if (count($search_set) == 1 && count($replace_set) == 1) {
$images = Image::find_images(0, 10, $replace_set); $images = Image::find_images(limit: 10, tags: $replace_set);
if (count($images) == 0) { if (count($images) == 0) {
log_info("tag_edit", "No images found with target tag, doing in-place rename"); log_info("tag_edit", "No images found with target tag, doing in-place rename");
$database->execute( $database->execute(
@ -329,7 +329,7 @@ class TagEdit extends Extension
$search_forward[] = "id<$last_id"; $search_forward[] = "id<$last_id";
} }
$images = Image::find_images(0, 100, $search_forward); $images = Image::find_images(limit: 100, tags: $search_forward);
if (count($images) == 0) { if (count($images) == 0) {
break; break;
} }
@ -365,7 +365,7 @@ class TagEdit extends Extension
$search_forward[] = "id<$last_id"; $search_forward[] = "id<$last_id";
} }
$images = Image::find_images(0, 100, $search_forward); $images = Image::find_images(limit: 100, tags: $search_forward);
if (count($images) == 0) { if (count($images) == 0) {
break; break;
} }