Complex classes like CrawlerController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CrawlerController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 62 | class CrawlerController |
||
| 63 | { |
||
| 64 | const CLI_STATUS_NOTHING_PROCCESSED = 0; |
||
| 65 | const CLI_STATUS_REMAIN = 1; //queue not empty |
||
| 66 | const CLI_STATUS_PROCESSED = 2; //(some) queue items where processed |
||
| 67 | const CLI_STATUS_ABORTED = 4; //instance didn't finish |
||
| 68 | const CLI_STATUS_POLLABLE_PROCESSED = 8; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var integer |
||
| 72 | */ |
||
| 73 | public $setID = 0; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | public $processID = ''; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * One hour is max stalled time for the CLI |
||
| 82 | * If the process had the status "start" for 3600 seconds, it will be regarded stalled and a new process is started |
||
| 83 | * |
||
| 84 | * @var integer |
||
| 85 | */ |
||
| 86 | public $max_CLI_exec_time = 3600; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var array |
||
| 90 | */ |
||
| 91 | public $duplicateTrack = []; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | public $downloadUrls = []; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | public $incomingProcInstructions = []; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | public $incomingConfigurationSelection = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var bool |
||
| 110 | */ |
||
| 111 | public $registerQueueEntriesInternallyOnly = false; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var array |
||
| 115 | */ |
||
| 116 | public $queueEntries = []; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var array |
||
| 120 | */ |
||
| 121 | public $urlList = []; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var boolean |
||
| 125 | */ |
||
| 126 | public $debugMode = false; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var array |
||
| 130 | */ |
||
| 131 | public $extensionSettings = []; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Mount Point |
||
| 135 | * |
||
| 136 | * @var boolean |
||
| 137 | */ |
||
| 138 | public $MP = false; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var string |
||
| 142 | */ |
||
| 143 | protected $processFilename; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Holds the internal access mode can be 'gui','cli' or 'cli_im' |
||
| 147 | * |
||
| 148 | * @var string |
||
| 149 | */ |
||
| 150 | protected $accessMode; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var DatabaseConnection |
||
| 154 | */ |
||
| 155 | private $db; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var BackendUserAuthentication |
||
| 159 | */ |
||
| 160 | private $backendUser; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var integer |
||
| 164 | */ |
||
| 165 | private $scheduledTime = 0; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var integer |
||
| 169 | */ |
||
| 170 | private $reqMinute = 0; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @var bool |
||
| 174 | */ |
||
| 175 | private $submitCrawlUrls = false; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var bool |
||
| 179 | */ |
||
| 180 | private $downloadCrawlUrls = false; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @var QueueRepository |
||
| 184 | */ |
||
| 185 | protected $queueRepository; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @var ConfigurationRepository |
||
| 189 | */ |
||
| 190 | protected $configurationRepository; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Method to set the accessMode can be gui, cli or cli_im |
||
| 194 | * |
||
| 195 | * @return string |
||
| 196 | */ |
||
| 197 | 1 | public function getAccessMode() |
|
| 198 | { |
||
| 199 | 1 | return $this->accessMode; |
|
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param string $accessMode |
||
| 204 | */ |
||
| 205 | 1 | public function setAccessMode($accessMode) |
|
| 206 | { |
||
| 207 | 1 | $this->accessMode = $accessMode; |
|
| 208 | 1 | } |
|
| 209 | |||
| 210 | /** |
||
| 211 | * Set disabled status to prevent processes from being processed |
||
| 212 | * |
||
| 213 | * @param bool $disabled (optional, defaults to true) |
||
| 214 | * @return void |
||
| 215 | */ |
||
| 216 | 3 | public function setDisabled($disabled = true) |
|
| 217 | { |
||
| 218 | 3 | if ($disabled) { |
|
| 219 | 2 | GeneralUtility::writeFile($this->processFilename, ''); |
|
| 220 | } else { |
||
| 221 | 1 | if (is_file($this->processFilename)) { |
|
| 222 | 1 | unlink($this->processFilename); |
|
| 223 | } |
||
| 224 | } |
||
| 225 | 3 | } |
|
| 226 | |||
| 227 | /** |
||
| 228 | * Get disable status |
||
| 229 | * |
||
| 230 | * @return bool true if disabled |
||
| 231 | */ |
||
| 232 | 3 | public function getDisabled() |
|
| 233 | { |
||
| 234 | 3 | if (is_file($this->processFilename)) { |
|
| 235 | 2 | return true; |
|
| 236 | } else { |
||
| 237 | 1 | return false; |
|
| 238 | } |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $filenameWithPath |
||
| 243 | * |
||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | 4 | public function setProcessFilename($filenameWithPath) |
|
| 247 | { |
||
| 248 | 4 | $this->processFilename = $filenameWithPath; |
|
| 249 | 4 | } |
|
| 250 | |||
| 251 | /** |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | 1 | public function getProcessFilename() |
|
| 255 | { |
||
| 256 | 1 | return $this->processFilename; |
|
| 257 | } |
||
| 258 | |||
| 259 | /************************************ |
||
| 260 | * |
||
| 261 | * Getting URLs based on Page TSconfig |
||
| 262 | * |
||
| 263 | ************************************/ |
||
| 264 | |||
| 265 | 43 | public function __construct() |
|
| 266 | { |
||
| 267 | 43 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
| 268 | 43 | $this->queueRepository = $objectManager->get(QueueRepository::class); |
|
| 269 | 43 | $this->configurationRepository = $objectManager->get(ConfigurationRepository::class); |
|
| 270 | |||
| 271 | 43 | $this->db = $GLOBALS['TYPO3_DB']; |
|
| 272 | 43 | $this->backendUser = $GLOBALS['BE_USER']; |
|
| 273 | 43 | $this->processFilename = PATH_site . 'typo3temp/tx_crawler.proc'; |
|
| 274 | |||
| 275 | 43 | $settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['crawler']); |
|
| 276 | 43 | $settings = is_array($settings) ? $settings : []; |
|
| 277 | |||
| 278 | // read ext_em_conf_template settings and set |
||
| 279 | 43 | $this->setExtensionSettings($settings); |
|
| 280 | |||
| 281 | // set defaults: |
||
| 282 | 43 | if (MathUtility::convertToPositiveInteger($this->extensionSettings['countInARun']) == 0) { |
|
| 283 | 36 | $this->extensionSettings['countInARun'] = 100; |
|
| 284 | } |
||
| 285 | |||
| 286 | 43 | $this->extensionSettings['processLimit'] = MathUtility::forceIntegerInRange($this->extensionSettings['processLimit'], 1, 99, 1); |
|
| 287 | 43 | } |
|
| 288 | |||
| 289 | /** |
||
| 290 | * Sets the extensions settings (unserialized pendant of $TYPO3_CONF_VARS['EXT']['extConf']['crawler']). |
||
| 291 | * |
||
| 292 | * @param array $extensionSettings |
||
| 293 | * @return void |
||
| 294 | */ |
||
| 295 | 52 | public function setExtensionSettings(array $extensionSettings) |
|
| 296 | { |
||
| 297 | 52 | $this->extensionSettings = $extensionSettings; |
|
| 298 | 52 | } |
|
| 299 | |||
| 300 | /** |
||
| 301 | * Check if the given page should be crawled |
||
| 302 | * |
||
| 303 | * @param array $pageRow |
||
| 304 | * @return false|string false if the page should be crawled (not excluded), true / skipMessage if it should be skipped |
||
| 305 | */ |
||
| 306 | 10 | public function checkIfPageShouldBeSkipped(array $pageRow) |
|
| 307 | { |
||
| 308 | 10 | $skipPage = false; |
|
| 309 | 10 | $skipMessage = 'Skipped'; // message will be overwritten later |
|
| 310 | |||
| 311 | // if page is hidden |
||
| 312 | 10 | if (!$this->extensionSettings['crawlHiddenPages']) { |
|
| 313 | 10 | if ($pageRow['hidden']) { |
|
| 314 | 1 | $skipPage = true; |
|
| 315 | 1 | $skipMessage = 'Because page is hidden'; |
|
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | 10 | if (!$skipPage) { |
|
| 320 | 9 | if (GeneralUtility::inList('3,4', $pageRow['doktype']) || $pageRow['doktype'] >= 199) { |
|
| 321 | 3 | $skipPage = true; |
|
| 322 | 3 | $skipMessage = 'Because doktype is not allowed'; |
|
| 323 | } |
||
| 324 | } |
||
| 325 | |||
| 326 | 10 | if (!$skipPage) { |
|
| 327 | 6 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'])) { |
|
| 328 | 2 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'] as $key => $doktypeList) { |
|
| 329 | 1 | if (GeneralUtility::inList($doktypeList, $pageRow['doktype'])) { |
|
| 330 | 1 | $skipPage = true; |
|
| 331 | 1 | $skipMessage = 'Doktype was excluded by "' . $key . '"'; |
|
| 332 | 1 | break; |
|
| 333 | } |
||
| 334 | } |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | 10 | if (!$skipPage) { |
|
| 339 | // veto hook |
||
| 340 | 5 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'])) { |
|
| 341 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'] as $key => $func) { |
||
| 342 | $params = [ |
||
| 343 | 'pageRow' => $pageRow, |
||
| 344 | ]; |
||
| 345 | // expects "false" if page is ok and "true" or a skipMessage if this page should _not_ be crawled |
||
| 346 | $veto = GeneralUtility::callUserFunction($func, $params, $this); |
||
| 347 | if ($veto !== false) { |
||
| 348 | $skipPage = true; |
||
| 349 | if (is_string($veto)) { |
||
| 350 | $skipMessage = $veto; |
||
| 351 | } else { |
||
| 352 | $skipMessage = 'Veto from hook "' . htmlspecialchars($key) . '"'; |
||
| 353 | } |
||
| 354 | // no need to execute other hooks if a previous one return a veto |
||
| 355 | break; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | 10 | return $skipPage ? $skipMessage : false; |
|
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Wrapper method for getUrlsForPageId() |
||
| 366 | * It returns an array of configurations and no urls! |
||
| 367 | * |
||
| 368 | * @param array $pageRow Page record with at least dok-type and uid columns. |
||
| 369 | * @param string $skipMessage |
||
| 370 | * @return array |
||
| 371 | * @see getUrlsForPageId() |
||
| 372 | */ |
||
| 373 | 6 | public function getUrlsForPageRow(array $pageRow, &$skipMessage = '') |
|
| 374 | { |
||
| 375 | 6 | $message = $this->checkIfPageShouldBeSkipped($pageRow); |
|
| 376 | |||
| 377 | 6 | if ($message === false) { |
|
| 378 | 5 | $forceSsl = ($pageRow['url_scheme'] === 2) ? true : false; |
|
| 379 | 5 | $res = $this->getUrlsForPageId($pageRow['uid'], $forceSsl); |
|
| 380 | 5 | $skipMessage = ''; |
|
| 381 | } else { |
||
| 382 | 1 | $skipMessage = $message; |
|
| 383 | 1 | $res = []; |
|
| 384 | } |
||
| 385 | |||
| 386 | 6 | return $res; |
|
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * This method is used to count if there are ANY unprocessed queue entries |
||
| 391 | * of a given page_id and the configuration which matches a given hash. |
||
| 392 | * If there if none, we can skip an inner detail check |
||
| 393 | * |
||
| 394 | * @param int $uid |
||
| 395 | * @param string $configurationHash |
||
| 396 | * @return boolean |
||
| 397 | */ |
||
| 398 | 7 | protected function noUnprocessedQueueEntriesForPageWithConfigurationHashExist($uid, $configurationHash) |
|
| 399 | { |
||
| 400 | 7 | $configurationHash = $this->db->fullQuoteStr($configurationHash, 'tx_crawler_queue'); |
|
| 401 | 7 | $res = $this->db->exec_SELECTquery('count(*) as anz', 'tx_crawler_queue', "page_id=" . intval($uid) . " AND configuration_hash=" . $configurationHash . " AND exec_time=0"); |
|
| 402 | 7 | $row = $this->db->sql_fetch_assoc($res); |
|
| 403 | |||
| 404 | 7 | return ($row['anz'] == 0); |
|
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Creates a list of URLs from input array (and submits them to queue if asked for) |
||
| 409 | * See Web > Info module script + "indexed_search"'s crawler hook-client using this! |
||
| 410 | * |
||
| 411 | * @param array Information about URLs from pageRow to crawl. |
||
| 412 | * @param array Page row |
||
| 413 | * @param integer Unix time to schedule indexing to, typically time() |
||
| 414 | * @param integer Number of requests per minute (creates the interleave between requests) |
||
| 415 | * @param boolean If set, submits the URLs to queue |
||
| 416 | * @param boolean If set (and submitcrawlUrls is false) will fill $downloadUrls with entries) |
||
| 417 | * @param array Array which is passed by reference and contains the an id per url to secure we will not crawl duplicates |
||
| 418 | * @param array Array which will be filled with URLS for download if flag is set. |
||
| 419 | * @param array Array of processing instructions |
||
| 420 | * @return string List of URLs (meant for display in backend module) |
||
| 421 | * |
||
| 422 | */ |
||
| 423 | 4 | public function urlListFromUrlArray( |
|
| 424 | array $vv, |
||
| 425 | array $pageRow, |
||
| 426 | $scheduledTime, |
||
| 427 | $reqMinute, |
||
| 428 | $submitCrawlUrls, |
||
| 429 | $downloadCrawlUrls, |
||
| 430 | array &$duplicateTrack, |
||
| 431 | array &$downloadUrls, |
||
| 432 | array $incomingProcInstructions |
||
| 433 | ) { |
||
| 434 | 4 | $urlList = ''; |
|
| 435 | // realurl support (thanks to Ingo Renner) |
||
| 436 | 4 | if (ExtensionManagementUtility::isLoaded('realurl') && $vv['subCfg']['realurl']) { |
|
| 437 | |||
| 438 | /** @var tx_realurl $urlObj */ |
||
| 439 | $urlObj = GeneralUtility::makeInstance('tx_realurl'); |
||
| 440 | |||
| 441 | if (!empty($vv['subCfg']['baseUrl'])) { |
||
| 442 | $urlParts = parse_url($vv['subCfg']['baseUrl']); |
||
| 443 | $host = strtolower($urlParts['host']); |
||
| 444 | $urlObj->host = $host; |
||
| 445 | |||
| 446 | // First pass, finding configuration OR pointer string: |
||
| 447 | $urlObj->extConf = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->host]) ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->host] : $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']; |
||
| 448 | |||
| 449 | // If it turned out to be a string pointer, then look up the real config: |
||
| 450 | if (is_string($urlObj->extConf)) { |
||
| 451 | $urlObj->extConf = is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->extConf]) ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->extConf] : $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']; |
||
| 452 | } |
||
| 453 | } |
||
| 454 | |||
| 455 | if (!$GLOBALS['TSFE']->sys_page) { |
||
| 456 | $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\PageRepository'); |
||
| 457 | } |
||
| 458 | |||
| 459 | if (!$GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) { |
||
| 460 | $GLOBALS['TSFE']->tmpl->rootLine[0]['uid'] = $urlObj->extConf['pagePath']['rootpage_id']; |
||
| 461 | } |
||
| 462 | } |
||
| 463 | |||
| 464 | 4 | if (is_array($vv['URLs'])) { |
|
| 465 | 4 | $configurationHash = $this->getConfigurationHash($vv); |
|
| 466 | 4 | $skipInnerCheck = $this->noUnprocessedQueueEntriesForPageWithConfigurationHashExist($pageRow['uid'], $configurationHash); |
|
| 467 | |||
| 468 | 4 | foreach ($vv['URLs'] as $urlQuery) { |
|
| 469 | 4 | if ($this->drawURLs_PIfilter($vv['subCfg']['procInstrFilter'], $incomingProcInstructions)) { |
|
| 470 | |||
| 471 | // Calculate cHash: |
||
| 472 | 4 | if ($vv['subCfg']['cHash']) { |
|
| 473 | /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */ |
||
| 474 | $cacheHash = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\CacheHashCalculator'); |
||
| 475 | $urlQuery .= '&cHash=' . $cacheHash->generateForParameters($urlQuery); |
||
| 476 | } |
||
| 477 | |||
| 478 | // Create key by which to determine unique-ness: |
||
| 479 | 4 | $uKey = $urlQuery . '|' . $vv['subCfg']['userGroups'] . '|' . $vv['subCfg']['baseUrl'] . '|' . $vv['subCfg']['procInstrFilter']; |
|
| 480 | |||
| 481 | // realurl support (thanks to Ingo Renner) |
||
| 482 | 4 | $urlQuery = 'index.php' . $urlQuery; |
|
| 483 | 4 | if (ExtensionManagementUtility::isLoaded('realurl') && $vv['subCfg']['realurl']) { |
|
| 484 | $params = [ |
||
| 485 | 'LD' => [ |
||
| 486 | 'totalURL' => $urlQuery, |
||
| 487 | ], |
||
| 488 | 'TCEmainHook' => true, |
||
| 489 | ]; |
||
| 490 | $urlObj->encodeSpURL($params); |
||
|
|
|||
| 491 | $urlQuery = $params['LD']['totalURL']; |
||
| 492 | } |
||
| 493 | |||
| 494 | // Scheduled time: |
||
| 495 | 4 | $schTime = $scheduledTime + round(count($duplicateTrack) * (60 / $reqMinute)); |
|
| 496 | 4 | $schTime = floor($schTime / 60) * 60; |
|
| 497 | |||
| 498 | 4 | if (isset($duplicateTrack[$uKey])) { |
|
| 499 | |||
| 500 | //if the url key is registered just display it and do not resubmit is |
||
| 501 | $urlList = '<em><span class="typo3-dimmed">' . htmlspecialchars($urlQuery) . '</span></em><br/>'; |
||
| 502 | } else { |
||
| 503 | 4 | $urlList = '[' . date('d.m.y H:i', $schTime) . '] ' . htmlspecialchars($urlQuery); |
|
| 504 | 4 | $this->urlList[] = '[' . date('d.m.y H:i', $schTime) . '] ' . $urlQuery; |
|
| 505 | |||
| 506 | 4 | $theUrl = ($vv['subCfg']['baseUrl'] ? $vv['subCfg']['baseUrl'] : GeneralUtility::getIndpEnv('TYPO3_SITE_URL')) . $urlQuery; |
|
| 507 | |||
| 508 | // Submit for crawling! |
||
| 509 | 4 | if ($submitCrawlUrls) { |
|
| 510 | 4 | $added = $this->addUrl( |
|
| 511 | 4 | $pageRow['uid'], |
|
| 512 | 4 | $theUrl, |
|
| 513 | 4 | $vv['subCfg'], |
|
| 514 | 4 | $scheduledTime, |
|
| 515 | 4 | $configurationHash, |
|
| 516 | 4 | $skipInnerCheck |
|
| 517 | ); |
||
| 518 | 4 | if ($added === false) { |
|
| 519 | 4 | $urlList .= ' (Url already existed)'; |
|
| 520 | } |
||
| 521 | } elseif ($downloadCrawlUrls) { |
||
| 522 | $downloadUrls[$theUrl] = $theUrl; |
||
| 523 | } |
||
| 524 | |||
| 525 | 4 | $urlList .= '<br />'; |
|
| 526 | } |
||
| 527 | 4 | $duplicateTrack[$uKey] = true; |
|
| 528 | } |
||
| 529 | } |
||
| 530 | } else { |
||
| 531 | $urlList = 'ERROR - no URL generated'; |
||
| 532 | } |
||
| 533 | |||
| 534 | 4 | return $urlList; |
|
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Returns true if input processing instruction is among registered ones. |
||
| 539 | * |
||
| 540 | * @param string $piString PI to test |
||
| 541 | * @param array $incomingProcInstructions Processing instructions |
||
| 542 | * @return boolean |
||
| 543 | */ |
||
| 544 | 5 | public function drawURLs_PIfilter($piString, array $incomingProcInstructions) |
|
| 556 | |||
| 557 | 5 | public function getPageTSconfigForId($id) |
|
| 579 | |||
| 580 | /** |
||
| 581 | * This methods returns an array of configurations. |
||
| 582 | * And no urls! |
||
| 583 | * |
||
| 584 | * @param integer $id Page ID |
||
| 585 | * @param bool $forceSsl Use https |
||
| 586 | * @return array |
||
| 587 | * |
||
| 588 | * TODO: Should be switched back to protected - TNM 2018-11-16 |
||
| 589 | */ |
||
| 590 | 4 | public function getUrlsForPageId($id, $forceSsl = false) |
|
| 591 | { |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Checks if a domain record exist and returns the base-url based on the record. If not the given baseUrl string is used. |
||
| 726 | * |
||
| 727 | * @param string $baseUrl |
||
| 728 | * @param integer $sysDomainUid |
||
| 729 | * @param bool $ssl |
||
| 730 | * @return string |
||
| 731 | */ |
||
| 732 | 4 | protected function getBaseUrlForConfigurationRecord($baseUrl, $sysDomainUid, $ssl = false) |
|
| 752 | |||
| 753 | 1 | public function getConfigurationsForBranch($rootid, $depth) |
|
| 754 | { |
||
| 755 | 1 | $configurationsForBranch = []; |
|
| 756 | |||
| 757 | 1 | $pageTSconfig = $this->getPageTSconfigForId($rootid); |
|
| 758 | 1 | if (is_array($pageTSconfig) && is_array($pageTSconfig['tx_crawler.']['crawlerCfg.']) && is_array($pageTSconfig['tx_crawler.']['crawlerCfg.']['paramSets.'])) { |
|
| 759 | $sets = $pageTSconfig['tx_crawler.']['crawlerCfg.']['paramSets.']; |
||
| 760 | if (is_array($sets)) { |
||
| 761 | foreach ($sets as $key => $value) { |
||
| 762 | if (!is_array($value)) { |
||
| 763 | continue; |
||
| 764 | } |
||
| 765 | $configurationsForBranch[] = substr($key, -1) == '.' ? substr($key, 0, -1) : $key; |
||
| 766 | } |
||
| 767 | } |
||
| 768 | } |
||
| 769 | 1 | $pids = []; |
|
| 770 | 1 | $rootLine = BackendUtility::BEgetRootLine($rootid); |
|
| 771 | 1 | foreach ($rootLine as $node) { |
|
| 772 | 1 | $pids[] = $node['uid']; |
|
| 773 | } |
||
| 774 | /* @var PageTreeView $tree */ |
||
| 775 | 1 | $tree = GeneralUtility::makeInstance(PageTreeView::class); |
|
| 776 | 1 | $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1); |
|
| 777 | 1 | $tree->init('AND ' . $perms_clause); |
|
| 778 | 1 | $tree->getTree($rootid, $depth, ''); |
|
| 779 | 1 | foreach ($tree->tree as $node) { |
|
| 780 | $pids[] = $node['row']['uid']; |
||
| 781 | } |
||
| 782 | |||
| 783 | 1 | $res = $this->db->exec_SELECTquery( |
|
| 784 | 1 | '*', |
|
| 785 | 1 | 'tx_crawler_configuration', |
|
| 786 | 1 | 'pid IN (' . implode(',', $pids) . ') ' . |
|
| 787 | 1 | BackendUtility::BEenableFields('tx_crawler_configuration') . |
|
| 788 | 1 | BackendUtility::deleteClause('tx_crawler_configuration') . ' ' . |
|
| 789 | 1 | BackendUtility::versioningPlaceholderClause('tx_crawler_configuration') . ' ' |
|
| 790 | ); |
||
| 791 | |||
| 792 | 1 | while ($row = $this->db->sql_fetch_assoc($res)) { |
|
| 793 | 1 | $configurationsForBranch[] = $row['name']; |
|
| 794 | } |
||
| 795 | 1 | $this->db->sql_free_result($res); |
|
| 796 | 1 | return $configurationsForBranch; |
|
| 797 | } |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Check if a user has access to an item |
||
| 801 | * (e.g. get the group list of the current logged in user from $GLOBALS['TSFE']->gr_list) |
||
| 802 | * |
||
| 803 | * @see \TYPO3\CMS\Frontend\Page\PageRepository::getMultipleGroupsWhereClause() |
||
| 804 | * @param string $groupList Comma-separated list of (fe_)group UIDs from a user |
||
| 805 | * @param string $accessList Comma-separated list of (fe_)group UIDs of the item to access |
||
| 806 | * @return bool TRUE if at least one of the users group UIDs is in the access list or the access list is empty |
||
| 807 | */ |
||
| 808 | 3 | public function hasGroupAccess($groupList, $accessList) |
|
| 820 | |||
| 821 | /** |
||
| 822 | * Parse GET vars of input Query into array with key=>value pairs |
||
| 823 | * |
||
| 824 | * @param string $inputQuery Input query string |
||
| 825 | * @return array |
||
| 826 | */ |
||
| 827 | 7 | public function parseParams($inputQuery) |
|
| 842 | |||
| 843 | /** |
||
| 844 | * Will expand the parameters configuration to individual values. This follows a certain syntax of the value of each parameter. |
||
| 845 | * Syntax of values: |
||
| 846 | * - Basically: If the value is wrapped in [...] it will be expanded according to the following syntax, otherwise the value is taken literally |
||
| 847 | * - Configuration is splitted by "|" and the parts are processed individually and finally added together |
||
| 848 | * - For each configuration part: |
||
| 849 | * - "[int]-[int]" = Integer range, will be expanded to all values in between, values included, starting from low to high (max. 1000). Example "1-34" or "-40--30" |
||
| 850 | * - "_TABLE:[TCA table name];[_PID:[optional page id, default is current page]];[_ENABLELANG:1]" = Look up of table records from PID, filtering out deleted records. Example "_TABLE:tt_content; _PID:123" |
||
| 851 | * _ENABLELANG:1 picks only original records without their language overlays |
||
| 852 | * - Default: Literal value |
||
| 853 | * |
||
| 854 | * @param array $paramArray Array with key (GET var name) and values (value of GET var which is configuration for expansion) |
||
| 855 | * @param integer $pid Current page ID |
||
| 856 | * @return array |
||
| 857 | */ |
||
| 858 | 4 | public function expandParameters($paramArray, $pid) |
|
| 968 | |||
| 969 | /** |
||
| 970 | * Compiling URLs from parameter array (output of expandParameters()) |
||
| 971 | * The number of URLs will be the multiplication of the number of parameter values for each key |
||
| 972 | * |
||
| 973 | * @param array $paramArray Output of expandParameters(): Array with keys (GET var names) and for each an array of values |
||
| 974 | * @param array $urls URLs accumulated in this array (for recursion) |
||
| 975 | * @return array |
||
| 976 | */ |
||
| 977 | 7 | public function compileUrls($paramArray, $urls = []) |
|
| 1002 | |||
| 1003 | /************************************ |
||
| 1004 | * |
||
| 1005 | * Crawler log |
||
| 1006 | * |
||
| 1007 | ************************************/ |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Return array of records from crawler queue for input page ID |
||
| 1011 | * |
||
| 1012 | * @param integer $id Page ID for which to look up log entries. |
||
| 1013 | * @param string$filter Filter: "all" => all entries, "pending" => all that is not yet run, "finished" => all complete ones |
||
| 1014 | * @param boolean $doFlush If TRUE, then entries selected at DELETED(!) instead of selected! |
||
| 1015 | * @param boolean $doFullFlush |
||
| 1016 | * @param integer $itemsPerPage Limit the amount of entries per page default is 10 |
||
| 1017 | * @return array |
||
| 1018 | */ |
||
| 1019 | 4 | public function getLogEntriesForPageId($id, $filter = '', $doFlush = false, $doFullFlush = false, $itemsPerPage = 10) |
|
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Return array of records from crawler queue for input set ID |
||
| 1051 | * |
||
| 1052 | * @param integer $set_id Set ID for which to look up log entries. |
||
| 1053 | * @param string $filter Filter: "all" => all entries, "pending" => all that is not yet run, "finished" => all complete ones |
||
| 1054 | * @param boolean $doFlush If TRUE, then entries selected at DELETED(!) instead of selected! |
||
| 1055 | * @param integer $itemsPerPage Limit the amount of entires per page default is 10 |
||
| 1056 | * @return array |
||
| 1057 | */ |
||
| 1058 | 6 | public function getLogEntriesForSetId($set_id, $filter = '', $doFlush = false, $doFullFlush = false, $itemsPerPage = 10) |
|
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Removes queue entries |
||
| 1090 | * |
||
| 1091 | * @param string $where SQL related filter for the entries which should be removed |
||
| 1092 | * @return void |
||
| 1093 | */ |
||
| 1094 | 10 | protected function flushQueue($where = '') |
|
| 1127 | |||
| 1128 | /** |
||
| 1129 | * Adding call back entries to log (called from hooks typically, see indexed search class "class.crawler.php" |
||
| 1130 | * |
||
| 1131 | * @param integer $setId Set ID |
||
| 1132 | * @param array $params Parameters to pass to call back function |
||
| 1133 | * @param string $callBack Call back object reference, eg. 'EXT:indexed_search/class.crawler.php:&tx_indexedsearch_crawler' |
||
| 1134 | * @param integer $page_id Page ID to attach it to |
||
| 1135 | * @param integer $schedule Time at which to activate |
||
| 1136 | * @return void |
||
| 1137 | */ |
||
| 1138 | public function addQueueEntry_callBack($setId, $params, $callBack, $page_id = 0, $schedule = 0) |
||
| 1157 | |||
| 1158 | /************************************ |
||
| 1159 | * |
||
| 1160 | * URL setting |
||
| 1161 | * |
||
| 1162 | ************************************/ |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Setting a URL for crawling: |
||
| 1166 | * |
||
| 1167 | * @param integer $id Page ID |
||
| 1168 | * @param string $url Complete URL |
||
| 1169 | * @param array $subCfg Sub configuration array (from TS config) |
||
| 1170 | * @param integer $tstamp Scheduled-time |
||
| 1171 | * @param string $configurationHash (optional) configuration hash |
||
| 1172 | * @param bool $skipInnerDuplicationCheck (optional) skip inner duplication check |
||
| 1173 | * @return bool |
||
| 1174 | */ |
||
| 1175 | 8 | public function addUrl( |
|
| 1176 | $id, |
||
| 1177 | $url, |
||
| 1178 | array $subCfg, |
||
| 1179 | $tstamp, |
||
| 1180 | $configurationHash = '', |
||
| 1181 | $skipInnerDuplicationCheck = false |
||
| 1182 | ) { |
||
| 1183 | 8 | $urlAdded = false; |
|
| 1184 | 8 | $rows = []; |
|
| 1185 | |||
| 1186 | // Creating parameters: |
||
| 1187 | $parameters = [ |
||
| 1188 | 8 | 'url' => $url, |
|
| 1189 | ]; |
||
| 1190 | |||
| 1191 | // fe user group simulation: |
||
| 1192 | 8 | $uGs = implode(',', array_unique(GeneralUtility::intExplode(',', $subCfg['userGroups'], true))); |
|
| 1193 | 8 | if ($uGs) { |
|
| 1194 | 1 | $parameters['feUserGroupList'] = $uGs; |
|
| 1195 | } |
||
| 1196 | |||
| 1197 | // Setting processing instructions |
||
| 1198 | 8 | $parameters['procInstructions'] = GeneralUtility::trimExplode(',', $subCfg['procInstrFilter']); |
|
| 1199 | 8 | if (is_array($subCfg['procInstrParams.'])) { |
|
| 1200 | 5 | $parameters['procInstrParams'] = $subCfg['procInstrParams.']; |
|
| 1201 | } |
||
| 1202 | |||
| 1203 | // Possible TypoScript Template Parents |
||
| 1204 | 8 | $parameters['rootTemplatePid'] = $subCfg['rootTemplatePid']; |
|
| 1205 | |||
| 1206 | // Compile value array: |
||
| 1207 | 8 | $parameters_serialized = serialize($parameters); |
|
| 1208 | $fieldArray = [ |
||
| 1209 | 8 | 'page_id' => intval($id), |
|
| 1210 | 8 | 'parameters' => $parameters_serialized, |
|
| 1211 | 8 | 'parameters_hash' => GeneralUtility::shortMD5($parameters_serialized), |
|
| 1212 | 8 | 'configuration_hash' => $configurationHash, |
|
| 1213 | 8 | 'scheduled' => $tstamp, |
|
| 1214 | 8 | 'exec_time' => 0, |
|
| 1215 | 8 | 'set_id' => intval($this->setID), |
|
| 1216 | 8 | 'result_data' => '', |
|
| 1217 | 8 | 'configuration' => $subCfg['key'], |
|
| 1218 | ]; |
||
| 1219 | |||
| 1220 | 8 | if ($this->registerQueueEntriesInternallyOnly) { |
|
| 1221 | //the entries will only be registered and not stored to the database |
||
| 1222 | 1 | $this->queueEntries[] = $fieldArray; |
|
| 1223 | } else { |
||
| 1224 | 7 | if (!$skipInnerDuplicationCheck) { |
|
| 1225 | // check if there is already an equal entry |
||
| 1226 | 6 | $rows = $this->getDuplicateRowsIfExist($tstamp, $fieldArray); |
|
| 1227 | } |
||
| 1228 | |||
| 1229 | 7 | if (count($rows) == 0) { |
|
| 1230 | 6 | $this->db->exec_INSERTquery('tx_crawler_queue', $fieldArray); |
|
| 1231 | 6 | $uid = $this->db->sql_insert_id(); |
|
| 1232 | 6 | $rows[] = $uid; |
|
| 1233 | 6 | $urlAdded = true; |
|
| 1234 | |||
| 1235 | // The event dispatcher is deprecated since crawler v6.4.0, will be removed in crawler v7.0.0. |
||
| 1236 | // Please use the Signal instead. |
||
| 1237 | 6 | EventDispatcher::getInstance()->post('urlAddedToQueue', $this->setID, ['uid' => $uid, 'fieldArray' => $fieldArray]); |
|
| 1238 | |||
| 1239 | 6 | $signalPayload = ['uid' => $uid, 'fieldArray' => $fieldArray]; |
|
| 1240 | 6 | SignalSlotUtility::emitSignal( |
|
| 1241 | 6 | __CLASS__, |
|
| 1242 | 6 | SignalSlotUtility::SIGNAL_URL_ADDED_TO_QUEUE, |
|
| 1243 | 6 | $signalPayload |
|
| 1244 | ); |
||
| 1245 | |||
| 1246 | } else { |
||
| 1247 | // The event dispatcher is deprecated since crawler v6.4.0, will be removed in crawler v7.0.0. |
||
| 1248 | // Please use the Signal instead. |
||
| 1249 | 3 | EventDispatcher::getInstance()->post('duplicateUrlInQueue', $this->setID, ['rows' => $rows, 'fieldArray' => $fieldArray]); |
|
| 1250 | |||
| 1251 | 3 | $signalPayload = ['rows' => $rows, 'fieldArray' => $fieldArray]; |
|
| 1252 | 3 | SignalSlotUtility::emitSignal( |
|
| 1253 | 3 | __CLASS__, |
|
| 1254 | 3 | SignalSlotUtility::SIGNAL_DUPLICATE_URL_IN_QUEUE, |
|
| 1255 | 3 | $signalPayload |
|
| 1256 | ); |
||
| 1257 | } |
||
| 1258 | } |
||
| 1259 | |||
| 1260 | 8 | return $urlAdded; |
|
| 1261 | } |
||
| 1262 | |||
| 1263 | /** |
||
| 1264 | * This method determines duplicates for a queue entry with the same parameters and this timestamp. |
||
| 1265 | * If the timestamp is in the past, it will check if there is any unprocessed queue entry in the past. |
||
| 1266 | * If the timestamp is in the future it will check, if the queued entry has exactly the same timestamp |
||
| 1267 | * |
||
| 1268 | * @param int $tstamp |
||
| 1269 | * @param array $fieldArray |
||
| 1270 | * |
||
| 1271 | * @return array |
||
| 1272 | */ |
||
| 1273 | 9 | protected function getDuplicateRowsIfExist($tstamp, $fieldArray) |
|
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Returns the current system time |
||
| 1316 | * |
||
| 1317 | * @return int |
||
| 1318 | */ |
||
| 1319 | public function getCurrentTime() |
||
| 1323 | |||
| 1324 | /************************************ |
||
| 1325 | * |
||
| 1326 | * URL reading |
||
| 1327 | * |
||
| 1328 | ************************************/ |
||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Read URL for single queue entry |
||
| 1332 | * |
||
| 1333 | * @param integer $queueId |
||
| 1334 | * @param boolean $force If set, will process even if exec_time has been set! |
||
| 1335 | * @return integer |
||
| 1336 | */ |
||
| 1337 | public function readUrl($queueId, $force = false) |
||
| 1419 | |||
| 1420 | /** |
||
| 1421 | * Read URL for not-yet-inserted log-entry |
||
| 1422 | * |
||
| 1423 | * @param array $field_array Queue field array, |
||
| 1424 | * |
||
| 1425 | * @return string |
||
| 1426 | */ |
||
| 1427 | public function readUrlFromArray($field_array) |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Read URL for a queue record |
||
| 1454 | * |
||
| 1455 | * @param array $queueRec Queue record |
||
| 1456 | * @return string |
||
| 1457 | */ |
||
| 1458 | public function readUrl_exec($queueRec) |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Gets the content of a URL. |
||
| 1499 | * |
||
| 1500 | * @param string $originalUrl URL to read |
||
| 1501 | * @param string $crawlerId Crawler ID string (qid + hash to verify) |
||
| 1502 | * @param integer $timeout Timeout time |
||
| 1503 | * @param integer $recursion Recursion limiter for 302 redirects |
||
| 1504 | * @return array |
||
| 1505 | */ |
||
| 1506 | 2 | public function requestUrl($originalUrl, $crawlerId, $timeout = 2, $recursion = 10) |
|
| 1599 | |||
| 1600 | /** |
||
| 1601 | * Gets the base path of the website frontend. |
||
| 1602 | * (e.g. if you call http://mydomain.com/cms/index.php in |
||
| 1603 | * the browser the base path is "/cms/") |
||
| 1604 | * |
||
| 1605 | * @return string Base path of the website frontend |
||
| 1606 | */ |
||
| 1607 | protected function getFrontendBasePath() |
||
| 1630 | |||
| 1631 | /** |
||
| 1632 | * Executes a shell command and returns the outputted result. |
||
| 1633 | * |
||
| 1634 | * @param string $command Shell command to be executed |
||
| 1635 | * @return string Outputted result of the command execution |
||
| 1636 | */ |
||
| 1637 | protected function executeShellCommand($command) |
||
| 1642 | |||
| 1643 | /** |
||
| 1644 | * Reads HTTP response from the given stream. |
||
| 1645 | * |
||
| 1646 | * @param resource $streamPointer Pointer to connection stream. |
||
| 1647 | * @return array Associative array with the following items: |
||
| 1648 | * headers <array> Response headers sent by server. |
||
| 1649 | * content <array> Content, with each line as an array item. |
||
| 1650 | */ |
||
| 1651 | 1 | protected function getHttpResponseFromStream($streamPointer) |
|
| 1674 | |||
| 1675 | /** |
||
| 1676 | * @param message |
||
| 1677 | */ |
||
| 1678 | 2 | protected function log($message) |
|
| 1687 | |||
| 1688 | /** |
||
| 1689 | * Builds HTTP request headers. |
||
| 1690 | * |
||
| 1691 | * @param array $url |
||
| 1692 | * @param string $crawlerId |
||
| 1693 | * |
||
| 1694 | * @return array |
||
| 1695 | */ |
||
| 1696 | 6 | protected function buildRequestHeaderArray(array $url, $crawlerId) |
|
| 1712 | |||
| 1713 | /** |
||
| 1714 | * Check if the submitted HTTP-Header contains a redirect location and built new crawler-url |
||
| 1715 | * |
||
| 1716 | * @param array $headers HTTP Header |
||
| 1717 | * @param string $user HTTP Auth. User |
||
| 1718 | * @param string $pass HTTP Auth. Password |
||
| 1719 | * @return bool|string |
||
| 1720 | */ |
||
| 1721 | 12 | protected function getRequestUrlFrom302Header($headers, $user = '', $pass = '') |
|
| 1755 | |||
| 1756 | /************************** |
||
| 1757 | * |
||
| 1758 | * tslib_fe hooks: |
||
| 1759 | * |
||
| 1760 | **************************/ |
||
| 1761 | |||
| 1762 | /** |
||
| 1763 | * Initialization hook (called after database connection) |
||
| 1764 | * Takes the "HTTP_X_T3CRAWLER" header and looks up queue record and verifies if the session comes from the system (by comparing hashes) |
||
| 1765 | * |
||
| 1766 | * @param array $params Parameters from frontend |
||
| 1767 | * @param object $ref TSFE object (reference under PHP5) |
||
| 1768 | * @return void |
||
| 1769 | * |
||
| 1770 | * FIXME: Look like this is not used, in commit 9910d3f40cce15f4e9b7bcd0488bf21f31d53ebc it's added as public, |
||
| 1771 | * FIXME: I think this can be removed. (TNM) |
||
| 1772 | */ |
||
| 1773 | public function fe_init(&$params, $ref) |
||
| 1790 | |||
| 1791 | /***************************** |
||
| 1792 | * |
||
| 1793 | * Compiling URLs to crawl - tools |
||
| 1794 | * |
||
| 1795 | *****************************/ |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * @param integer $id Root page id to start from. |
||
| 1799 | * @param integer $depth Depth of tree, 0=only id-page, 1= on sublevel, 99 = infinite |
||
| 1800 | * @param integer $scheduledTime Unix Time when the URL is timed to be visited when put in queue |
||
| 1801 | * @param integer $reqMinute Number of requests per minute (creates the interleave between requests) |
||
| 1802 | * @param boolean $submitCrawlUrls If set, submits the URLs to queue in database (real crawling) |
||
| 1803 | * @param boolean $downloadCrawlUrls If set (and submitcrawlUrls is false) will fill $downloadUrls with entries) |
||
| 1804 | * @param array $incomingProcInstructions Array of processing instructions |
||
| 1805 | * @param array $configurationSelection Array of configuration keys |
||
| 1806 | * @return string |
||
| 1807 | */ |
||
| 1808 | public function getPageTreeAndUrls( |
||
| 1895 | |||
| 1896 | /** |
||
| 1897 | * Expands exclude string |
||
| 1898 | * |
||
| 1899 | * @param string $excludeString Exclude string |
||
| 1900 | * @return array |
||
| 1901 | */ |
||
| 1902 | 1 | public function expandExcludeString($excludeString) |
|
| 1947 | |||
| 1948 | /** |
||
| 1949 | * Create the rows for display of the page tree |
||
| 1950 | * For each page a number of rows are shown displaying GET variable configuration |
||
| 1951 | * |
||
| 1952 | * @param array Page row |
||
| 1953 | * @param string Page icon and title for row |
||
| 1954 | * @return string HTML <tr> content (one or more) |
||
| 1955 | */ |
||
| 1956 | public function drawURLs_addRowsForPage(array $pageRow, $pageTitleAndIcon) |
||
| 2065 | |||
| 2066 | /***************************** |
||
| 2067 | * |
||
| 2068 | * CLI functions |
||
| 2069 | * |
||
| 2070 | *****************************/ |
||
| 2071 | |||
| 2072 | /** |
||
| 2073 | * Main function for running from Command Line PHP script (cron job) |
||
| 2074 | * See ext/crawler/cli/crawler_cli.phpsh for details |
||
| 2075 | * |
||
| 2076 | * @return int number of remaining items or false if error |
||
| 2077 | */ |
||
| 2078 | public function CLI_main() |
||
| 2119 | |||
| 2120 | /** |
||
| 2121 | * Function executed by crawler_im.php cli script. |
||
| 2122 | * |
||
| 2123 | * @return void |
||
| 2124 | */ |
||
| 2125 | public function CLI_main_im() |
||
| 2234 | |||
| 2235 | /** |
||
| 2236 | * Function executed by crawler_im.php cli script. |
||
| 2237 | * |
||
| 2238 | * @return bool |
||
| 2239 | */ |
||
| 2240 | public function CLI_main_flush() |
||
| 2278 | |||
| 2279 | /** |
||
| 2280 | * Obtains configuration keys from the CLI arguments |
||
| 2281 | * |
||
| 2282 | * @param QueueCommandLineController $cliObj |
||
| 2283 | * @return array |
||
| 2284 | * |
||
| 2285 | * @deprecated since crawler v6.3.0, will be removed in crawler v7.0.0. |
||
| 2286 | */ |
||
| 2287 | protected function getConfigurationKeys(QueueCommandLineController $cliObj) |
||
| 2292 | |||
| 2293 | /** |
||
| 2294 | * Running the functionality of the CLI (crawling URLs from queue) |
||
| 2295 | * |
||
| 2296 | * @param int $countInARun |
||
| 2297 | * @param int $sleepTime |
||
| 2298 | * @param int $sleepAfterFinish |
||
| 2299 | * @return string |
||
| 2300 | */ |
||
| 2301 | public function CLI_run($countInARun, $sleepTime, $sleepAfterFinish) |
||
| 2408 | |||
| 2409 | /** |
||
| 2410 | * Activate hooks |
||
| 2411 | * |
||
| 2412 | * @return void |
||
| 2413 | */ |
||
| 2414 | public function CLI_runHooks() |
||
| 2426 | |||
| 2427 | /** |
||
| 2428 | * Try to acquire a new process with the given id |
||
| 2429 | * also performs some auto-cleanup for orphan processes |
||
| 2430 | * @todo preemption might not be the most elegant way to clean up |
||
| 2431 | * |
||
| 2432 | * @param string $id identification string for the process |
||
| 2433 | * @return boolean |
||
| 2434 | */ |
||
| 2435 | public function CLI_checkAndAcquireNewProcess($id) |
||
| 2491 | |||
| 2492 | /** |
||
| 2493 | * Release a process and the required resources |
||
| 2494 | * |
||
| 2495 | * @param mixed $releaseIds string with a single process-id or array with multiple process-ids |
||
| 2496 | * @param boolean $withinLock show whether the DB-actions are included within an existing lock |
||
| 2497 | * @return boolean |
||
| 2498 | */ |
||
| 2499 | public function CLI_releaseProcesses($releaseIds, $withinLock = false) |
||
| 2561 | |||
| 2562 | /** |
||
| 2563 | * Delete processes marked as deleted |
||
| 2564 | * |
||
| 2565 | * @return void |
||
| 2566 | */ |
||
| 2567 | 1 | public function CLI_deleteProcessesMarkedDeleted() |
|
| 2571 | |||
| 2572 | /** |
||
| 2573 | * Check if there are still resources left for the process with the given id |
||
| 2574 | * Used to determine timeouts and to ensure a proper cleanup if there's a timeout |
||
| 2575 | * |
||
| 2576 | * @param string identification string for the process |
||
| 2577 | * @return boolean determines if the process is still active / has resources |
||
| 2578 | * |
||
| 2579 | * FIXME: Please remove Transaction, not needed as only a select query. |
||
| 2580 | */ |
||
| 2581 | public function CLI_checkIfProcessIsActive($pid) |
||
| 2600 | |||
| 2601 | /** |
||
| 2602 | * Create a unique Id for the current process |
||
| 2603 | * |
||
| 2604 | * @return string the ID |
||
| 2605 | */ |
||
| 2606 | 2 | public function CLI_buildProcessId() |
|
| 2613 | |||
| 2614 | /** |
||
| 2615 | * @param bool $get_as_float |
||
| 2616 | * |
||
| 2617 | * @return mixed |
||
| 2618 | */ |
||
| 2619 | protected function microtime($get_as_float = false) |
||
| 2623 | |||
| 2624 | /** |
||
| 2625 | * Prints a message to the stdout (only if debug-mode is enabled) |
||
| 2626 | * |
||
| 2627 | * @param string $msg the message |
||
| 2628 | */ |
||
| 2629 | public function CLI_debug($msg) |
||
| 2636 | |||
| 2637 | /** |
||
| 2638 | * Get URL content by making direct request to TYPO3. |
||
| 2639 | * |
||
| 2640 | * @param string $url Page URL |
||
| 2641 | * @param int $crawlerId Crawler-ID |
||
| 2642 | * @return array |
||
| 2643 | */ |
||
| 2644 | 2 | protected function sendDirectRequest($url, $crawlerId) |
|
| 2675 | |||
| 2676 | /** |
||
| 2677 | * Cleans up entries that stayed for too long in the queue. These are: |
||
| 2678 | * - processed entries that are over 1.5 days in age |
||
| 2679 | * - scheduled entries that are over 7 days old |
||
| 2680 | * |
||
| 2681 | * @return void |
||
| 2682 | * |
||
| 2683 | * TODO: Should be switched back to protected - TNM 2018-11-16 |
||
| 2684 | */ |
||
| 2685 | public function cleanUpOldQueueEntries() |
||
| 2694 | |||
| 2695 | /** |
||
| 2696 | * Initializes a TypoScript Frontend necessary for using TypoScript and TypoLink functions |
||
| 2697 | * |
||
| 2698 | * @param int $id |
||
| 2699 | * @param int $typeNum |
||
| 2700 | * |
||
| 2701 | * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException |
||
| 2702 | * |
||
| 2703 | * @return void |
||
| 2704 | */ |
||
| 2705 | protected function initTSFE($id = 1, $typeNum = 0) |
||
| 2730 | |||
| 2731 | /** |
||
| 2732 | * Returns a md5 hash generated from a serialized configuration array. |
||
| 2733 | * |
||
| 2734 | * @param array $configuration |
||
| 2735 | * |
||
| 2736 | * @return string |
||
| 2737 | */ |
||
| 2738 | 10 | protected function getConfigurationHash(array $configuration) { |
|
| 2743 | |||
| 2744 | /** |
||
| 2745 | * Check whether the Crawling Protocol should be http or https |
||
| 2746 | * |
||
| 2747 | * @param $crawlerConfiguration |
||
| 2748 | * @param $pageConfiguration |
||
| 2749 | * |
||
| 2750 | * @return bool |
||
| 2751 | */ |
||
| 2752 | 10 | protected function isCrawlingProtocolHttps($crawlerConfiguration, $pageConfiguration) { |
|
| 2764 | } |
||
| 2765 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: