From 5297e6e9189ca8e4b60d714c93ba7aa27912b1f2 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 4 May 2023 11:35:22 +0300 Subject: [PATCH] fix condition error --- crontab/crawler.php | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/crontab/crawler.php b/crontab/crawler.php index fe89a94..791b9ca 100644 --- a/crontab/crawler.php +++ b/crontab/crawler.php @@ -268,35 +268,38 @@ foreach ($db->getHostPageCrawlQueue(CRAWL_PAGE_LIMIT, time() - CRAWL_PAGE_SECOND // Save image info $hostImageId = $db->getHostImageId($hostId, crc32($hostImageURI->string)); - if ($hostStatus && // host enabled - $robots->uriAllowed($hostImageURI->string) && // src allowed by robots.txt rules - $hostImageLimit > $db->getTotalHostImages($hostId) && // images quantity not reached host limit - !$hostImageId) { // image not exists + if (!$hostImageId && // image not exists + $hostStatus && // host enabled + $robots->uriAllowed($hostImageURI->string) && // src allowed by robots.txt rules + $hostImageLimit > $db->getTotalHostImages($hostId)) { // images quantity not reached host limit - // Add host image - if ($hostImageId = $db->addHostImage($hostId, crc32($hostImageURI->string), $hostImageURI->string, time(), null, 200)) { + // Add host image + if ($hostImageId = $db->addHostImage($hostId, crc32($hostImageURI->string), $hostImageURI->string, time(), null, 200)) { - $hostImagesAdded++; + $hostImagesAdded++; - } else { + } else { - continue; - } + continue; + } } - // Add/update host image description - $db->setHostImageDescription($hostImageId, - crc32(md5((string) $imageAlt . (string) $imageTitle)), - Filter::imageAlt($imageAlt), - Filter::imageTitle($imageTitle), - time(), - time()); + // Host image exists or created new one + if ($hostImageId) { + // Add/update host image description + $db->setHostImageDescription($hostImageId, + crc32(md5((string) $imageAlt . (string) $imageTitle)), + Filter::imageAlt($imageAlt), + Filter::imageTitle($imageTitle), + time(), + time()); - // Relate host image with host page was found - $db->setHostImageToHostPage($hostImageId, $queueHostPage->hostPageId, time(), time(), 1); + // Relate host image with host page was found + $db->setHostImageToHostPage($hostImageId, $queueHostPage->hostPageId, time(), time(), 1); + } - // Increase page rank when link does not match the current host + // Increase image rank when link does not match the current host if ($hostImageURL->scheme . '://' . $hostImageURL->name . ($hostImageURL->port ? ':' . $hostImageURL->port : '')