Completed
Push — issue/233 ( a6a112 )
by Tomas Norre
13:07
created
Classes/Hooks/TsfeHook.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
         if (isset($_SERVER['HTTP_X_T3CRAWLER'])) {
49 49
             //@todo: ask service to exclude current call for special reasons: for example no relevance because the language version is not affected
50 50
 
51
-            list($queueId,$hash) = explode(':', $_SERVER['HTTP_X_T3CRAWLER']);
52
-            list($queueRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*','tx_crawler_queue','qid='.intval($queueId));
51
+            list($queueId, $hash) = explode(':', $_SERVER['HTTP_X_T3CRAWLER']);
52
+            list($queueRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_crawler_queue', 'qid='.intval($queueId));
53 53
 
54 54
             // If a crawler record was found and hash was matching, set it up:
55 55
             if (is_array($queueRec) && $hash === md5($queueRec['qid'].'|'.$queueRec['set_id'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
              * Required because some extensions (staticpub) might never be requested to run due to some Core side effects
120 120
              * and since this is considered as error the crawler should handle it properly
121 121
              */
122
-            if(is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pollSuccess'])) {
123
-                foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pollSuccess'] as $pollable) {
124
-                    if(is_array($params['pObj']->applicationData['tx_crawler']['content']['parameters']['procInstructions']) && in_array($pollable,$params['pObj']->applicationData['tx_crawler']['content']['parameters']['procInstructions'])){
125
-                        if(empty($params['pObj']->applicationData['tx_crawler']['success'][$pollable])) {
122
+            if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pollSuccess'])) {
123
+                foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pollSuccess'] as $pollable) {
124
+                    if (is_array($params['pObj']->applicationData['tx_crawler']['content']['parameters']['procInstructions']) && in_array($pollable, $params['pObj']->applicationData['tx_crawler']['content']['parameters']['procInstructions'])) {
125
+                        if (empty($params['pObj']->applicationData['tx_crawler']['success'][$pollable])) {
126 126
                             $params['pObj']->applicationData['tx_crawler']['errorlog'][] = 'Error: Pollable extension ('.$pollable.') did not complete successfully.';
127 127
                         }
128 128
                     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,9 @@
 block discarded – undo
76 76
         if ($params['pObj']->applicationData['tx_crawler']['running']) {
77 77
             $grList = $params['pObj']->applicationData['tx_crawler']['parameters']['feUserGroupList'];
78 78
             if ($grList) {
79
-                if (!is_array($params['pObj']->fe_user->user)) $params['pObj']->fe_user->user = array();
79
+                if (!is_array($params['pObj']->fe_user->user)) {
80
+                    $params['pObj']->fe_user->user = array();
81
+                }
80 82
                 $params['pObj']->fe_user->user['usergroup'] = $grList;
81 83
                 $params['pObj']->applicationData['tx_crawler']['log'][] = 'User Groups: '.$grList;
82 84
             }
Please login to merge, or discard this patch.
Classes/Hooks/ProcessCleanUpHook.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
         $results = $this->getDatabaseConnection()->exec_SELECTgetRows(
71 71
             'process_id, system_process_id',
72 72
             'tx_crawler_process',
73
-            'ttl <= ' . intval(time() - $this->extensionSettings['processMaxRunTime'] - 3600) . ' AND active = 1'
73
+            'ttl <= '.intval(time() - $this->extensionSettings['processMaxRunTime'] - 3600).' AND active = 1'
74 74
         );
75 75
 
76 76
         if (!is_array($results)) {
77 77
             return;
78 78
         }
79 79
         foreach ($results as $result) {
80
-            $systemProcessId = (int)$result['system_process_id'];
80
+            $systemProcessId = (int) $result['system_process_id'];
81 81
             $processId = $result['process_id'];
82 82
             if ($systemProcessId > 1) {
83 83
                 if ($this->doProcessStillExists($systemProcessId)) {
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         $results = $this->getDatabaseConnection()->exec_SELECTgetRows(
99 99
             'process_id, system_process_id',
100 100
             'tx_crawler_process',
101
-            'ttl <= ' . intval(time() - $this->extensionSettings['processMaxRunTime']) . ' AND active = 1'
101
+            'ttl <= '.intval(time() - $this->extensionSettings['processMaxRunTime']).' AND active = 1'
102 102
         );
103 103
 
104 104
         if (!is_array($results)) {
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
         }
107 107
         foreach ($results as $result) {
108 108
             $processExists = false;
109
-            $systemProcessId = (int)$result['system_process_id'];
109
+            $systemProcessId = (int) $result['system_process_id'];
110 110
             $processId = $result['process_id'];
111 111
             if ($systemProcessId > 1) {
112 112
                 $dispatcherProcesses = $this->findDispatcherProcesses();
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
                 }
117 117
                 foreach ($dispatcherProcesses as $process) {
118 118
                     $responseArray = $this->createResponseArray($process);
119
-                    if ($systemProcessId === (int)$responseArray[1]) {
119
+                    if ($systemProcessId === (int) $responseArray[1]) {
120 120
                         $processExists = true;
121 121
                     };
122 122
                 }
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
     {
139 139
         $this->getDatabaseConnection()->exec_DELETEquery(
140 140
             'tx_crawler_process',
141
-            'process_id = ' . $this->getDatabaseConnection()->fullQuoteStr($processId, 'tx_crawler_process')
141
+            'process_id = '.$this->getDatabaseConnection()->fullQuoteStr($processId, 'tx_crawler_process')
142 142
         );
143 143
 
144 144
         $this->getDatabaseConnection()->exec_UPDATEquery(
145 145
             'tx_crawler_queue',
146
-            'process_id = ' . $this->getDatabaseConnection()->fullQuoteStr($processId, 'tx_crawler_queue'),
146
+            'process_id = '.$this->getDatabaseConnection()->fullQuoteStr($processId, 'tx_crawler_queue'),
147 147
             array('process_id' => '')
148 148
         );
149 149
     }
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
         $doProcessStillExists = false;
178 178
         if (!$this->isOsWindows()) {
179 179
             // Not windows
180
-            if (file_exists('/proc/' . $pid)) {
180
+            if (file_exists('/proc/'.$pid)) {
181 181
                 $doProcessStillExists = true;
182 182
             }
183 183
         } else {
184 184
             // Windows
185
-            exec('tasklist | find "' . $pid . '"', $returnArray, $returnValue);
185
+            exec('tasklist | find "'.$pid.'"', $returnArray, $returnValue);
186 186
             if (count($returnArray) > 0 && preg_match('/php/i', $returnValue[0])) {
187 187
                 $doProcessStillExists = true;
188 188
             }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
             posix_kill($pid, 9);
205 205
         } else {
206 206
             // Windows
207
-            exec('taskkill /PID ' . $pid);
207
+            exec('taskkill /PID '.$pid);
208 208
         }
209 209
     }
210 210
 
Please login to merge, or discard this patch.
Classes/ClickMenu/CrawlerClickMenu.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $additionalParameters = array();
68 68
         $additionalParameters[] = 'SET[function]=tx_crawler_modfunc1';
69 69
         $additionalParameters[] = 'SET[crawlaction]=start';
70
-        $additionalParameters[] = 'configurationSelection[]=' . $crawlerConfiguration['name'];
70
+        $additionalParameters[] = 'configurationSelection[]='.$crawlerConfiguration['name'];
71 71
 
72 72
         $additionalMenuItems = array();
73 73
         $additionalMenuItems[] = $backRef->linkItem(
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 'crawler'
77 77
             ),
78 78
             $this->getContextMenuIcon(),
79
-            'top.goToModule(\'web_info\', 1, \'&' . implode('&', $additionalParameters) . '\'); return hideCM();'
79
+            'top.goToModule(\'web_info\', 1, \'&'.implode('&', $additionalParameters).'\'); return hideCM();'
80 80
         );
81 81
 
82 82
         return array_merge($menuItems, $additionalMenuItems);
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
     {
92 92
         $icon = sprintf(
93 93
             '<img src="%s" border="0" align="top" alt="" />',
94
-            ExtensionManagementUtility::extRelPath('crawler') . 'icon_tx_crawler_configuration.gif'
94
+            ExtensionManagementUtility::extRelPath('crawler').'icon_tx_crawler_configuration.gif'
95 95
         );
96 96
 
97 97
         return $icon;
Please login to merge, or discard this patch.
Classes/Task/CrawlerQueueTask.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             $this->startPage = 0;
93 93
         }
94 94
 
95
-        $_SERVER['argv'] = array($_SERVER['argv'][0], $this->startPage,'-ss', '-d', $this->depth, '-o', self::MODE, '-conf', implode(',', $this->configuration));
95
+        $_SERVER['argv'] = array($_SERVER['argv'][0], $this->startPage, '-ss', '-d', $this->depth, '-o', self::MODE, '-conf', implode(',', $this->configuration));
96 96
     }
97 97
 
98 98
 
@@ -109,6 +109,6 @@  discard block
 block discarded – undo
109 109
             $this->startPage = 0;
110 110
         }
111 111
 
112
-        return implode(',', $this->configuration) . ' (depth: ' . $this->depth . ', startPage:' . $this->startPage . ')';
112
+        return implode(',', $this->configuration).' (depth: '.$this->depth.', startPage:'.$this->startPage.')';
113 113
     }
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.
domain/queue/class.tx_crawler_domain_queue_entry.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,21 +24,21 @@
 block discarded – undo
24 24
 
25 25
 class tx_crawler_domain_queue_entry extends tx_crawler_domain_lib_abstract_dbobject {
26 26
 
27
-	/**
28
-	 * @var string table name
29
-	 */
30
-	protected static $tableName = 'tx_crawler_queue';
27
+    /**
28
+     * @var string table name
29
+     */
30
+    protected static $tableName = 'tx_crawler_queue';
31 31
 
32
-	/**
33
-	 * Returns the execution time of the record as int value
34
-	 *
35
-	 * @param void
36
-	 * @author Timo Schmidt <[email protected]>
37
-	 * @return int
38
-	 */
39
-	public function getExecutionTime(){
40
-		return $this->row['exec_time'];
41
-	}
32
+    /**
33
+     * Returns the execution time of the record as int value
34
+     *
35
+     * @param void
36
+     * @author Timo Schmidt <[email protected]>
37
+     * @return int
38
+     */
39
+    public function getExecutionTime(){
40
+        return $this->row['exec_time'];
41
+    }
42 42
 
43 43
 }
44 44
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
 	 * @author Timo Schmidt <[email protected]>
37 37
 	 * @return int
38 38
 	 */
39
-	public function getExecutionTime(){
39
+	public function getExecutionTime() {
40 40
 		return $this->row['exec_time'];
41 41
 	}
42 42
 
Please login to merge, or discard this patch.
domain/lib/class.tx_crawler_domain_lib_abstract_repository.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -24,36 +24,36 @@
 block discarded – undo
24 24
 
25 25
 abstract class tx_crawler_domain_lib_abstract_repository {
26 26
 
27
-	/**
28
-	 * @var string object class name
29
-	 */
30
-	protected $objectClassname;
27
+    /**
28
+     * @var string object class name
29
+     */
30
+    protected $objectClassname;
31 31
 
32
-	/**
33
-	 * @var string table name
34
-	 */
35
-	protected $tableName;
32
+    /**
33
+     * @var string table name
34
+     */
35
+    protected $tableName;
36 36
 
37
-	/**
38
-	 * Returns an instance of the TYPO3 database class.
39
-	 *
40
-	 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
41
-	 */
42
-	protected function getDB() {
43
-		return $GLOBALS['TYPO3_DB'];
44
-	}
37
+    /**
38
+     * Returns an instance of the TYPO3 database class.
39
+     *
40
+     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
41
+     */
42
+    protected function getDB() {
43
+        return $GLOBALS['TYPO3_DB'];
44
+    }
45 45
 
46
-	/**
47
-	 * Counts items by a given where clause
48
-	 *
49
-	 * @param  string $where    Where clause
50
-	 * @return integer
51
-	 */
52
-	protected function countByWhere($where) {
53
-		$db  = $this->getDB();
54
-		$rs  = $db->exec_SELECTquery('count(*) as anz', $this->tableName, $where);
55
-		$res = $db->sql_fetch_assoc($rs);
46
+    /**
47
+     * Counts items by a given where clause
48
+     *
49
+     * @param  string $where    Where clause
50
+     * @return integer
51
+     */
52
+    protected function countByWhere($where) {
53
+        $db  = $this->getDB();
54
+        $rs  = $db->exec_SELECTquery('count(*) as anz', $this->tableName, $where);
55
+        $res = $db->sql_fetch_assoc($rs);
56 56
 
57
-		return $res['anz'];
58
-	}
57
+        return $res['anz'];
58
+    }
59 59
 }
Please login to merge, or discard this patch.
domain/process/class.tx_crawler_domain_process_repository.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -24,97 +24,97 @@
 block discarded – undo
24 24
 
25 25
 class tx_crawler_domain_process_repository extends tx_crawler_domain_lib_abstract_repository {
26 26
 
27
-	/**
28
-	 * @var string object class name
29
-	 */
30
-	protected $objectClassname = 'tx_crawler_domain_process';
27
+    /**
28
+     * @var string object class name
29
+     */
30
+    protected $objectClassname = 'tx_crawler_domain_process';
31 31
 
32
-	/**
33
-	 * @var string
34
-	 */
35
-	protected $tableName = 'tx_crawler_process';
32
+    /**
33
+     * @var string
34
+     */
35
+    protected $tableName = 'tx_crawler_process';
36 36
 
37
-	/**
38
-	 * This method is used to find all cli processes within a limit.
39
-	 * 
40
-	 * @param  string  $orderField
41
-	 * @param  string  $orderDirection
42
-	 * @param  integer $itemCount
43
-	 * @param  integer $offset
44
-	 * @param  string  $where
45
-	 * @return tx_crawler_domain_process_collection
46
-	 */
47
-	public function findAll($orderField = '', $orderDirection = 'DESC', $itemCount = NULL, $offset = NULL, $where = '') {
48
-		/** @var tx_crawler_domain_process_collection $collection */
49
-		$collection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_domain_process_collection');
37
+    /**
38
+     * This method is used to find all cli processes within a limit.
39
+     * 
40
+     * @param  string  $orderField
41
+     * @param  string  $orderDirection
42
+     * @param  integer $itemCount
43
+     * @param  integer $offset
44
+     * @param  string  $where
45
+     * @return tx_crawler_domain_process_collection
46
+     */
47
+    public function findAll($orderField = '', $orderDirection = 'DESC', $itemCount = NULL, $offset = NULL, $where = '') {
48
+        /** @var tx_crawler_domain_process_collection $collection */
49
+        $collection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_domain_process_collection');
50 50
 
51
-		$orderField = trim($orderField);
52
-		$orderField = empty($orderField) ? 'process_id' : $orderField;
51
+        $orderField = trim($orderField);
52
+        $orderField = empty($orderField) ? 'process_id' : $orderField;
53 53
 
54
-		$orderDirection = strtoupper(trim($orderDirection));
55
-		$orderDirection = in_array($orderDirection, array('ASC', 'DESC')) ? $orderDirection : 'DESC';
54
+        $orderDirection = strtoupper(trim($orderDirection));
55
+        $orderDirection = in_array($orderDirection, array('ASC', 'DESC')) ? $orderDirection : 'DESC';
56 56
 
57
-		$rows = $this->getDB()->exec_SELECTgetRows(
58
-			'*',
59
-			$this->tableName,
60
-			$where,
61
-			'',
62
-			htmlspecialchars($orderField) . ' ' . htmlspecialchars($orderDirection),
63
-			self::getLimitFromItemCountAndOffset($itemCount, $offset)
64
-		);
57
+        $rows = $this->getDB()->exec_SELECTgetRows(
58
+            '*',
59
+            $this->tableName,
60
+            $where,
61
+            '',
62
+            htmlspecialchars($orderField) . ' ' . htmlspecialchars($orderDirection),
63
+            self::getLimitFromItemCountAndOffset($itemCount, $offset)
64
+        );
65 65
 
66
-		if (is_array($rows)) {
67
-			foreach($rows as $row) {
68
-				$collection->append(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->objectClassname, $row));
69
-			}
70
-		}
66
+        if (is_array($rows)) {
67
+            foreach($rows as $row) {
68
+                $collection->append(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->objectClassname, $row));
69
+            }
70
+        }
71 71
 
72
-		return $collection;
73
-	}
72
+        return $collection;
73
+    }
74 74
 
75
-	/**
76
-	 * This method is used to count all processes in the process table.
77
-	 *
78
-	 * @param  string $where    Where clause
79
-	 * @return integer
80
-	 * @author Timo Schmidt <[email protected]>
81
-	 */
82
-	public function countAll($where = '1 = 1') {
83
-		return $this->countByWhere($where);
84
-	}
75
+    /**
76
+     * This method is used to count all processes in the process table.
77
+     *
78
+     * @param  string $where    Where clause
79
+     * @return integer
80
+     * @author Timo Schmidt <[email protected]>
81
+     */
82
+    public function countAll($where = '1 = 1') {
83
+        return $this->countByWhere($where);
84
+    }
85 85
 
86
-	/**
87
-	 * Returns the number of active processes.
88
-	 *
89
-	 * @return integer
90
-	 */
91
-	public function countActive() {
92
-		return $this->countByWhere('active = 1 AND deleted = 0');
93
-	}
86
+    /**
87
+     * Returns the number of active processes.
88
+     *
89
+     * @return integer
90
+     */
91
+    public function countActive() {
92
+        return $this->countByWhere('active = 1 AND deleted = 0');
93
+    }
94 94
 
95
-	/**
96
-	 * Returns the number of processes that live longer than the given timestamp.
97
-	 *
98
-	 * @param  integer $ttl
99
-	 * @return integer
100
-	 */
101
-	public function countNotTimeouted($ttl) {
102
-		return $this->countByWhere('deleted = 0 AND ttl > ' . intval($ttl));
103
-	}
95
+    /**
96
+     * Returns the number of processes that live longer than the given timestamp.
97
+     *
98
+     * @param  integer $ttl
99
+     * @return integer
100
+     */
101
+    public function countNotTimeouted($ttl) {
102
+        return $this->countByWhere('deleted = 0 AND ttl > ' . intval($ttl));
103
+    }
104 104
 
105
-	/**
106
-	 * Get limit clause
107
-	 *
108
-	 * @param  integer $itemCount   Item count
109
-	 * @param  integer $offset      Offset
110
-	 * @return string               Limit clause
111
-	 * @author Fabrizio Branca <[email protected]>
112
-	 */
113
-	public static function getLimitFromItemCountAndOffset($itemCount, $offset) {
114
-		$itemCount = filter_var($itemCount, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'default' => 20)));
115
-		$offset = filter_var($offset, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'default' => 0)));
116
-		$limit = $offset . ', ' . $itemCount;
105
+    /**
106
+     * Get limit clause
107
+     *
108
+     * @param  integer $itemCount   Item count
109
+     * @param  integer $offset      Offset
110
+     * @return string               Limit clause
111
+     * @author Fabrizio Branca <[email protected]>
112
+     */
113
+    public static function getLimitFromItemCountAndOffset($itemCount, $offset) {
114
+        $itemCount = filter_var($itemCount, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'default' => 20)));
115
+        $offset = filter_var($offset, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'default' => 0)));
116
+        $limit = $offset . ', ' . $itemCount;
117 117
 
118
-		return $limit;
119
-	}
118
+        return $limit;
119
+    }
120 120
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 			$this->tableName,
60 60
 			$where,
61 61
 			'',
62
-			htmlspecialchars($orderField) . ' ' . htmlspecialchars($orderDirection),
62
+			htmlspecialchars($orderField).' '.htmlspecialchars($orderDirection),
63 63
 			self::getLimitFromItemCountAndOffset($itemCount, $offset)
64 64
 		);
65 65
 
66 66
 		if (is_array($rows)) {
67
-			foreach($rows as $row) {
67
+			foreach ($rows as $row) {
68 68
 				$collection->append(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->objectClassname, $row));
69 69
 			}
70 70
 		}
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @return integer
100 100
 	 */
101 101
 	public function countNotTimeouted($ttl) {
102
-		return $this->countByWhere('deleted = 0 AND ttl > ' . intval($ttl));
102
+		return $this->countByWhere('deleted = 0 AND ttl > '.intval($ttl));
103 103
 	}
104 104
 
105 105
 	/**
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	public static function getLimitFromItemCountAndOffset($itemCount, $offset) {
114 114
 		$itemCount = filter_var($itemCount, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'default' => 20)));
115 115
 		$offset = filter_var($offset, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'default' => 0)));
116
-		$limit = $offset . ', ' . $itemCount;
116
+		$limit = $offset.', '.$itemCount;
117 117
 
118 118
 		return $limit;
119 119
 	}
Please login to merge, or discard this patch.
domain/process/class.tx_crawler_domain_process_manager.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -174,8 +174,7 @@
 block discarded – undo
174 174
 		$completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null';
175 175
 		if (system($completePath) === FALSE) {
176 176
 			throw new Exception('could not start process!');
177
-		}
178
-		else {
177
+		} else {
179 178
 			for ($i=0;$i<10;$i++) {
180 179
 				if ($this->processRepository->countNotTimeouted($ttl) > $current) {
181 180
 					return true;
Please login to merge, or discard this patch.
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -27,175 +27,175 @@
 block discarded – undo
27 27
  *
28 28
  */
29 29
 class tx_crawler_domain_process_manager  {
30
-	/**
31
-	 * @var $timeToLive integer
32
-	 */
33
-	private $timeToLive;
34
-	/**
35
-	 * @var integer
36
-	 */
37
-	private $countInARun;
30
+    /**
31
+     * @var $timeToLive integer
32
+     */
33
+    private $timeToLive;
34
+    /**
35
+     * @var integer
36
+     */
37
+    private $countInARun;
38 38
 
39
-	/**
40
-	 * @var integer
41
-	 */
42
-	private $processLimit;
39
+    /**
40
+     * @var integer
41
+     */
42
+    private $processLimit;
43 43
 
44
-	/**
45
-	 * @var $crawlerObj tx_crawler_lib
46
-	 */
47
-	private $crawlerObj;
44
+    /**
45
+     * @var $crawlerObj tx_crawler_lib
46
+     */
47
+    private $crawlerObj;
48 48
 
49
-	/**
50
-	 * @var $queueRepository tx_crawler_domain_queue_repository
51
-	 */
52
-	private $queueRepository;
49
+    /**
50
+     * @var $queueRepository tx_crawler_domain_queue_repository
51
+     */
52
+    private $queueRepository;
53 53
 
54
-	/**
55
-	 * @var tx_crawler_domain_process_repository
56
-	 */
57
-	private $processRepository;
54
+    /**
55
+     * @var tx_crawler_domain_process_repository
56
+     */
57
+    private $processRepository;
58 58
 
59
-	/**
60
-	 * @var $verbose boolean
61
-	 */
62
-	private $verbose;
59
+    /**
60
+     * @var $verbose boolean
61
+     */
62
+    private $verbose;
63 63
 
64
-	/**
65
-	 * the constructor
66
-	 */
67
-	public function __construct() {
68
-		$this->processRepository	= new tx_crawler_domain_process_repository();
69
-		$this->queueRepository	= new tx_crawler_domain_queue_repository();
70
-		$this->crawlerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_lib');
71
-		$this->timeToLive = intval($this->crawlerObj->extensionSettings['processMaxRunTime']);
72
-		$this->countInARun = intval($this->crawlerObj->extensionSettings['countInARun']);
73
-		$this->processLimit = intval($this->crawlerObj->extensionSettings['processLimit']);
74
-		$this->verbose = intval($this->crawlerObj->extensionSettings['processVerbose']);
75
-	}
64
+    /**
65
+     * the constructor
66
+     */
67
+    public function __construct() {
68
+        $this->processRepository	= new tx_crawler_domain_process_repository();
69
+        $this->queueRepository	= new tx_crawler_domain_queue_repository();
70
+        $this->crawlerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_lib');
71
+        $this->timeToLive = intval($this->crawlerObj->extensionSettings['processMaxRunTime']);
72
+        $this->countInARun = intval($this->crawlerObj->extensionSettings['countInARun']);
73
+        $this->processLimit = intval($this->crawlerObj->extensionSettings['processLimit']);
74
+        $this->verbose = intval($this->crawlerObj->extensionSettings['processVerbose']);
75
+    }
76 76
 
77
-	/**
78
-	 * starts multiple processes
79
-	 *
80
-	 * @param integer $timeout
81
-	 */
82
-	public function multiProcess($timeout) {
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);
85
-		}
77
+    /**
78
+     * starts multiple processes
79
+     *
80
+     * @param integer $timeout
81
+     */
82
+    public function multiProcess($timeout) {
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);
85
+        }
86 86
 
87
-		$pendingItemsStart = $this->queueRepository->countAllPendingItems();
88
-		$itemReportLimit = 20;
89
-		$reportItemCount = $pendingItemsStart - $itemReportLimit;
90
-		if ($this->verbose) {
91
-			$this->reportItemStatus();
92
-		}
93
-		$this->startRequiredProcesses();
94
-		$nextTimeOut = time() + $this->timeToLive;
95
-		for ($i = 0; $i < $timeout; $i++) {
96
-			$currentPendingItems = $this->queueRepository->countAllPendingItems();
97
-			if ($this->startRequiredProcesses($this->verbose)) {
98
-				$nextTimeOut = time() + $this->timeToLive;
99
-			}
100
-			if ($currentPendingItems == 0) {
101
-				if ($this->verbose) {
102
-					echo 'Finished...' . chr(10);
103
-				}
104
-				break;
105
-			}
106
-			if ($currentPendingItems < $reportItemCount) {
107
-				if ($this->verbose) {
108
-					$this->reportItemStatus();
109
-				}
110
-				$reportItemCount = $currentPendingItems - $itemReportLimit;
111
-			}
112
-			sleep(1);
113
-			if ($nextTimeOut < time()) {
114
-				$timedOutProcesses = $this->processRepository->findAll('', 'DESC', NULL, 0, 'ttl >' . $nextTimeOut);
115
-				$nextTimeOut = time() + $this->timeToLive;
116
-				if ($this->verbose) {
117
-					echo 'Cleanup' . implode(',', $timedOutProcesses->getProcessIds()) . chr(10);
118
-				}
119
-				$this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(), true);
120
-			}
121
-		}
122
-		if ($currentPendingItems > 0 && $this->verbose) {
123
-			echo 'Stop with timeout' . chr(10);
124
-		}
125
-	}
87
+        $pendingItemsStart = $this->queueRepository->countAllPendingItems();
88
+        $itemReportLimit = 20;
89
+        $reportItemCount = $pendingItemsStart - $itemReportLimit;
90
+        if ($this->verbose) {
91
+            $this->reportItemStatus();
92
+        }
93
+        $this->startRequiredProcesses();
94
+        $nextTimeOut = time() + $this->timeToLive;
95
+        for ($i = 0; $i < $timeout; $i++) {
96
+            $currentPendingItems = $this->queueRepository->countAllPendingItems();
97
+            if ($this->startRequiredProcesses($this->verbose)) {
98
+                $nextTimeOut = time() + $this->timeToLive;
99
+            }
100
+            if ($currentPendingItems == 0) {
101
+                if ($this->verbose) {
102
+                    echo 'Finished...' . chr(10);
103
+                }
104
+                break;
105
+            }
106
+            if ($currentPendingItems < $reportItemCount) {
107
+                if ($this->verbose) {
108
+                    $this->reportItemStatus();
109
+                }
110
+                $reportItemCount = $currentPendingItems - $itemReportLimit;
111
+            }
112
+            sleep(1);
113
+            if ($nextTimeOut < time()) {
114
+                $timedOutProcesses = $this->processRepository->findAll('', 'DESC', NULL, 0, 'ttl >' . $nextTimeOut);
115
+                $nextTimeOut = time() + $this->timeToLive;
116
+                if ($this->verbose) {
117
+                    echo 'Cleanup' . implode(',', $timedOutProcesses->getProcessIds()) . chr(10);
118
+                }
119
+                $this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(), true);
120
+            }
121
+        }
122
+        if ($currentPendingItems > 0 && $this->verbose) {
123
+            echo 'Stop with timeout' . chr(10);
124
+        }
125
+    }
126 126
 
