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 |
||
| 60 | class CrawlerController |
||
| 61 | { |
||
| 62 | const CLI_STATUS_NOTHING_PROCCESSED = 0; |
||
| 63 | const CLI_STATUS_REMAIN = 1; //queue not empty |
||
| 64 | const CLI_STATUS_PROCESSED = 2; //(some) queue items where processed |
||
| 65 | const CLI_STATUS_ABORTED = 4; //instance didn't finish |
||
| 66 | const CLI_STATUS_POLLABLE_PROCESSED = 8; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var integer |
||
| 70 | */ |
||
| 71 | public $setID = 0; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | public $processID = ''; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * One hour is max stalled time for the CLI |
||
| 80 | * If the process had the status "start" for 3600 seconds, it will be regarded stalled and a new process is started |
||
| 81 | * |
||
| 82 | * @var integer |
||
| 83 | */ |
||
| 84 | public $max_CLI_exec_time = 3600; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | public $duplicateTrack = []; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var array |
||
| 93 | */ |
||
| 94 | public $downloadUrls = []; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | public $incomingProcInstructions = []; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | public $incomingConfigurationSelection = []; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var bool |
||
| 108 | */ |
||
| 109 | public $registerQueueEntriesInternallyOnly = false; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var array |
||
| 113 | */ |
||
| 114 | public $queueEntries = []; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var array |
||
| 118 | */ |
||
| 119 | public $urlList = []; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var boolean |
||
| 123 | */ |
||
| 124 | public $debugMode = false; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var array |
||
| 128 | */ |
||
| 129 | public $extensionSettings = []; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Mount Point |
||
| 133 | * |
||
| 134 | * @var boolean |
||
| 135 | */ |
||
| 136 | public $MP = false; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var string |
||
| 140 | */ |
||
| 141 | protected $processFilename; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Holds the internal access mode can be 'gui','cli' or 'cli_im' |
||
| 145 | * |
||
| 146 | * @var string |
||
| 147 | */ |
||
| 148 | protected $accessMode; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @var DatabaseConnection |
||
| 152 | */ |
||
| 153 | private $db; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @var BackendUserAuthentication |
||
| 157 | */ |
||
| 158 | private $backendUser; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @var integer |
||
| 162 | */ |
||
| 163 | private $scheduledTime = 0; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @var integer |
||
| 167 | */ |
||
| 168 | private $reqMinute = 0; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @var bool |
||
| 172 | */ |
||
| 173 | private $submitCrawlUrls = false; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @var bool |
||
| 177 | */ |
||
| 178 | private $downloadCrawlUrls = false; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @var QueueRepository |
||
| 182 | */ |
||
| 183 | protected $queueRepository; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Method to set the accessMode can be gui, cli or cli_im |
||
| 187 | * |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | 1 | public function getAccessMode() |
|
| 191 | { |
||
| 192 | 1 | return $this->accessMode; |
|
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param string $accessMode |
||
| 197 | */ |
||
| 198 | 1 | public function setAccessMode($accessMode) |
|
| 199 | { |
||
| 200 | 1 | $this->accessMode = $accessMode; |
|
| 201 | 1 | } |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Set disabled status to prevent processes from being processed |
||
| 205 | * |
||
| 206 | * @param bool $disabled (optional, defaults to true) |
||
| 207 | * @return void |
||
| 208 | */ |
||
| 209 | 3 | public function setDisabled($disabled = true) |
|
| 210 | { |
||
| 211 | 3 | if ($disabled) { |
|
| 212 | 2 | GeneralUtility::writeFile($this->processFilename, ''); |
|
| 213 | } else { |
||
| 214 | 1 | if (is_file($this->processFilename)) { |
|
| 215 | 1 | unlink($this->processFilename); |
|
| 216 | } |
||
| 217 | } |
||
| 218 | 3 | } |
|
| 219 | |||
| 220 | /** |
||
| 221 | * Get disable status |
||
| 222 | * |
||
| 223 | * @return bool true if disabled |
||
| 224 | */ |
||
| 225 | 3 | public function getDisabled() |
|
| 226 | { |
||
| 227 | 3 | if (is_file($this->processFilename)) { |
|
| 228 | 2 | return true; |
|
| 229 | } else { |
||
| 230 | 1 | return false; |
|
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param string $filenameWithPath |
||
| 236 | * |
||
| 237 | * @return void |
||
| 238 | */ |
||
| 239 | 4 | public function setProcessFilename($filenameWithPath) |
|
| 240 | { |
||
| 241 | 4 | $this->processFilename = $filenameWithPath; |
|
| 242 | 4 | } |
|
| 243 | |||
| 244 | /** |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | 1 | public function getProcessFilename() |
|
| 248 | { |
||
| 249 | 1 | return $this->processFilename; |
|
| 250 | } |
||
| 251 | |||
| 252 | /************************************ |
||
| 253 | * |
||
| 254 | * Getting URLs based on Page TSconfig |
||
| 255 | * |
||
| 256 | ************************************/ |
||
| 257 | |||
| 258 | public function __construct() |
||
| 259 | { |
||
| 260 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
||
| 261 | $this->queueRepository = $objectManager->get(QueueRepository::class); |
||
| 262 | |||
| 263 | $this->db = $GLOBALS['TYPO3_DB']; |
||
| 264 | $this->backendUser = $GLOBALS['BE_USER']; |
||
| 265 | $this->processFilename = PATH_site . 'typo3temp/tx_crawler.proc'; |
||
| 266 | |||
| 267 | $settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['crawler']); |
||
| 268 | $settings = is_array($settings) ? $settings : []; |
||
| 269 | |||
| 270 | // read ext_em_conf_template settings and set |
||
| 271 | $this->setExtensionSettings($settings); |
||
| 272 | |||
| 273 | // set defaults: |
||
| 274 | if (MathUtility::convertToPositiveInteger($this->extensionSettings['countInARun']) == 0) { |
||
| 275 | $this->extensionSettings['countInARun'] = 100; |
||
| 276 | } |
||
| 277 | |||
| 278 | $this->extensionSettings['processLimit'] = MathUtility::forceIntegerInRange($this->extensionSettings['processLimit'], 1, 99, 1); |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Sets the extensions settings (unserialized pendant of $TYPO3_CONF_VARS['EXT']['extConf']['crawler']). |
||
| 283 | * |
||
| 284 | * @param array $extensionSettings |
||
| 285 | * @return void |
||
| 286 | */ |
||
| 287 | 9 | public function setExtensionSettings(array $extensionSettings) |
|
| 288 | { |
||
| 289 | 9 | $this->extensionSettings = $extensionSettings; |
|
| 290 | 9 | } |
|
| 291 | |||
| 292 | /** |
||
| 293 | * Check if the given page should be crawled |
||
| 294 | * |
||
| 295 | * @param array $pageRow |
||
| 296 | * @return false|string false if the page should be crawled (not excluded), true / skipMessage if it should be skipped |
||
| 297 | */ |
||
| 298 | 6 | public function checkIfPageShouldBeSkipped(array $pageRow) |
|
| 299 | { |
||
| 300 | 6 | $skipPage = false; |
|
| 301 | 6 | $skipMessage = 'Skipped'; // message will be overwritten later |
|
| 302 | |||
| 303 | // if page is hidden |
||
| 304 | 6 | if (!$this->extensionSettings['crawlHiddenPages']) { |
|
| 305 | 6 | if ($pageRow['hidden']) { |
|
| 306 | 1 | $skipPage = true; |
|
| 307 | 1 | $skipMessage = 'Because page is hidden'; |
|
| 308 | } |
||
| 309 | } |
||
| 310 | |||
| 311 | 6 | if (!$skipPage) { |
|
| 312 | 5 | if (GeneralUtility::inList('3,4', $pageRow['doktype']) || $pageRow['doktype'] >= 199) { |
|
| 313 | 3 | $skipPage = true; |
|
| 314 | 3 | $skipMessage = 'Because doktype is not allowed'; |
|
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | 6 | if (!$skipPage) { |
|
| 319 | 2 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'])) { |
|
| 320 | 2 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'] as $key => $doktypeList) { |
|
| 321 | 1 | if (GeneralUtility::inList($doktypeList, $pageRow['doktype'])) { |
|
| 322 | 1 | $skipPage = true; |
|
| 323 | 1 | $skipMessage = 'Doktype was excluded by "' . $key . '"'; |
|
| 324 | 1 | break; |
|
| 325 | } |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | 6 | if (!$skipPage) { |
|
| 331 | // veto hook |
||
| 332 | 1 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'])) { |
|
| 333 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'] as $key => $func) { |
||
| 334 | $params = [ |
||
| 335 | 'pageRow' => $pageRow |
||
| 336 | ]; |
||
| 337 | // expects "false" if page is ok and "true" or a skipMessage if this page should _not_ be crawled |
||
| 338 | $veto = GeneralUtility::callUserFunction($func, $params, $this); |
||
| 339 | if ($veto !== false) { |
||
| 340 | $skipPage = true; |
||
| 341 | if (is_string($veto)) { |
||
| 342 | $skipMessage = $veto; |
||
| 343 | } else { |
||
| 344 | $skipMessage = 'Veto from hook "' . htmlspecialchars($key) . '"'; |
||
| 345 | } |
||
| 346 | // no need to execute other hooks if a previous one return a veto |
||
| 347 | break; |
||
| 348 | } |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } |
||
| 352 | |||
| 353 | 6 | return $skipPage ? $skipMessage : false; |
|
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Wrapper method for getUrlsForPageId() |
||
| 358 | * It returns an array of configurations and no urls! |
||
| 359 | * |
||
| 360 | * @param array $pageRow Page record with at least dok-type and uid columns. |
||
| 361 | * @param string $skipMessage |
||
| 362 | * @return array |
||
| 363 | * @see getUrlsForPageId() |
||
| 364 | */ |
||
| 365 | 2 | public function getUrlsForPageRow(array $pageRow, &$skipMessage = '') |
|
| 366 | { |
||
| 367 | 2 | $message = $this->checkIfPageShouldBeSkipped($pageRow); |
|
| 368 | |||
| 369 | 2 | if ($message === false) { |
|
| 370 | 1 | $forceSsl = ($pageRow['url_scheme'] === 2) ? true : false; |
|
| 371 | 1 | $res = $this->getUrlsForPageId($pageRow['uid'], $forceSsl); |
|
| 372 | 1 | $skipMessage = ''; |
|
| 373 | } else { |
||
| 374 | 1 | $skipMessage = $message; |
|
| 375 | 1 | $res = []; |
|
| 376 | } |
||
| 377 | |||
| 378 | 2 | return $res; |
|
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * This method is used to count if there are ANY unprocessed queue entries |
||
| 383 | * of a given page_id and the configuration which matches a given hash. |
||
| 384 | * If there if none, we can skip an inner detail check |
||
| 385 | * |
||
| 386 | * @param int $uid |
||
| 387 | * @param string $configurationHash |
||
| 388 | * @return boolean |
||
| 389 | */ |
||
| 390 | protected function noUnprocessedQueueEntriesForPageWithConfigurationHashExist($uid, $configurationHash) |
||
| 391 | { |
||
| 392 | $configurationHash = $this->db->fullQuoteStr($configurationHash, 'tx_crawler_queue'); |
||
| 393 | $res = $this->db->exec_SELECTquery('count(*) as anz', 'tx_crawler_queue', "page_id=" . intval($uid) . " AND configuration_hash=" . $configurationHash . " AND exec_time=0"); |
||
| 394 | $row = $this->db->sql_fetch_assoc($res); |
||
| 395 | |||
| 396 | return ($row['anz'] == 0); |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Creates a list of URLs from input array (and submits them to queue if asked for) |
||
| 401 | * See Web > Info module script + "indexed_search"'s crawler hook-client using this! |
||
| 402 | * |
||
| 403 | * @param array Information about URLs from pageRow to crawl. |
||
| 404 | * @param array Page row |
||
| 405 | * @param integer Unix time to schedule indexing to, typically time() |
||
| 406 | * @param integer Number of requests per minute (creates the interleave between requests) |
||
| 407 | * @param boolean If set, submits the URLs to queue |
||
| 408 | * @param boolean If set (and submitcrawlUrls is false) will fill $downloadUrls with entries) |
||
| 409 | * @param array Array which is passed by reference and contains the an id per url to secure we will not crawl duplicates |
||
| 410 | * @param array Array which will be filled with URLS for download if flag is set. |
||
| 411 | * @param array Array of processing instructions |
||
| 412 | * @return string List of URLs (meant for display in backend module) |
||
| 413 | * |
||
| 414 | */ |
||
| 415 | public function urlListFromUrlArray( |
||
| 416 | array $vv, |
||
| 417 | array $pageRow, |
||
| 418 | $scheduledTime, |
||
| 419 | $reqMinute, |
||
| 420 | $submitCrawlUrls, |
||
| 421 | $downloadCrawlUrls, |
||
| 422 | array &$duplicateTrack, |
||
| 423 | array &$downloadUrls, |
||
| 424 | array $incomingProcInstructions |
||
| 425 | ) { |
||
| 426 | $urlList = ''; |
||
| 427 | // realurl support (thanks to Ingo Renner) |
||
| 428 | if (ExtensionManagementUtility::isLoaded('realurl') && $vv['subCfg']['realurl']) { |
||
| 429 | |||
| 430 | /** @var tx_realurl $urlObj */ |
||
| 431 | $urlObj = GeneralUtility::makeInstance('tx_realurl'); |
||
| 432 | |||
| 433 | if (!empty($vv['subCfg']['baseUrl'])) { |
||
| 434 | $urlParts = parse_url($vv['subCfg']['baseUrl']); |
||
| 435 | $host = strtolower($urlParts['host']); |
||
| 436 | $urlObj->host = $host; |
||
| 437 | |||
| 438 | // First pass, finding configuration OR pointer string: |
||
| 439 | $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']; |
||
| 440 | |||
| 441 | // If it turned out to be a string pointer, then look up the real config: |
||
| 442 | if (is_string($urlObj->extConf)) { |
||
| 443 | $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']; |
||
| 444 | } |
||
| 445 | } |
||
| 446 | |||
| 447 | if (!$GLOBALS['TSFE']->sys_page) { |
||
| 448 | $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\PageRepository'); |
||
| 449 | } |
||
| 450 | |||
| 451 | if (!$GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) { |
||
| 452 | $GLOBALS['TSFE']->tmpl->rootLine[0]['uid'] = $urlObj->extConf['pagePath']['rootpage_id']; |
||
| 453 | } |
||
| 454 | } |
||
| 455 | |||
| 456 | if (is_array($vv['URLs'])) { |
||
| 457 | $configurationHash = $this->getConfigurationHash($vv); |
||
| 458 | $skipInnerCheck = $this->noUnprocessedQueueEntriesForPageWithConfigurationHashExist($pageRow['uid'], $configurationHash); |
||
| 459 | |||
| 460 | foreach ($vv['URLs'] as $urlQuery) { |
||
| 461 | if ($this->drawURLs_PIfilter($vv['subCfg']['procInstrFilter'], $incomingProcInstructions)) { |
||
| 462 | |||
| 463 | // Calculate cHash: |
||
| 464 | if ($vv['subCfg']['cHash']) { |
||
| 465 | /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */ |
||
| 466 | $cacheHash = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\CacheHashCalculator'); |
||
| 467 | $urlQuery .= '&cHash=' . $cacheHash->generateForParameters($urlQuery); |
||
| 468 | } |
||
| 469 | |||
| 470 | // Create key by which to determine unique-ness: |
||
| 471 | $uKey = $urlQuery . '|' . $vv['subCfg']['userGroups'] . '|' . $vv['subCfg']['baseUrl'] . '|' . $vv['subCfg']['procInstrFilter']; |
||
| 472 | |||
| 473 | // realurl support (thanks to Ingo Renner) |
||
| 474 | $urlQuery = 'index.php' . $urlQuery; |
||
| 475 | if (ExtensionManagementUtility::isLoaded('realurl') && $vv['subCfg']['realurl']) { |
||
| 476 | $params = [ |
||
| 477 | 'LD' => [ |
||
| 478 | 'totalURL' => $urlQuery |
||
| 479 | ], |
||
| 480 | 'TCEmainHook' => true |
||
| 481 | ]; |
||
| 482 | $urlObj->encodeSpURL($params); |
||
|
|
|||
| 483 | $urlQuery = $params['LD']['totalURL']; |
||
| 484 | } |
||
| 485 | |||
| 486 | // Scheduled time: |
||
| 487 | $schTime = $scheduledTime + round(count($duplicateTrack) * (60 / $reqMinute)); |
||
| 488 | $schTime = floor($schTime / 60) * 60; |
||
| 489 | |||
| 490 | if (isset($duplicateTrack[$uKey])) { |
||
| 491 | |||
| 492 | //if the url key is registered just display it and do not resubmit is |
||
| 493 | $urlList = '<em><span class="typo3-dimmed">' . htmlspecialchars($urlQuery) . '</span></em><br/>'; |
||
| 494 | } else { |
||
| 495 | $urlList = '[' . date('d.m.y H:i', $schTime) . '] ' . htmlspecialchars($urlQuery); |
||
| 496 | $this->urlList[] = '[' . date('d.m.y H:i', $schTime) . '] ' . $urlQuery; |
||
| 497 | |||
| 498 | $theUrl = ($vv['subCfg']['baseUrl'] ? $vv['subCfg']['baseUrl'] : GeneralUtility::getIndpEnv('TYPO3_SITE_URL')) . $urlQuery; |
||
| 499 | |||
| 500 | // Submit for crawling! |
||
| 501 | if ($submitCrawlUrls) { |
||
| 502 | $added = $this->addUrl( |
||
| 503 | $pageRow['uid'], |
||
| 504 | $theUrl, |
||
| 505 | $vv['subCfg'], |
||
| 506 | $scheduledTime, |
||
| 507 | $configurationHash, |
||
| 508 | $skipInnerCheck |
||
| 509 | ); |
||
| 510 | if ($added === false) { |
||
| 511 | $urlList .= ' (Url already existed)'; |
||
| 512 | } |
||
| 513 | } elseif ($downloadCrawlUrls) { |
||
| 514 | $downloadUrls[$theUrl] = $theUrl; |
||
| 515 | } |
||
| 516 | |||
| 517 | $urlList .= '<br />'; |
||
| 518 | } |
||
| 519 | $duplicateTrack[$uKey] = true; |
||
| 520 | } |
||
| 521 | } |
||
| 522 | } else { |
||
| 523 | $urlList = 'ERROR - no URL generated'; |
||
| 524 | } |
||
| 525 | |||
| 526 | return $urlList; |
||
| 527 | } |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Returns true if input processing instruction is among registered ones. |
||
| 531 | * |
||
| 532 | * @param string $piString PI to test |
||
| 533 | * @param array $incomingProcInstructions Processing instructions |
||
| 534 | * @return boolean |
||
| 535 | */ |
||
| 536 | 5 | public function drawURLs_PIfilter($piString, array $incomingProcInstructions) |
|
| 537 | { |
||
| 538 | 5 | if (empty($incomingProcInstructions)) { |
|
| 539 | 1 | return true; |
|
| 540 | } |
||
| 541 | |||
| 542 | 4 | foreach ($incomingProcInstructions as $pi) { |
|
| 543 | 4 | if (GeneralUtility::inList($piString, $pi)) { |
|
| 544 | 4 | return true; |
|
| 545 | } |
||
| 546 | } |
||
| 547 | 2 | } |
|
| 548 | |||
| 549 | public function getPageTSconfigForId($id) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * This methods returns an array of configurations. |
||
| 574 | * And no urls! |
||
| 575 | * |
||
| 576 | * @param integer $id Page ID |
||
| 577 | * @param bool $forceSsl Use https |
||
| 578 | * @return array |
||
| 579 | * |
||
| 580 | * TODO: Should be switched back to protected - TNM 2018-11-16 |
||
| 581 | */ |
||
| 582 | public function getUrlsForPageId($id, $forceSsl = false) |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Checks if a domain record exist and returns the base-url based on the record. If not the given baseUrl string is used. |
||
| 721 | * |
||
| 722 | * @param string $baseUrl |
||
| 723 | * @param integer $sysDomainUid |
||
| 724 | * @param bool $ssl |
||
| 725 | * @return string |
||
| 726 | */ |
||
| 727 | protected function getBaseUrlForConfigurationRecord($baseUrl, $sysDomainUid, $ssl = false) |
||
| 728 | { |
||
| 729 | $sysDomainUid = intval($sysDomainUid); |
||
| 730 | $urlScheme = ($ssl === false) ? 'http' : 'https'; |
||
| 731 | |||
| 732 | if ($sysDomainUid > 0) { |
||
| 733 | $res = $this->db->exec_SELECTquery( |
||
| 734 | '*', |
||
| 735 | 'sys_domain', |
||
| 736 | 'uid = ' . $sysDomainUid . |
||
| 737 | BackendUtility::BEenableFields('sys_domain') . |
||
| 738 | BackendUtility::deleteClause('sys_domain') |
||
| 739 | ); |
||
| 740 | $row = $this->db->sql_fetch_assoc($res); |
||
| 741 | if ($row['domainName'] != '') { |
||
| 742 | return $urlScheme . '://' . $row['domainName']; |
||
| 743 | } |
||
| 744 | } |
||
| 745 | return $baseUrl; |
||
| 746 | } |
||
| 747 | |||
| 748 | public function getConfigurationsForBranch($rootid, $depth) |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Check if a user has access to an item |
||
| 796 | * (e.g. get the group list of the current logged in user from $GLOBALS['TSFE']->gr_list) |
||
| 797 | * |
||
| 798 | * @see \TYPO3\CMS\Frontend\Page\PageRepository::getMultipleGroupsWhereClause() |
||
| 799 | * @param string $groupList Comma-separated list of (fe_)group UIDs from a user |
||
| 800 | * @param string $accessList Comma-separated list of (fe_)group UIDs of the item to access |
||
| 801 | * @return bool TRUE if at least one of the users group UIDs is in the access list or the access list is empty |
||
| 802 | */ |
||
| 803 | 3 | public function hasGroupAccess($groupList, $accessList) |
|
| 804 | { |
||
| 805 | 3 | if (empty($accessList)) { |
|
| 806 | 1 | return true; |
|
| 807 | } |
||
| 808 | 2 | foreach (GeneralUtility::intExplode(',', $groupList) as $groupUid) { |
|
| 809 | 2 | if (GeneralUtility::inList($accessList, $groupUid)) { |
|
| 810 | 2 | return true; |
|
| 811 | } |
||
| 812 | } |
||
| 813 | 1 | return false; |
|
| 814 | } |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Parse GET vars of input Query into array with key=>value pairs |
||
| 818 | * |
||
| 819 | * @param string $inputQuery Input query string |
||
| 820 | * @return array |
||
| 821 | */ |
||
| 822 | 3 | public function parseParams($inputQuery) |
|
| 823 | { |
||
| 824 | // Extract all GET parameters into an ARRAY: |
||
| 825 | 3 | $paramKeyValues = []; |
|
| 826 | 3 | $GETparams = explode('&', $inputQuery); |
|
| 827 | |||
| 828 | 3 | foreach ($GETparams as $paramAndValue) { |
|
| 829 | 3 | list($p, $v) = explode('=', $paramAndValue, 2); |
|
| 830 | 3 | if (strlen($p)) { |
|
| 831 | 3 | $paramKeyValues[rawurldecode($p)] = rawurldecode($v); |
|
| 832 | } |
||
| 833 | } |
||
| 834 | |||
| 835 | 3 | return $paramKeyValues; |
|
| 836 | } |
||
| 837 | |||
| 838 | /** |
||
| 839 | * Will expand the parameters configuration to individual values. This follows a certain syntax of the value of each parameter. |
||
| 840 | * Syntax of values: |
||
| 841 | * - Basically: If the value is wrapped in [...] it will be expanded according to the following syntax, otherwise the value is taken literally |
||
| 842 | * - Configuration is splitted by "|" and the parts are processed individually and finally added together |
||
| 843 | * - For each configuration part: |
||
| 844 | * - "[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" |
||
| 845 | * - "_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" |
||
| 846 | * _ENABLELANG:1 picks only original records without their language overlays |
||
| 847 | * - Default: Literal value |
||
| 848 | * |
||
| 849 | * @param array $paramArray Array with key (GET var name) and values (value of GET var which is configuration for expansion) |
||
| 850 | * @param integer $pid Current page ID |
||
| 851 | * @return array |
||
| 852 | */ |
||
| 853 | public function expandParameters($paramArray, $pid) |
||
| 963 | |||
| 964 | /** |
||
| 965 | * Compiling URLs from parameter array (output of expandParameters()) |
||
| 966 | * The number of URLs will be the multiplication of the number of parameter values for each key |
||
| 967 | * |
||
| 968 | * @param array $paramArray Output of expandParameters(): Array with keys (GET var names) and for each an array of values |
||
| 969 | * @param array $urls URLs accumulated in this array (for recursion) |
||
| 970 | * @return array |
||
| 971 | */ |
||
| 972 | 3 | public function compileUrls($paramArray, $urls = []) |
|
| 973 | { |
||
| 974 | 3 | if (count($paramArray) && is_array($urls)) { |
|
| 975 | // shift first off stack: |
||
| 976 | 2 | reset($paramArray); |
|
| 977 | 2 | $varName = key($paramArray); |
|
| 978 | 2 | $valueSet = array_shift($paramArray); |
|
| 979 | |||
| 997 | |||
| 998 | /************************************ |
||
| 999 | * |
||
| 1000 | * Crawler log |
||
| 1001 | * |
||
| 1002 | ************************************/ |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Return array of records from crawler queue for input page ID |
||
| 1006 | * |
||
| 1007 | * @param integer $id Page ID for which to look up log entries. |
||
| 1008 | * @param string$filter Filter: "all" => all entries, "pending" => all that is not yet run, "finished" => all complete ones |
||
| 1009 | * @param boolean $doFlush If TRUE, then entries selected at DELETED(!) instead of selected! |
||
| 1010 | * @param boolean $doFullFlush |
||
| 1011 | * @param integer $itemsPerPage Limit the amount of entries per page default is 10 |
||
| 1012 | * @return array |
||
| 1013 | */ |
||
| 1014 | public function getLogEntriesForPageId($id, $filter = '', $doFlush = false, $doFullFlush = false, $itemsPerPage = 10) |
||
| 1043 | |||
| 1044 | /** |
||
| 1045 | * Return array of records from crawler queue for input set ID |
||
| 1046 | * |
||
| 1047 | * @param integer $set_id Set ID for which to look up log entries. |
||
| 1048 | * @param string $filter Filter: "all" => all entries, "pending" => all that is not yet run, "finished" => all complete ones |
||
| 1049 | * @param boolean $doFlush If TRUE, then entries selected at DELETED(!) instead of selected! |
||
| 1050 | * @param integer $itemsPerPage Limit the amount of entires per page default is 10 |
||
| 1051 | * @return array |
||
| 1052 | */ |
||
| 1053 | public function getLogEntriesForSetId($set_id, $filter = '', $doFlush = false, $doFullFlush = false, $itemsPerPage = 10) |
||
| 1082 | |||
| 1083 | /** |
||
| 1084 | * Removes queue entries |
||
| 1085 | * |
||
| 1086 | * @param string $where SQL related filter for the entries which should be removed |
||
| 1087 | * @return void |
||
| 1088 | */ |
||
| 1089 | protected function flushQueue($where = '') |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Adding call back entries to log (called from hooks typically, see indexed search class "class.crawler.php" |
||
| 1125 | * |
||
| 1126 | * @param integer $setId Set ID |
||
| 1127 | * @param array $params Parameters to pass to call back function |
||
| 1128 | * @param string $callBack Call back object reference, eg. 'EXT:indexed_search/class.crawler.php:&tx_indexedsearch_crawler' |
||
| 1129 | * @param integer $page_id Page ID to attach it to |
||
| 1130 | * @param integer $schedule Time at which to activate |
||
| 1131 | * @return void |
||
| 1132 | */ |
||
| 1133 | public function addQueueEntry_callBack($setId, $params, $callBack, $page_id = 0, $schedule = 0) |
||
| 1152 | |||
| 1153 | /************************************ |
||
| 1154 | * |
||
| 1155 | * URL setting |
||
| 1156 | * |
||
| 1157 | ************************************/ |
||
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Setting a URL for crawling: |
||
| 1161 | * |
||
| 1162 | * @param integer $id Page ID |
||
| 1163 | * @param string $url Complete URL |
||
| 1164 | * @param array $subCfg Sub configuration array (from TS config) |
||
| 1165 | * @param integer $tstamp Scheduled-time |
||
| 1166 | * @param string $configurationHash (optional) configuration hash |
||
| 1167 | * @param bool $skipInnerDuplicationCheck (optional) skip inner duplication check |
||
| 1168 | * @return bool |
||
| 1169 | */ |
||
| 1170 | public function addUrl( |
||
| 1257 | |||
| 1258 | /** |
||
| 1259 | * This method determines duplicates for a queue entry with the same parameters and this timestamp. |
||
| 1260 | * If the timestamp is in the past, it will check if there is any unprocessed queue entry in the past. |
||
| 1261 | * If the timestamp is in the future it will check, if the queued entry has exactly the same timestamp |
||
| 1262 | * |
||
| 1263 | * @param int $tstamp |
||
| 1264 | * @param array $fieldArray |
||
| 1265 | * |
||
| 1266 | * @return array |
||
| 1267 | */ |
||
| 1268 | protected function getDuplicateRowsIfExist($tstamp, $fieldArray) |
||
| 1308 | |||
| 1309 | /** |
||
| 1310 | * Returns the current system time |
||
| 1311 | * |
||
| 1312 | * @return int |
||
| 1313 | */ |
||
| 1314 | public function getCurrentTime() |
||
| 1318 | |||
| 1319 | /************************************ |
||
| 1320 | * |
||
| 1321 | * URL reading |
||
| 1322 | * |
||
| 1323 | ************************************/ |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Read URL for single queue entry |
||
| 1327 | * |
||
| 1328 | * @param integer $queueId |
||
| 1329 | * @param boolean $force If set, will process even if exec_time has been set! |
||
| 1330 | * @return integer |
||
| 1331 | */ |
||
| 1332 | public function readUrl($queueId, $force = false) |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Read URL for not-yet-inserted log-entry |
||
| 1417 | * |
||
| 1418 | * @param array $field_array Queue field array, |
||
| 1419 | * |
||
| 1420 | * @return string |
||
| 1421 | */ |
||
| 1422 | public function readUrlFromArray($field_array) |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * Read URL for a queue record |
||
| 1449 | * |
||
| 1450 | * @param array $queueRec Queue record |
||
| 1451 | * @return string |
||
| 1452 | */ |
||
| 1453 | public function readUrl_exec($queueRec) |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Gets the content of a URL. |
||
| 1494 | * |
||
| 1495 | * @param string $originalUrl URL to read |
||
| 1496 | * @param string $crawlerId Crawler ID string (qid + hash to verify) |
||
| 1497 | * @param integer $timeout Timeout time |
||
| 1498 | * @param integer $recursion Recursion limiter for 302 redirects |
||
| 1499 | * @return array |
||
| 1500 | */ |
||
| 1501 | 2 | public function requestUrl($originalUrl, $crawlerId, $timeout = 2, $recursion = 10) |
|
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Gets the base path of the website frontend. |
||
| 1597 | * (e.g. if you call http://mydomain.com/cms/index.php in |
||
| 1598 | * the browser the base path is "/cms/") |
||
| 1599 | * |
||
| 1600 | * @return string Base path of the website frontend |
||
| 1601 | */ |
||
| 1602 | protected function getFrontendBasePath() |
||
| 1625 | |||
| 1626 | /** |
||
| 1627 | * Executes a shell command and returns the outputted result. |
||
| 1628 | * |
||
| 1629 | * @param string $command Shell command to be executed |
||
| 1630 | * @return string Outputted result of the command execution |
||
| 1631 | */ |
||
| 1632 | protected function executeShellCommand($command) |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * Reads HTTP response from the given stream. |
||
| 1640 | * |
||
| 1641 | * @param resource $streamPointer Pointer to connection stream. |
||
| 1642 | * @return array Associative array with the following items: |
||
| 1643 | * headers <array> Response headers sent by server. |
||
| 1644 | * content <array> Content, with each line as an array item. |
||
| 1645 | */ |
||
| 1646 | protected function getHttpResponseFromStream($streamPointer) |
||
| 1669 | |||
| 1670 | /** |
||
| 1671 | * @param message |
||
| 1672 | */ |
||
| 1673 | 2 | protected function log($message) |
|
| 1682 | |||
| 1683 | /** |
||
| 1684 | * Builds HTTP request headers. |
||
| 1685 | * |
||
| 1686 | * @param array $url |
||
| 1687 | * @param string $crawlerId |
||
| 1688 | * |
||
| 1689 | * @return array |
||
| 1690 | */ |
||
| 1691 | 6 | protected function buildRequestHeaderArray(array $url, $crawlerId) |
|
| 1707 | |||
| 1708 | /** |
||
| 1709 | * Check if the submitted HTTP-Header contains a redirect location and built new crawler-url |
||
| 1710 | * |
||
| 1711 | * @param array $headers HTTP Header |
||
| 1712 | * @param string $user HTTP Auth. User |
||
| 1713 | * @param string $pass HTTP Auth. Password |
||
| 1714 | * @return bool|string |
||
| 1715 | */ |
||
| 1716 | 12 | protected function getRequestUrlFrom302Header($headers, $user = '', $pass = '') |
|
| 1750 | |||
| 1751 | /************************** |
||
| 1752 | * |
||
| 1753 | * tslib_fe hooks: |
||
| 1754 | * |
||
| 1755 | **************************/ |
||
| 1756 | |||
| 1757 | /** |
||
| 1758 | * Initialization hook (called after database connection) |
||
| 1759 | * Takes the "HTTP_X_T3CRAWLER" header and looks up queue record and verifies if the session comes from the system (by comparing hashes) |
||
| 1760 | * |
||
| 1761 | * @param array $params Parameters from frontend |
||
| 1762 | * @param object $ref TSFE object (reference under PHP5) |
||
| 1763 | * @return void |
||
| 1764 | * |
||
| 1765 | * FIXME: Look like this is not used, in commit 9910d3f40cce15f4e9b7bcd0488bf21f31d53ebc it's added as public, |
||
| 1766 | * FIXME: I think this can be removed. (TNM) |
||
| 1767 | */ |
||
| 1768 | public function fe_init(&$params, $ref) |
||
| 1785 | |||
| 1786 | /***************************** |
||
| 1787 | * |
||
| 1788 | * Compiling URLs to crawl - tools |
||
| 1789 | * |
||
| 1790 | *****************************/ |
||
| 1791 | |||
| 1792 | /** |
||
| 1793 | * @param integer $id Root page id to start from. |
||
| 1794 | * @param integer $depth Depth of tree, 0=only id-page, 1= on sublevel, 99 = infinite |
||
| 1795 | * @param integer $scheduledTime Unix Time when the URL is timed to be visited when put in queue |
||
| 1796 | * @param integer $reqMinute Number of requests per minute (creates the interleave between requests) |
||
| 1797 | * @param boolean $submitCrawlUrls If set, submits the URLs to queue in database (real crawling) |
||
| 1798 | * @param boolean $downloadCrawlUrls If set (and submitcrawlUrls is false) will fill $downloadUrls with entries) |
||
| 1799 | * @param array $incomingProcInstructions Array of processing instructions |
||
| 1800 | * @param array $configurationSelection Array of configuration keys |
||
| 1801 | * @return string |
||
| 1802 | */ |
||
| 1803 | public function getPageTreeAndUrls( |
||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * Expands exclude string |
||
| 1893 | * |
||
| 1894 | * @param string $excludeString Exclude string |
||
| 1895 | * @return array |
||
| 1896 | */ |
||
| 1897 | public function expandExcludeString($excludeString) |
||
| 1942 | |||
| 1943 | /** |
||
| 1944 | * Create the rows for display of the page tree |
||
| 1945 | * For each page a number of rows are shown displaying GET variable configuration |
||
| 1946 | * |
||
| 1947 | * @param array Page row |
||
| 1948 | * @param string Page icon and title for row |
||
| 1949 | * @return string HTML <tr> content (one or more) |
||
| 1950 | */ |
||
| 1951 | public function drawURLs_addRowsForPage(array $pageRow, $pageTitleAndIcon) |
||
| 2060 | |||
| 2061 | /***************************** |
||
| 2062 | * |
||
| 2063 | * CLI functions |
||
| 2064 | * |
||
| 2065 | *****************************/ |
||
| 2066 | |||
| 2067 | /** |
||
| 2068 | * Main function for running from Command Line PHP script (cron job) |
||
| 2069 | * See ext/crawler/cli/crawler_cli.phpsh for details |
||
| 2070 | * |
||
| 2071 | * @return int number of remaining items or false if error |
||
| 2072 | */ |
||
| 2073 | public function CLI_main() |
||
| 2114 | |||
| 2115 | /** |
||
| 2116 | * Function executed by crawler_im.php cli script. |
||
| 2117 | * |
||
| 2118 | * @return void |
||
| 2119 | */ |
||
| 2120 | public function CLI_main_im() |
||
| 2229 | |||
| 2230 | /** |
||
| 2231 | * Function executed by crawler_im.php cli script. |
||
| 2232 | * |
||
| 2233 | * @return bool |
||
| 2234 | */ |
||
| 2235 | public function CLI_main_flush() |
||
| 2273 | |||
| 2274 | /** |
||
| 2275 | * Obtains configuration keys from the CLI arguments |
||
| 2276 | * |
||
| 2277 | * @param QueueCommandLineController $cliObj |
||
| 2278 | * @return array |
||
| 2279 | * |
||
| 2280 | * @deprecated since crawler v6.3.0, will be removed in crawler v7.0.0. |
||
| 2281 | */ |
||
| 2282 | protected function getConfigurationKeys(QueueCommandLineController $cliObj) |
||
| 2287 | |||
| 2288 | /** |
||
| 2289 | * Running the functionality of the CLI (crawling URLs from queue) |
||
| 2290 | * |
||
| 2291 | * @param int $countInARun |
||
| 2292 | * @param int $sleepTime |
||
| 2293 | * @param int $sleepAfterFinish |
||
| 2294 | * @return string |
||
| 2295 | */ |
||
| 2296 | public function CLI_run($countInARun, $sleepTime, $sleepAfterFinish) |
||
| 2403 | |||
| 2404 | /** |
||
| 2405 | * Activate hooks |
||
| 2406 | * |
||
| 2407 | * @return void |
||
| 2408 | */ |
||
| 2409 | public function CLI_runHooks() |
||
| 2421 | |||
| 2422 | /** |
||
| 2423 | * Try to acquire a new process with the given id |
||
| 2424 | * also performs some auto-cleanup for orphan processes |
||
| 2425 | * @todo preemption might not be the most elegant way to clean up |
||
| 2426 | * |
||
| 2427 | * @param string $id identification string for the process |
||
| 2428 | * @return boolean |
||
| 2429 | */ |
||
| 2430 | public function CLI_checkAndAcquireNewProcess($id) |
||
| 2486 | |||
| 2487 | /** |
||
| 2488 | * Release a process and the required resources |
||
| 2489 | * |
||
| 2490 | * @param mixed $releaseIds string with a single process-id or array with multiple process-ids |
||
| 2491 | * @param boolean $withinLock show whether the DB-actions are included within an existing lock |
||
| 2492 | * @return boolean |
||
| 2493 | */ |
||
| 2494 | public function CLI_releaseProcesses($releaseIds, $withinLock = false) |
||
| 2556 | |||
| 2557 | /** |
||
| 2558 | * Delete processes marked as deleted |
||
| 2559 | * |
||
| 2560 | * @return void |
||
| 2561 | */ |
||
| 2562 | public function CLI_deleteProcessesMarkedDeleted() |
||
| 2566 | |||
| 2567 | /** |
||
| 2568 | * Check if there are still resources left for the process with the given id |
||
| 2569 | * Used to determine timeouts and to ensure a proper cleanup if there's a timeout |
||
| 2570 | * |
||
| 2571 | * @param string identification string for the process |
||
| 2572 | * @return boolean determines if the process is still active / has resources |
||
| 2573 | * |
||
| 2574 | * FIXME: Please remove Transaction, not needed as only a select query. |
||
| 2575 | */ |
||
| 2576 | public function CLI_checkIfProcessIsActive($pid) |
||
| 2595 | |||
| 2596 | /** |
||
| 2597 | * Create a unique Id for the current process |
||
| 2598 | * |
||
| 2599 | * @return string the ID |
||
| 2600 | */ |
||
| 2601 | 2 | public function CLI_buildProcessId() |
|
| 2608 | |||
| 2609 | /** |
||
| 2610 | * @param bool $get_as_float |
||
| 2611 | * |
||
| 2612 | * @return mixed |
||
| 2613 | */ |
||
| 2614 | protected function microtime($get_as_float = false) |
||
| 2618 | |||
| 2619 | /** |
||
| 2620 | * Prints a message to the stdout (only if debug-mode is enabled) |
||
| 2621 | * |
||
| 2622 | * @param string $msg the message |
||
| 2623 | */ |
||
| 2624 | public function CLI_debug($msg) |
||
| 2631 | |||
| 2632 | /** |
||
| 2633 | * Get URL content by making direct request to TYPO3. |
||
| 2634 | * |
||
| 2635 | * @param string $url Page URL |
||
| 2636 | * @param int $crawlerId Crawler-ID |
||
| 2637 | * @return array |
||
| 2638 | */ |
||
| 2639 | 2 | protected function sendDirectRequest($url, $crawlerId) |
|
| 2670 | |||
| 2671 | /** |
||
| 2672 | * Cleans up entries that stayed for too long in the queue. These are: |
||
| 2673 | * - processed entries that are over 1.5 days in age |
||
| 2674 | * - scheduled entries that are over 7 days old |
||
| 2675 | * |
||
| 2676 | * @return void |
||
| 2677 | * |
||
| 2678 | * TODO: Should be switched back to protected - TNM 2018-11-16 |
||
| 2679 | */ |
||
| 2680 | public function cleanUpOldQueueEntries() |
||
| 2689 | |||
| 2690 | /** |
||
| 2691 | * Initializes a TypoScript Frontend necessary for using TypoScript and TypoLink functions |
||
| 2692 | * |
||
| 2693 | * @param int $id |
||
| 2694 | * @param int $typeNum |
||
| 2695 | * |
||
| 2696 | * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException |
||
| 2697 | * |
||
| 2698 | * @return void |
||
| 2699 | */ |
||
| 2700 | protected function initTSFE($id = 1, $typeNum = 0) |
||
| 2725 | |||
| 2726 | /** |
||
| 2727 | * Returns a md5 hash generated from a serialized configuration array. |
||
| 2728 | * |
||
| 2729 | * @param array $configuration |
||
| 2730 | * |
||
| 2731 | * @return string |
||
| 2732 | */ |
||
| 2733 | 5 | protected function getConfigurationHash(array $configuration) { |
|
| 2738 | |||
| 2739 | /** |
||
| 2740 | * Check whether the Crawling Protocol should be http or https |
||
| 2741 | * |
||
| 2742 | * @param $crawlerConfiguration |
||
| 2743 | * @param $pageConfiguration |
||
| 2744 | * |
||
| 2745 | * @return bool |
||
| 2746 | */ |
||
| 2747 | 5 | protected function isCrawlingProtocolHttps($crawlerConfiguration, $pageConfiguration) { |
|
| 2759 | } |
||
| 2760 |
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: