@@ -4,10 +4,10 @@ |
||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | $processManager = new tx_crawler_domain_process_manager(); |
| 7 | -$timeout = isset($_SERVER['argv'][1] ) ? intval($_SERVER['argv'][1]) : 1800; |
|
| 7 | +$timeout = isset($_SERVER['argv'][1]) ? intval($_SERVER['argv'][1]) : 1800; |
|
| 8 | 8 | |
| 9 | 9 | try { |
| 10 | 10 | $processManager->multiProcess($timeout); |
| 11 | 11 | } catch (Exception $e) { |
| 12 | - echo PHP_EOL . $e->getMessage(); |
|
| 12 | + echo PHP_EOL.$e->getMessage(); |
|
| 13 | 13 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * Manages cralwer processes and can be used to start a new process or multiple processes |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | -class tx_crawler_domain_process_manager { |
|
| 29 | +class tx_crawler_domain_process_manager { |
|
| 30 | 30 | /** |
| 31 | 31 | * @var $timeToLive integer |
| 32 | 32 | */ |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * the constructor |
| 66 | 66 | */ |
| 67 | 67 | public function __construct() { |
| 68 | - $this->processRepository = new tx_crawler_domain_process_repository(); |
|
| 69 | - $this->queueRepository = new tx_crawler_domain_queue_repository(); |
|
| 68 | + $this->processRepository = new tx_crawler_domain_process_repository(); |
|
| 69 | + $this->queueRepository = new tx_crawler_domain_queue_repository(); |
|
| 70 | 70 | $this->crawlerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_lib'); |
| 71 | 71 | $this->timeToLive = intval($this->crawlerObj->extensionSettings['processMaxRunTime']); |
| 72 | 72 | $this->countInARun = intval($this->crawlerObj->extensionSettings['countInARun']); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function multiProcess($timeout) { |
| 83 | 83 | if ($this->processLimit <= 1) { |
| 84 | - throw new RuntimeException('To run crawler in multi process mode you have to configure the processLimit > 1.' . PHP_EOL); |
|
| 84 | + throw new RuntimeException('To run crawler in multi process mode you have to configure the processLimit > 1.'.PHP_EOL); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $pendingItemsStart = $this->queueRepository->countAllPendingItems(); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | if ($currentPendingItems == 0) { |
| 101 | 101 | if ($this->verbose) { |
| 102 | - echo 'Finished...' . chr(10); |
|
| 102 | + echo 'Finished...'.chr(10); |
|
| 103 | 103 | } |
| 104 | 104 | break; |
| 105 | 105 | } |
@@ -111,16 +111,16 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | sleep(1); |
| 113 | 113 | if ($nextTimeOut < time()) { |
| 114 | - $timedOutProcesses = $this->processRepository->findAll('', 'DESC', NULL, 0, 'ttl >' . $nextTimeOut); |
|
| 114 | + $timedOutProcesses = $this->processRepository->findAll('', 'DESC', NULL, 0, 'ttl >'.$nextTimeOut); |
|
| 115 | 115 | $nextTimeOut = time() + $this->timeToLive; |
| 116 | 116 | if ($this->verbose) { |
| 117 | - echo 'Cleanup' . implode(',', $timedOutProcesses->getProcessIds()) . chr(10); |
|
| 117 | + echo 'Cleanup'.implode(',', $timedOutProcesses->getProcessIds()).chr(10); |
|
| 118 | 118 | } |
| 119 | 119 | $this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(), true); |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | if ($currentPendingItems > 0 && $this->verbose) { |
| 123 | - echo 'Stop with timeout' . chr(10); |
|
| 123 | + echo 'Stop with timeout'.chr(10); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -138,17 +138,17 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | private function startRequiredProcesses() { |
| 140 | 140 | $ret = FALSE; |
| 141 | - $currentProcesses= $this->processRepository->countActive(); |
|
| 142 | - $availableProcessesCount = $this->processLimit-$currentProcesses; |
|
| 141 | + $currentProcesses = $this->processRepository->countActive(); |
|
| 142 | + $availableProcessesCount = $this->processLimit - $currentProcesses; |
|
| 143 | 143 | $requiredProcessesCount = ceil($this->queueRepository->countAllUnassignedPendingItems() / $this->countInARun); |
| 144 | - $startProcessCount = min(array($availableProcessesCount,$requiredProcessesCount)); |
|
| 144 | + $startProcessCount = min(array($availableProcessesCount, $requiredProcessesCount)); |
|
| 145 | 145 | if ($startProcessCount <= 0) { |
| 146 | 146 | return $ret; |
| 147 | 147 | } |
| 148 | 148 | if ($startProcessCount && $this->verbose) { |
| 149 | 149 | echo 'Start '.$startProcessCount.' new processes (Running:'.$currentProcesses.')'; |
| 150 | 150 | } |
| 151 | - for($i=0;$i<$startProcessCount;$i++) { |
|
| 151 | + for ($i = 0; $i < $startProcessCount; $i++) { |
|
| 152 | 152 | usleep(100); |
| 153 | 153 | if ($this->startProcess()) { |
| 154 | 154 | if ($this->verbose) { |
@@ -168,14 +168,14 @@ discard block |
||
| 168 | 168 | * @throws Exception if no crawlerprocess was started |
| 169 | 169 | */ |
| 170 | 170 | public function startProcess() { |
| 171 | - $ttl = (time() + $this->timeToLive -1); |
|
| 171 | + $ttl = (time() + $this->timeToLive - 1); |
|
| 172 | 172 | $current = $this->processRepository->countNotTimeouted($ttl); |
| 173 | - $completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null'; |
|
| 173 | + $completePath = '('.escapeshellcmd($this->getCrawlerCliPath()).' &) > /dev/null'; |
|
| 174 | 174 | if (system($completePath) === FALSE) { |
| 175 | 175 | throw new Exception('could not start process!'); |
| 176 | 176 | } |
| 177 | 177 | else { |
| 178 | - for ($i=0;$i<10;$i++) { |
|
| 178 | + for ($i = 0; $i < 10; $i++) { |
|
| 179 | 179 | if ($this->processRepository->countNotTimeouted($ttl) > $current) { |
| 180 | 180 | return true; |
| 181 | 181 | } |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @return string |
| 192 | 192 | */ |
| 193 | - public function getCrawlerCliPath(){ |
|
| 194 | - $phpPath = $this->crawlerObj->extensionSettings['phpPath'] . ' '; |
|
| 195 | - $pathToTypo3 = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/'); |
|
| 196 | - $pathToTypo3 .= rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'), '/'); |
|
| 193 | + public function getCrawlerCliPath() { |
|
| 194 | + $phpPath = $this->crawlerObj->extensionSettings['phpPath'].' '; |
|
| 195 | + $pathToTypo3 = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/'); |
|
| 196 | + $pathToTypo3 .= rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'), '/'); |
|
| 197 | 197 | $cliPart = '/typo3/cli_dispatch.phpsh crawler'; |
| 198 | 198 | return $phpPath.$pathToTypo3.$cliPart; |
| 199 | 199 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | |
| 64 | 64 | // input for timeOut |
| 65 | 65 | $fieldId = 'task_timeOut'; |
| 66 | - $fieldCode = '<input type="text" name="tx_scheduler[timeOut]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['timeOut']) . '" class="form-control" />'; |
|
| 66 | + $fieldCode = '<input type="text" name="tx_scheduler[timeOut]" id="'.$fieldId.'" value="'.htmlentities($taskInfo['timeOut']).'" class="form-control" />'; |
|
| 67 | 67 | $additionalFields[$fieldId] = array( |
| 68 | 68 | 'code' => $fieldCode, |
| 69 | 69 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.timeOut' |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | // input for startPage |
| 90 | 90 | $fieldId = 'task_startPage'; |
| 91 | - $fieldCode = '<input name="tx_scheduler[startPage]" type="text" id="' . $fieldId . '" value="' . $task->startPage . '" class="form-control" />'; |
|
| 91 | + $fieldCode = '<input name="tx_scheduler[startPage]" type="text" id="'.$fieldId.'" value="'.$task->startPage.'" class="form-control" />'; |
|
| 92 | 92 | $additionalFields[$fieldId] = array( |
| 93 | 93 | 'code' => $fieldCode, |
| 94 | 94 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.startPage' |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | '4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_4'), |
| 105 | 105 | '99' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_infi'), |
| 106 | 106 | ); |
| 107 | - $fieldCode = '<select name="tx_scheduler[depth]" id="' . $fieldId . '" class="form-control">'; |
|
| 107 | + $fieldCode = '<select name="tx_scheduler[depth]" id="'.$fieldId.'" class="form-control">'; |
|
| 108 | 108 | |
| 109 | 109 | foreach ($fieldValueArray as $key => $label) { |
| 110 | - $fieldCode .= "\t" . '<option value="' . $key . '"' . (($key == $task->depth) ? ' selected="selected"' : '') . '>' . $label . '</option>'; |
|
| 110 | + $fieldCode .= "\t".'<option value="'.$key.'"'.(($key == $task->depth) ? ' selected="selected"' : '').'>'.$label.'</option>'; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $fieldCode .= '</select>'; |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | // combobox for configuration records |
| 120 | 120 | $recordsArray = $this->getCrawlerConfigurationRecords(); |
| 121 | 121 | $fieldId = 'task_configuration'; |
| 122 | - $fieldCode = '<select name="tx_scheduler[configuration][]" multiple="multiple" id="' . $fieldId . '" class="form-control">'; |
|
| 123 | - $fieldCode .= "\t" . '<option value=""></option>'; |
|
| 122 | + $fieldCode = '<select name="tx_scheduler[configuration][]" multiple="multiple" id="'.$fieldId.'" class="form-control">'; |
|
| 123 | + $fieldCode .= "\t".'<option value=""></option>'; |
|
| 124 | 124 | for ($i = 0; $i < count($recordsArray); $i++) { |
| 125 | - $fieldCode .= "\t" . '<option ' . $this->getSelectedState($task->configuration, $recordsArray[$i]['name']) . 'value="' . $recordsArray[$i]['name'] . '">' . $recordsArray[$i]['name'] . '</option>'; |
|
| 125 | + $fieldCode .= "\t".'<option '.$this->getSelectedState($task->configuration, $recordsArray[$i]['name']).'value="'.$recordsArray[$i]['name'].'">'.$recordsArray[$i]['name'].'</option>'; |
|
| 126 | 126 | } |
| 127 | 127 | $fieldCode .= '</select>'; |
| 128 | 128 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
| 166 | 166 | '*', |
| 167 | 167 | 'tx_crawler_configuration', |
| 168 | - '1=1' . BackendUtility::deleteClause('tx_crawler_configuration') |
|
| 168 | + '1=1'.BackendUtility::deleteClause('tx_crawler_configuration') |
|
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | 171 | while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
@@ -60,10 +60,10 @@ |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $fieldId = 'mode'; |
| 63 | - $fieldCode = '<select name="tx_scheduler[mode]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['mode']) . '" class="form-control">' |
|
| 64 | - . '<option value="all"' . ($taskInfo['mode'] == 'all' ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modeAll') . '</option>' |
|
| 65 | - . '<option value="finished"' . ($taskInfo['mode'] == 'finished' ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modeFinished') . '</option>' |
|
| 66 | - . '<option value="pending"' . ($taskInfo['mode'] == 'pending' ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modePending') . '</option>' |
|
| 63 | + $fieldCode = '<select name="tx_scheduler[mode]" id="'.$fieldId.'" value="'.htmlentities($taskInfo['mode']).'" class="form-control">' |
|
| 64 | + . '<option value="all"'.($taskInfo['mode'] == 'all' ? ' selected="selected"' : '').'>'.$GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modeAll').'</option>' |
|
| 65 | + . '<option value="finished"'.($taskInfo['mode'] == 'finished' ? ' selected="selected"' : '').'>'.$GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modeFinished').'</option>' |
|
| 66 | + . '<option value="pending"'.($taskInfo['mode'] == 'pending' ? ' selected="selected"' : '').'>'.$GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modePending').'</option>' |
|
| 67 | 67 | . '</select>'; |
| 68 | 68 | |
| 69 | 69 | $additionalFields[$fieldId] = array( |
@@ -83,21 +83,21 @@ |
||
| 83 | 83 | |
| 84 | 84 | // input for sleepTime |
| 85 | 85 | $fieldId = 'task_sleepTime'; |
| 86 | - $fieldCode = '<input type="text" name="tx_scheduler[sleepTime]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['sleepTime']) . '" class="form-control" />'; |
|
| 86 | + $fieldCode = '<input type="text" name="tx_scheduler[sleepTime]" id="'.$fieldId.'" value="'.htmlentities($taskInfo['sleepTime']).'" class="form-control" />'; |
|
| 87 | 87 | $additionalFields[$fieldId] = array( |
| 88 | 88 | 'code' => $fieldCode, |
| 89 | 89 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.sleepTime' |
| 90 | 90 | ); |
| 91 | 91 | // input for sleepAfterFinish |
| 92 | 92 | $fieldId = 'task_sleepAfterFinish'; |
| 93 | - $fieldCode = '<input type="text" name="tx_scheduler[sleepAfterFinish]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['sleepAfterFinish']) . '" class="form-control" />'; |
|
| 93 | + $fieldCode = '<input type="text" name="tx_scheduler[sleepAfterFinish]" id="'.$fieldId.'" value="'.htmlentities($taskInfo['sleepAfterFinish']).'" class="form-control" />'; |
|
| 94 | 94 | $additionalFields[$fieldId] = array( |
| 95 | 95 | 'code' => $fieldCode, |
| 96 | 96 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.sleepAfterFinish' |
| 97 | 97 | ); |
| 98 | 98 | // input for countInARun |
| 99 | 99 | $fieldId = 'task_countInARun'; |
| 100 | - $fieldCode = '<input type="text" name="tx_scheduler[countInARun]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['countInARun']) . '" class="form-control" />'; |
|
| 100 | + $fieldCode = '<input type="text" name="tx_scheduler[countInARun]" id="'.$fieldId.'" value="'.htmlentities($taskInfo['countInARun']).'" class="form-control" />'; |
|
| 101 | 101 | $additionalFields[$fieldId] = array( |
| 102 | 102 | 'code' => $fieldCode, |
| 103 | 103 | 'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.countInARun' |