127
-	/**
128
-	 * Reports curent Status of queue
129
-	 */
130
-	protected function reportItemStatus() {
131
-		echo 'Pending:'.$this->queueRepository->countAllPendingItems().' / Assigned:'.$this->queueRepository->countAllAssignedPendingItems().chr(10);
132
-	}
127
+    /**
128
+     * Reports curent Status of queue
129
+     */
130
+    protected function reportItemStatus() {
131
+        echo 'Pending:'.$this->queueRepository->countAllPendingItems().' / Assigned:'.$this->queueRepository->countAllAssignedPendingItems().chr(10);
132
+    }
133 133
 
134
-	/**
135
-	 * according to the given count of pending items and the countInARun Setting this method
136
-	 * starts more crawling processes
137
-	 * @return boolean if processes are started
138
-	 */
139
-	private function startRequiredProcesses() {
140
-		$ret = FALSE;
141
-		$currentProcesses= $this->processRepository->countActive();
142
-		$availableProcessesCount = $this->processLimit-$currentProcesses;
143
-		$requiredProcessesCount = ceil($this->queueRepository->countAllUnassignedPendingItems() / $this->countInARun);
144
-		$startProcessCount = min(array($availableProcessesCount,$requiredProcessesCount));
145
-		if ($startProcessCount <= 0) {
146
-			return $ret;
147
-		}
148
-		if ($startProcessCount && $this->verbose) {
149
-			echo 'Start '.$startProcessCount.' new processes (Running:'.$currentProcesses.')';
150
-		}
151
-		for($i=0;$i<$startProcessCount;$i++) {
152
-			usleep(100);
153
-			if ($this->startProcess()) {
154
-				if ($this->verbose) {
155
-					echo '.';
156
-					$ret = TRUE;
157
-				}
158
-			}
159
-		}
160
-		if ($this->verbose) {
161
-			echo chr(10);
162
-		}
163
-		return $ret;
164
-	}
134
+    /**
135
+     * according to the given count of pending items and the countInARun Setting this method
136
+     * starts more crawling processes
137
+     * @return boolean if processes are started
138
+     */
139
+    private function startRequiredProcesses() {
140
+        $ret = FALSE;
141
+        $currentProcesses= $this->processRepository->countActive();
142
+        $availableProcessesCount = $this->processLimit-$currentProcesses;
143
+        $requiredProcessesCount = ceil($this->queueRepository->countAllUnassignedPendingItems() / $this->countInARun);
144
+        $startProcessCount = min(array($availableProcessesCount,$requiredProcessesCount));
145
+        if ($startProcessCount <= 0) {
146
+            return $ret;
147
+        }
148
+        if ($startProcessCount && $this->verbose) {
149
+            echo 'Start '.$startProcessCount.' new processes (Running:'.$currentProcesses.')';
150
+        }
151
+        for($i=0;$i<$startProcessCount;$i++) {
152
+            usleep(100);
153
+            if ($this->startProcess()) {
154
+                if ($this->verbose) {
155
+                    echo '.';
156
+                    $ret = TRUE;
157
+                }
158
+            }
159
+        }
160
+        if ($this->verbose) {
161
+            echo chr(10);
162
+        }
163
+        return $ret;
164
+    }
165 165
 
