From f8a5139bad211fc2e2896db409343cfa67686f42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 6 Dec 2020 23:07:50 +0100 Subject: [PATCH] Continued: - introduced isLastCsvFileImported() - added some noisy debug lines MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../class_CrawlerUploadedListUrlSource.php | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php b/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php index c4c62862f..cee8d06c8 100644 --- a/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php +++ b/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php @@ -246,7 +246,7 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: csvArray()=' . count($csvArray) . ' - AFTER!'); $this->enqueueInFileStack($csvArray); - // Debug message + // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: EXIT!'); } @@ -257,9 +257,11 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R */ private function isCsvFileAdded () { // Check whether the stacker is not empty + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); $isAdded = (($this->getStackSourceInstance()->isStackInitialized(self::STACK_NAME_CSV_FILE)) && (!$this->getStackSourceInstance()->isStackEmpty(self::STACK_NAME_CSV_FILE))); // Return the result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRAWLER-UPLOADED-LIST-URL-SOURCE: isAdded=%d - EXIT!', intval($isAdded))); return $isAdded; } @@ -270,12 +272,29 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R */ private function isCsvEntryAdded () { // Check whether the stacker is not empty + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); $isAdded = (($this->getStackSourceInstance()->isStackInitialized(self::STACK_NAME_CSV_ENTRY)) && (!$this->getStackSourceInstance()->isStackEmpty(self::STACK_NAME_CSV_ENTRY))); // Return the result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRAWLER-UPLOADED-LIST-URL-SOURCE: isAdded=%d - EXIT!', intval($isAdded))); return $isAdded; } + /** + * Checks wether lastCsvFileInstance has already been imported + * + * @return $isImported Whether lastCsvFileInstance has already been imported + */ + private function isLastCsvFileImported () { + // Determine it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); + $isImported = in_array($this->lastCsvFileInstance->getFileObject()->getBasename(), $this->csvFileImported); + + // Return result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRAWLER-UPLOADED-LIST-URL-SOURCE: isImported=%d - EXIT!', intval($isImported))); + return $isImported; + } + /** * Initializes the import of the CSV file which is being processed by other task * @@ -288,7 +307,7 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R if (is_null($this->lastCsvFileInstance)) { // This should not happen throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (in_array($this->lastCsvFileInstance->getFileObject()->getBasename(), $this->csvFileImported)) { + } elseif ($this->isLastCsvFileImported()) { // Already stacked return; } @@ -315,10 +334,8 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R * @return void */ private function parseCsvFile () { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); - // Get next entry + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); $csvFileInstance = $this->getStackSourceInstance()->popNamed(self::STACK_NAME_CSV_FILE); // Read full "CSV line" @@ -347,7 +364,7 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R // Push array on next stack $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_ENTRY, $csvData); - // Debug message + // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: EXIT!'); } @@ -357,22 +374,18 @@ class CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, R * @return void */ private function parseCsvEntry () { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); - // Pop it from stack + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: CALLED!'); $csvData = $this->getStackSourceInstance()->popNamed(self::STACK_NAME_CSV_ENTRY); - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE)); - // It must have a fixed amount of elements (see method parseCsvFile() for details) + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE)); assert(count($csvData) == self::CRAWL_ENTRY_SIZE); // Save it in crawler queue (which will enrich it with way more informations $this->saveCsvDataInCrawlerQueue($csvData); - // Debug message + // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CRAWLER-UPLOADED-LIST-URL-SOURCE: EXIT!'); } -- 2.39.5