166
-	/**
167
-	 * starts new process
168
-	 * @throws Exception if no crawlerprocess was started
169
-	 */
170
-	public function startProcess() {
171
-		$ttl = (time() + $this->timeToLive -1);
172
-		$current = $this->processRepository->countNotTimeouted($ttl);
173
-		$completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null';
174
-		if (system($completePath) === FALSE) {
175
-			throw new Exception('could not start process!');
176
-		}
177
-		else {
178
-			for ($i=0;$i<10;$i++) {
179
-				if ($this->processRepository->countNotTimeouted($ttl) > $current) {
180
-					return true;
181
-				}
182
-				sleep(1);
183
-			}
184
-			throw new Exception('Something went wrong: process did not appear within 10 seconds.');
185
-		}
186
-	}
166
+    /**
167
+     * starts new process
168
+     * @throws Exception if no crawlerprocess was started
169
+     */
170
+    public function startProcess() {
171
+        $ttl = (time() + $this->timeToLive -1);
172
+        $current = $this->processRepository->countNotTimeouted($ttl);
173
+        $completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null';
174
+        if (system($completePath) === FALSE) {
175
+            throw new Exception('could not start process!');
176
+        }
177
+        else {
178
+            for ($i=0;$i<10;$i++) {
179
+                if ($this->processRepository->countNotTimeouted($ttl) > $current) {
180
+                    return true;
181
+                }
182
+                sleep(1);
183
+            }
184
+            throw new Exception('Something went wrong: process did not appear within 10 seconds.');
185
+        }
186
+    }
187 187
 
188
-	/**
189
-	 * Returns the path to start the crawler from the command line
190
-	 *
191
-	 * @return string
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'), '/');
197
-		$cliPart	 	= '/typo3/cli_dispatch.phpsh crawler';
198
-		return $phpPath.$pathToTypo3.$cliPart;
199
-	}
188
+    /**
189
+     * Returns the path to start the crawler from the command line
190
+     *
191
+     * @return string
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'), '/');
197
+        $cliPart	 	= '/typo3/cli_dispatch.phpsh crawler';
198
+        return $phpPath.$pathToTypo3.$cliPart;
199
+    }
200 200
 
201 201
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
domain/process/class.tx_crawler_domain_process.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -24,140 +24,140 @@
 block discarded – undo
24 24
 
25 25
 class tx_crawler_domain_process extends tx_crawler_domain_lib_abstract_dbobject {
26 26
 
27
-	/**
28
-	 * @var string table name
29
-	 */
30
-	protected static $tableName = 'tx_crawler_process';
31
-
32
-	/**
33
-	 * Returns the activity state for this process
34
-	 *
35
-	 * @param void
36
-	 * @return boolean
37
-	 */
38
-	public function getActive() {
39
-		return $this->row['active'];
40
-	}
41
-
42
-	/**
43
-	 * Returns the identifier for the process
44
-	 *
45
-	 * @return string
46
-	 */
47
-	public function getProcess_id() {
48
-		return $this->row['process_id'];
49
-	}
50
-
51
-	/**
52
-	 * Returns the timestamp of the exectime for the first relevant queue item.
53
-	 * This can be used to determine the runtime
54
-	 *
55
-	 * @return int
56
-	 */
57
-	public function getTimeForFirstItem() {
58
-		$queueRepository = new tx_crawler_domain_queue_repository();
59
-		$entry = $queueRepository->findYoungestEntryForProcess($this);
60
-
61
-		return $entry->getExecutionTime();
62
-	}
63
-
64
-	/**
65
-	 * Returns the timestamp of the exectime for the last relevant queue item.
66
-	 * This can be used to determine the runtime
67
-	 *
68
-	 * @return int
69
-	 */
70
-	public function getTimeForLastItem() {
71
-		$queueRepository = new tx_crawler_domain_queue_repository();
72
-		$entry = $queueRepository->findOldestEntryForProcess($this);
73
-
74
-		return $entry->getExecutionTime();
75
-	}
76
-
77
-	/**
78
-	 * Returns the difference between first and last processed item
79
-	 *
80
-	 * @return int
81
-	 */
82
-	public function getRuntime() {
83
-		return $this->getTimeForLastItem() - $this->getTimeForFirstItem();
84
-	}
85
-
86
-	/**
87
-	 * Returns the ttl of the process
88
-	 *
89
-	 * @return int
90
-	 */
91
-	public function getTTL() {
92
-		return $this->row['ttl'];
93
-	}
94
-
95
-	/**
96
-	 * Counts the number of items which need to be processed
97
-	 *
98
-	 * @author Timo Schmidt <[email protected]>
99
-	 * @param void
100
-	 * @return int
101
-	 */
102
-	public function countItemsProcessed() {
103
-		$queueRepository = new tx_crawler_domain_queue_repository();
104
-		return $queueRepository->countExtecutedItemsByProcess($this);
105
-	}
106
-
107
-	/**
108
-	 * Counts the number of items which still need to be processed
109
-	 *
110
-	 * @author Timo Schmidt <[email protected]>
111
-	 * @param void
112
-	 * @return int
113
-	 */
114
-	public function countItemsToProcess() {
115
-		$queueRepository = new tx_crawler_domain_queue_repository();
116
-		return $queueRepository->countNonExecutedItemsByProcess($this);
117
-	}
118
-
119
-	/**
120
-	 * Returns the Progress of a crawling process as a percentage value
121
-	 *
122
-	 * @param void
123
-	 * @return float
124
-	 */
125
-	public function getProgress() {
126
-		$all = $this->countItemsAssigned();
127
-		if ($all > 0) {
128
-			$res = round((100 / $all) * $this->countItemsProcessed());
129
-		} else {
130
-			$res = 0;
131
-		}
132
-		return $res;
133
-	}
134
-
135
-	/**
136
-	 * Returns the number of assigned Entrys
137
-	 *
138
-	 * @return int
139
-	 */
140
-	public function countItemsAssigned() {
141
-		return $this->row['assigned_items_count'];
142
-	}
143
-
144
-	/**
145
-	 * Return the processes current state
146
-	 *
147
-	 * @param void
148
-	 * @return string 'running'|'cancelled'|'completed'
149
-	 */
150
-	public function getState() {
151
-		// TODO: use class constants for these states
152
-		if ($this->getActive() && $this->getProgress() < 100) {
153
-			$stage = 'running';
154
-		} elseif(!$this->getActive() && $this->getProgress() < 100) {
155
-			$stage = 'cancelled';
156
-		} else {
157
-			$stage = 'completed';
158
-		}
159
-		return $stage;
160
-	}
27
+    /**
28
+     * @var string table name
29
+     */
30
+    protected static $tableName = 'tx_crawler_process';
31
+
32
+    /**
33
+     * Returns the activity state for this process
34
+     *
35
+     * @param void
36
+     * @return boolean
37
+     */
38
+    public function getActive() {
39
+        return $this->row['active'];
40
+    }
41
+
42
+    /**
43
+     * Returns the identifier for the process
44
+     *
45
+     * @return string
46
+     */
47
+    public function getProcess_id() {
48
+        return $this->row['process_id'];
49
+    }
50
+
51
+    /**
52
+     * Returns the timestamp of the exectime for the first relevant queue item.
53
+     * This can be used to determine the runtime
54
+     *
55
+     * @return int
56
+     */
57
+    public function getTimeForFirstItem() {
58
+        $queueRepository = new tx_crawler_domain_queue_repository();
59
+        $entry = $queueRepository->findYoungestEntryForProcess($this);
60
+
61
+        return $entry->getExecutionTime();
62
+    }
63
+
64
+    /**
65
+     * Returns the timestamp of the exectime for the last relevant queue item.
66
+     * This can be used to determine the runtime
67
+     *
68
+     * @return int
69
+     */
70
+    public function getTimeForLastItem() {
71
+        $queueRepository = new tx_crawler_domain_queue_repository();
72
+        $entry = $queueRepository->findOldestEntryForProcess($this);
73
+
74
+        return $entry->getExecutionTime();
75
+    }
76
+
77
+    /**
78
+     * Returns the difference between first and last processed item
79
+     *
80
+     * @return int
81
+     */
82
+    public function getRuntime() {
83
+        return $this->getTimeForLastItem() - $this->getTimeForFirstItem();
84
+    }
85
+
86
+    /**
87
+     * Returns the ttl of the process
88
+     *
89
+     * @return int
90
+     */
91
+    public function getTTL() {
92
+        return $this->row['ttl'];
93
+    }
94
+
95
+    /**
96
+     * Counts the number of items which need to be processed
97
+     *
98
+     * @author Timo Schmidt <[email protected]>
99
+     * @param void
100
+     * @return int
101
+     */
102
+    public function countItemsProcessed() {
103
+        $queueRepository = new tx_crawler_domain_queue_repository();
104
+        return $queueRepository->countExtecutedItemsByProcess($this);
105
+    }
106
+
107
+    /**
108
+     * Counts the number of items which still need to be processed
109
+     *
110
+     * @author Timo Schmidt <[email protected]>
111
+     * @param void
112
+     * @return int
113
+     */
114
+    public function countItemsToProcess() {
115
+        $queueRepository = new tx_crawler_domain_queue_repository();
116
+        return $queueRepository->countNonExecutedItemsByProcess($this);
117
+    }
118
+
119
+    /**
120
+     * Returns the Progress of a crawling process as a percentage value
121
+     *
122
+     * @param void
123
+     * @return float
124
+     */
125
+    public function getProgress() {
126
+        $all = $this->countItemsAssigned();
127
+        if ($all > 0) {
128
+            $res = round((100 / $all) * $this->countItemsProcessed());
129
+        } else {
130
+            $res = 0;
131
+        }
132
+        return $res;
133
+    }
134
+
135
+    /**
136
+     * Returns the number of assigned Entrys
137
+     *
138
+     * @return int
139
+     */
140
+    public function countItemsAssigned() {
141
+        return $this->row['assigned_items_count'];
142
+    }
143
+
144
+    /**
145
+     * Return the processes current state
146
+     *
147
+     * @param void
148
+     * @return string 'running'|'cancelled'|'completed'
149
+     */
150
+    public function getState() {
151
+        // TODO: use class constants for these states
152
+        if ($this->getActive() && $this->getProgress() < 100) {
153
+            $stage = 'running';
154
+        } elseif(!$this->getActive() && $this->getProgress() < 100) {
155
+            $stage = 'cancelled';
156
+        } else {
157
+            $stage = 'completed';
158
+        }
159
+        return $stage;
160
+    }
161 161
 }
162 162
 
163 163
 ?>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@
 block discarded – undo
151 151
 		// TODO: use class constants for these states
152 152
 		if ($this->getActive() && $this->getProgress() < 100) {
153 153
 			$stage = 'running';
154
-		} elseif(!$this->getActive() && $this->getProgress() < 100) {
154
+		} elseif (!$this->getActive() && $this->getProgress() < 100) {
155 155
 			$stage = 'cancelled';
156 156
 		} else {
157 157
 			$stage = 'completed';
Please login to merge, or discard this patch.