@@ -25,270 +25,270 @@ |
||
25 | 25 | class tx_crawler_domain_queue_repository extends tx_crawler_domain_lib_abstract_repository { |
26 | 26 | |
27 | 27 | |
28 | - protected $objectClassname = 'tx_crawler_domain_queue_entry'; |
|
28 | + protected $objectClassname = 'tx_crawler_domain_queue_entry'; |
|
29 | 29 | |
30 | - protected $tableName = 'tx_crawler_queue'; |
|
30 | + protected $tableName = 'tx_crawler_queue'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * This mehtod is used to find the youngest entry for a given process. |
|
34 | - * |
|
35 | - * @author Timo Schmidt <[email protected]> |
|
36 | - * @param tx_crawler_domain_process $process |
|
37 | - * @return tx_crawler_domain_queue_entry $entry |
|
38 | - */ |
|
39 | - public function findYoungestEntryForProcess(tx_crawler_domain_process $process) { |
|
40 | - return $this->getFirstOrLastObjectByProcess($process,'exec_time ASC'); |
|
41 | - } |
|
32 | + /** |
|
33 | + * This mehtod is used to find the youngest entry for a given process. |
|
34 | + * |
|
35 | + * @author Timo Schmidt <[email protected]> |
|
36 | + * @param tx_crawler_domain_process $process |
|
37 | + * @return tx_crawler_domain_queue_entry $entry |
|
38 | + */ |
|
39 | + public function findYoungestEntryForProcess(tx_crawler_domain_process $process) { |
|
40 | + return $this->getFirstOrLastObjectByProcess($process,'exec_time ASC'); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * This method is used to find the oldest entry for a given process. |
|
45 | - * |
|
46 | - * @param tx_crawler_domain_process $process |
|
47 | - * @return tx_crawler_domain_queue_entry |
|
48 | - */ |
|
49 | - public function findOldestEntryForProcess(tx_crawler_domain_process $process) { |
|
50 | - return $this->getFirstOrLastObjectByProcess($process,'exec_time DESC'); |
|
51 | - } |
|
43 | + /** |
|
44 | + * This method is used to find the oldest entry for a given process. |
|
45 | + * |
|
46 | + * @param tx_crawler_domain_process $process |
|
47 | + * @return tx_crawler_domain_queue_entry |
|
48 | + */ |
|
49 | + public function findOldestEntryForProcess(tx_crawler_domain_process $process) { |
|
50 | + return $this->getFirstOrLastObjectByProcess($process,'exec_time DESC'); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * This internal helper method is used to create an instance of an entry object |
|
56 | - * |
|
57 | - * @param tx_crawler_domain_process $process |
|
58 | - * @param string $orderby first matching item will be returned as object |
|
59 | - * @return tx_crawler_domain_queue_entry |
|
60 | - */ |
|
61 | - protected function getFirstOrLastObjectByProcess($process, $orderby) { |
|
62 | - $db = $this->getDB(); |
|
63 | - $where = 'process_id_completed='.$db->fullQuoteStr($process->getProcess_id(),$this->tableName). |
|
64 | - ' AND exec_time > 0 '; |
|
65 | - $limit = 1; |
|
66 | - $groupby = ''; |
|
54 | + /** |
|
55 | + * This internal helper method is used to create an instance of an entry object |
|
56 | + * |
|
57 | + * @param tx_crawler_domain_process $process |
|
58 | + * @param string $orderby first matching item will be returned as object |
|
59 | + * @return tx_crawler_domain_queue_entry |
|
60 | + */ |
|
61 | + protected function getFirstOrLastObjectByProcess($process, $orderby) { |
|
62 | + $db = $this->getDB(); |
|
63 | + $where = 'process_id_completed='.$db->fullQuoteStr($process->getProcess_id(),$this->tableName). |
|
64 | + ' AND exec_time > 0 '; |
|
65 | + $limit = 1; |
|
66 | + $groupby = ''; |
|
67 | 67 | |
68 | - $res = $db->exec_SELECTgetRows('*','tx_crawler_queue',$where,$groupby,$orderby,$limit); |
|
69 | - if($res) { |
|
70 | - $first = $res[0]; |
|
71 | - }else{ |
|
72 | - $first = array(); |
|
73 | - } |
|
74 | - $resultObject = new tx_crawler_domain_queue_entry($first); |
|
75 | - return $resultObject; |
|
76 | - } |
|
68 | + $res = $db->exec_SELECTgetRows('*','tx_crawler_queue',$where,$groupby,$orderby,$limit); |
|
69 | + if($res) { |
|
70 | + $first = $res[0]; |
|
71 | + }else{ |
|
72 | + $first = array(); |
|
73 | + } |
|
74 | + $resultObject = new tx_crawler_domain_queue_entry($first); |
|
75 | + return $resultObject; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Counts all executed items of a process. |
|
80 | - * |
|
81 | - * @param tx_crawler_domain_process $process |
|
82 | - * @return int |
|
83 | - */ |
|
84 | - public function countExtecutedItemsByProcess($process) { |
|
78 | + /** |
|
79 | + * Counts all executed items of a process. |
|
80 | + * |
|
81 | + * @param tx_crawler_domain_process $process |
|
82 | + * @return int |
|
83 | + */ |
|
84 | + public function countExtecutedItemsByProcess($process) { |
|
85 | 85 | |
86 | - return $this->countItemsByWhereClause('exec_time > 0 AND process_id_completed = '.$this->getDB()->fullQuoteStr($process->getProcess_id(),$this->tableName)); |
|
87 | - } |
|
86 | + return $this->countItemsByWhereClause('exec_time > 0 AND process_id_completed = '.$this->getDB()->fullQuoteStr($process->getProcess_id(),$this->tableName)); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Counts items of a process which yet have not been processed/executed |
|
91 | - * |
|
92 | - * @param tx_crawler_domain_process $process |
|
93 | - * @return int |
|
94 | - */ |
|
95 | - public function countNonExecutedItemsByProcess($process) { |
|
96 | - return $this->countItemsByWhereClause('exec_time = 0 AND process_id = '.$this->getDB()->fullQuoteStr($process->getProcess_id(),$this->tableName)); |
|
97 | - } |
|
89 | + /** |
|
90 | + * Counts items of a process which yet have not been processed/executed |
|
91 | + * |
|
92 | + * @param tx_crawler_domain_process $process |
|
93 | + * @return int |
|
94 | + */ |
|
95 | + public function countNonExecutedItemsByProcess($process) { |
|
96 | + return $this->countItemsByWhereClause('exec_time = 0 AND process_id = '.$this->getDB()->fullQuoteStr($process->getProcess_id(),$this->tableName)); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * This method can be used to count all queue entrys which are |
|
101 | - * scheduled for now or a earler date. |
|
102 | - * |
|
103 | - * @param void |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function countAllPendingItems() { |
|
107 | - return $this->countItemsByWhereClause('exec_time = 0 AND scheduled < '.time()); |
|
108 | - } |
|
99 | + /** |
|
100 | + * This method can be used to count all queue entrys which are |
|
101 | + * scheduled for now or a earler date. |
|
102 | + * |
|
103 | + * @param void |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function countAllPendingItems() { |
|
107 | + return $this->countItemsByWhereClause('exec_time = 0 AND scheduled < '.time()); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * This method can be used to count all queue entrys which are |
|
112 | - * scheduled for now or a earler date and are assigned to a process. |
|
113 | - * |
|
114 | - * @param void |
|
115 | - * @return int |
|
116 | - */ |
|
117 | - public function countAllAssignedPendingItems() { |
|
118 | - return $this->countItemsByWhereClause("exec_time = 0 AND scheduled < ".time()." AND process_id != ''"); |
|
119 | - } |
|
110 | + /** |
|
111 | + * This method can be used to count all queue entrys which are |
|
112 | + * scheduled for now or a earler date and are assigned to a process. |
|
113 | + * |
|
114 | + * @param void |
|
115 | + * @return int |
|
116 | + */ |
|
117 | + public function countAllAssignedPendingItems() { |
|
118 | + return $this->countItemsByWhereClause("exec_time = 0 AND scheduled < ".time()." AND process_id != ''"); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * This method can be used to count all queue entrys which are |
|
123 | - * scheduled for now or a earler date and are not assigned to a process. |
|
124 | - * |
|
125 | - * @param void |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - public function countAllUnassignedPendingItems() { |
|
129 | - return $this->countItemsByWhereClause("exec_time = 0 AND scheduled < ".time()." AND process_id = ''"); |
|
130 | - } |
|
121 | + /** |
|
122 | + * This method can be used to count all queue entrys which are |
|
123 | + * scheduled for now or a earler date and are not assigned to a process. |
|
124 | + * |
|
125 | + * @param void |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + public function countAllUnassignedPendingItems() { |
|
129 | + return $this->countItemsByWhereClause("exec_time = 0 AND scheduled < ".time()." AND process_id = ''"); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Internal method to count items by a given where clause |
|
134 | - * |
|
135 | - */ |
|
136 | - protected function countItemsByWhereClause($where) { |
|
137 | - $db = $this->getDB(); |
|
138 | - $rs = $db->exec_SELECTquery('count(*) as anz',$this->tableName,$where); |
|
139 | - $res = $db->sql_fetch_assoc($rs); |
|
132 | + /** |
|
133 | + * Internal method to count items by a given where clause |
|
134 | + * |
|
135 | + */ |
|
136 | + protected function countItemsByWhereClause($where) { |
|
137 | + $db = $this->getDB(); |
|
138 | + $rs = $db->exec_SELECTquery('count(*) as anz',$this->tableName,$where); |
|
139 | + $res = $db->sql_fetch_assoc($rs); |
|
140 | 140 | |
141 | - return $res['anz']; |
|
142 | - } |
|
141 | + return $res['anz']; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Count pending queue entries grouped by configuration key |
|
146 | - * |
|
147 | - * @param void |
|
148 | - * @return array |
|
149 | - * @author Fabrizio Branca <[email protected]> |
|
150 | - * @since 2099-09-03 |
|
151 | - */ |
|
152 | - public function countPendingItemsGroupedByConfigurationKey() { |
|
153 | - $db = $this->getDB(); |
|
154 | - $res = $db->exec_SELECTquery( |
|
155 | - "configuration, count(*) as unprocessed, sum(process_id != '') as assignedButUnprocessed", |
|
156 | - $this->tableName, |
|
157 | - 'exec_time = 0 AND scheduled < '.time(), |
|
158 | - 'configuration' |
|
159 | - ); |
|
160 | - $rows = array(); |
|
161 | - while ($row = $db->sql_fetch_assoc($res)) { |
|
162 | - $rows[] = $row; |
|
163 | - } |
|
164 | - return $rows; |
|
165 | - } |
|
144 | + /** |
|
145 | + * Count pending queue entries grouped by configuration key |
|
146 | + * |
|
147 | + * @param void |
|
148 | + * @return array |
|
149 | + * @author Fabrizio Branca <[email protected]> |
|
150 | + * @since 2099-09-03 |
|
151 | + */ |
|
152 | + public function countPendingItemsGroupedByConfigurationKey() { |
|
153 | + $db = $this->getDB(); |
|
154 | + $res = $db->exec_SELECTquery( |
|
155 | + "configuration, count(*) as unprocessed, sum(process_id != '') as assignedButUnprocessed", |
|
156 | + $this->tableName, |
|
157 | + 'exec_time = 0 AND scheduled < '.time(), |
|
158 | + 'configuration' |
|
159 | + ); |
|
160 | + $rows = array(); |
|
161 | + while ($row = $db->sql_fetch_assoc($res)) { |
|
162 | + $rows[] = $row; |
|
163 | + } |
|
164 | + return $rows; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Get set id with unprocessed entries |
|
169 | - * |
|
170 | - * @param void |
|
171 | - * @return array array of set ids |
|
172 | - * @author Fabrizio Branca <[email protected]> |
|
173 | - * @since 2009-09-03 |
|
174 | - */ |
|
175 | - public function getSetIdWithUnprocessedEntries() { |
|
176 | - $db = $this->getDB(); |
|
177 | - $res = $db->exec_SELECTquery( |
|
178 | - 'set_id', |
|
179 | - $this->tableName, |
|
180 | - 'exec_time = 0 AND scheduled < '.time(), |
|
181 | - 'set_id' |
|
182 | - ); |
|
183 | - $setIds = array(); |
|
184 | - while ($row = $db->sql_fetch_assoc($res)) { |
|
185 | - $setIds[] = intval($row['set_id']); |
|
186 | - } |
|
187 | - return $setIds; |
|
188 | - } |
|
167 | + /** |
|
168 | + * Get set id with unprocessed entries |
|
169 | + * |
|
170 | + * @param void |
|
171 | + * @return array array of set ids |
|
172 | + * @author Fabrizio Branca <[email protected]> |
|
173 | + * @since 2009-09-03 |
|
174 | + */ |
|
175 | + public function getSetIdWithUnprocessedEntries() { |
|
176 | + $db = $this->getDB(); |
|
177 | + $res = $db->exec_SELECTquery( |
|
178 | + 'set_id', |
|
179 | + $this->tableName, |
|
180 | + 'exec_time = 0 AND scheduled < '.time(), |
|
181 | + 'set_id' |
|
182 | + ); |
|
183 | + $setIds = array(); |
|
184 | + while ($row = $db->sql_fetch_assoc($res)) { |
|
185 | + $setIds[] = intval($row['set_id']); |
|
186 | + } |
|
187 | + return $setIds; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Get total queue entries by configuration |
|
192 | - * |
|
193 | - * @param array set ids |
|
194 | - * @return array totals by configuration (keys) |
|
195 | - * @author Fabrizio Branca <[email protected]> |
|
196 | - * @since 2009-09-03 |
|
197 | - */ |
|
198 | - public function getTotalQueueEntriesByConfiguration(array $setIds) { |
|
199 | - $totals = array(); |
|
200 | - if (count($setIds) > 0) { |
|
201 | - $db = $this->getDB(); |
|
202 | - $res = $db->exec_SELECTquery( |
|
203 | - 'configuration, count(*) as c', |
|
204 | - $this->tableName, |
|
205 | - 'set_id in ('. implode(',',$setIds).') AND scheduled < '.time(), |
|
206 | - 'configuration' |
|
207 | - ); |
|
208 | - while ($row = $db->sql_fetch_assoc($res)) { |
|
209 | - $totals[$row['configuration']] = $row['c']; |
|
210 | - } |
|
211 | - } |
|
212 | - return $totals; |
|
213 | - } |
|
190 | + /** |
|
191 | + * Get total queue entries by configuration |
|
192 | + * |
|
193 | + * @param array set ids |
|
194 | + * @return array totals by configuration (keys) |
|
195 | + * @author Fabrizio Branca <[email protected]> |
|
196 | + * @since 2009-09-03 |
|
197 | + */ |
|
198 | + public function getTotalQueueEntriesByConfiguration(array $setIds) { |
|
199 | + $totals = array(); |
|
200 | + if (count($setIds) > 0) { |
|
201 | + $db = $this->getDB(); |
|
202 | + $res = $db->exec_SELECTquery( |
|
203 | + 'configuration, count(*) as c', |
|
204 | + $this->tableName, |
|
205 | + 'set_id in ('. implode(',',$setIds).') AND scheduled < '.time(), |
|
206 | + 'configuration' |
|
207 | + ); |
|
208 | + while ($row = $db->sql_fetch_assoc($res)) { |
|
209 | + $totals[$row['configuration']] = $row['c']; |
|
210 | + } |
|
211 | + } |
|
212 | + return $totals; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Get the timestamps of the last processed entries |
|
217 | - * |
|
218 | - * @param void |
|
219 | - * @return array |
|
220 | - * @author Fabrizio Branca <[email protected]> |
|
221 | - * @since 2009-09-03 |
|
222 | - */ |
|
223 | - public function getLastProcessedEntriesTimestamps($limit = 100) { |
|
224 | - $db = $this->getDB(); |
|
225 | - $res = $db->exec_SELECTquery( |
|
226 | - 'exec_time', |
|
227 | - $this->tableName, |
|
228 | - '', |
|
229 | - '', |
|
230 | - 'exec_time desc', |
|
231 | - $limit |
|
232 | - ); |
|
215 | + /** |
|
216 | + * Get the timestamps of the last processed entries |
|
217 | + * |
|
218 | + * @param void |
|
219 | + * @return array |
|
220 | + * @author Fabrizio Branca <[email protected]> |
|
221 | + * @since 2009-09-03 |
|
222 | + */ |
|
223 | + public function getLastProcessedEntriesTimestamps($limit = 100) { |
|
224 | + $db = $this->getDB(); |
|
225 | + $res = $db->exec_SELECTquery( |
|
226 | + 'exec_time', |
|
227 | + $this->tableName, |
|
228 | + '', |
|
229 | + '', |
|
230 | + 'exec_time desc', |
|
231 | + $limit |
|
232 | + ); |
|
233 | 233 | |
234 | - $rows = array(); |
|
235 | - while (($row = $db->sql_fetch_assoc($res)) !== false) { |
|
236 | - $rows[] = $row['exec_time']; |
|
237 | - } |
|
238 | - return $rows; |
|
239 | - } |
|
234 | + $rows = array(); |
|
235 | + while (($row = $db->sql_fetch_assoc($res)) !== false) { |
|
236 | + $rows[] = $row['exec_time']; |
|
237 | + } |
|
238 | + return $rows; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Get the last processed entries |
|
243 | - * |
|
244 | - * @param string $selectFields |
|
245 | - * @param int $limit |
|
246 | - * @return array |
|
247 | - * @author Fabrizio Branca <[email protected]> |
|
248 | - * @since 2010-11-16 |
|
249 | - */ |
|
250 | - public function getLastProcessedEntries($selectFields='*', $limit='100') { |
|
251 | - $db = $this->getDB(); |
|
252 | - $res = $db->exec_SELECTquery( |
|
253 | - $selectFields, |
|
254 | - $this->tableName, |
|
255 | - '', |
|
256 | - '', |
|
257 | - 'exec_time desc', |
|
258 | - $limit |
|
259 | - ); |
|
241 | + /** |
|
242 | + * Get the last processed entries |
|
243 | + * |
|
244 | + * @param string $selectFields |
|
245 | + * @param int $limit |
|
246 | + * @return array |
|
247 | + * @author Fabrizio Branca <[email protected]> |
|
248 | + * @since 2010-11-16 |
|
249 | + */ |
|
250 | + public function getLastProcessedEntries($selectFields='*', $limit='100') { |
|
251 | + $db = $this->getDB(); |
|
252 | + $res = $db->exec_SELECTquery( |
|
253 | + $selectFields, |
|
254 | + $this->tableName, |
|
255 | + '', |
|
256 | + '', |
|
257 | + 'exec_time desc', |
|
258 | + $limit |
|
259 | + ); |
|
260 | 260 | |
261 | - $rows = array(); |
|
262 | - while (($row = $db->sql_fetch_assoc($res)) !== false) { |
|
263 | - $rows[] = $row; |
|
264 | - } |
|
265 | - return $rows; |
|
266 | - } |
|
261 | + $rows = array(); |
|
262 | + while (($row = $db->sql_fetch_assoc($res)) !== false) { |
|
263 | + $rows[] = $row; |
|
264 | + } |
|
265 | + return $rows; |
|
266 | + } |
|
267 | 267 | |
268 | - /** |
|
269 | - * Get performance statistics data |
|
270 | - * |
|
271 | - * @param int start timestamp |
|
272 | - * @param int end timestamp |
|
273 | - * @return array performance data |
|
274 | - * @author Fabrizio Branca <[email protected]> |
|
275 | - * @since 2009-09-03 |
|
276 | - */ |
|
277 | - public function getPerformanceData($start, $end) { |
|
278 | - $db = $this->getDB(); |
|
279 | - $res = $db->exec_SELECTquery( |
|
280 | - 'process_id_completed, min(exec_time) as start, max(exec_time) as end, count(*) as urlcount', |
|
281 | - $this->tableName, |
|
282 | - 'exec_time != 0 and exec_time >= '.intval($start). ' and exec_time <= ' . intval($end), |
|
283 | - 'process_id_completed' |
|
284 | - ); |
|
268 | + /** |
|
269 | + * Get performance statistics data |
|
270 | + * |
|
271 | + * @param int start timestamp |
|
272 | + * @param int end timestamp |
|
273 | + * @return array performance data |
|
274 | + * @author Fabrizio Branca <[email protected]> |
|
275 | + * @since 2009-09-03 |
|
276 | + */ |
|
277 | + public function getPerformanceData($start, $end) { |
|
278 | + $db = $this->getDB(); |
|
279 | + $res = $db->exec_SELECTquery( |
|
280 | + 'process_id_completed, min(exec_time) as start, max(exec_time) as end, count(*) as urlcount', |
|
281 | + $this->tableName, |
|
282 | + 'exec_time != 0 and exec_time >= '.intval($start). ' and exec_time <= ' . intval($end), |
|
283 | + 'process_id_completed' |
|
284 | + ); |
|
285 | 285 | |
286 | - $rows = array(); |
|
287 | - while (($row = $db->sql_fetch_assoc($res)) !== false) { |
|
288 | - $rows[$row['process_id_completed']] = $row; |
|
289 | - } |
|
290 | - return $rows; |
|
291 | - } |
|
286 | + $rows = array(); |
|
287 | + while (($row = $db->sql_fetch_assoc($res)) !== false) { |
|
288 | + $rows[$row['process_id_completed']] = $row; |
|
289 | + } |
|
290 | + return $rows; |
|
291 | + } |
|
292 | 292 | |
293 | 293 | /** |
294 | 294 | * This method is used to count all processes in the process table. |
@@ -24,21 +24,21 @@ |
||
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 |
@@ -24,36 +24,36 @@ |
||
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 | } |
@@ -24,97 +24,97 @@ |
||
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 | } |
@@ -24,140 +24,140 @@ |
||
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 | ?> |
@@ -24,121 +24,121 @@ |
||
24 | 24 | |
25 | 25 | class tx_crawler_view_pagination { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string template path |
|
29 | - */ |
|
30 | - protected $template = 'EXT:crawler/template/pagination.php'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var int $perpage number of items perPage |
|
34 | - */ |
|
35 | - protected $perPage; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int $currentOffset current offset |
|
39 | - */ |
|
40 | - protected $currentOffset; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int $totalItemCount number of total item |
|
44 | - */ |
|
45 | - protected $totalItemCount; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $baseUrl |
|
49 | - */ |
|
50 | - protected $baseUrl; |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Method to render the view. |
|
57 | - * |
|
58 | - * @return string html content |
|
59 | - */ |
|
60 | - public function render() { |
|
61 | - ob_start(); |
|
62 | - $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->template); |
|
63 | - include($this->template); |
|
64 | - $content = ob_get_contents(); |
|
65 | - ob_end_clean(); |
|
66 | - |
|
67 | - return $content; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the currently configured offset- |
|
72 | - * @return int |
|
73 | - */ |
|
74 | - public function getCurrentOffset() { |
|
75 | - return $this->currentOffset; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Method to read the number of items per page |
|
80 | - * |
|
81 | - * @return int |
|
82 | - */ |
|
83 | - public function getPerPage() { |
|
84 | - return $this->perPage; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Method to set the current offset from start |
|
89 | - * |
|
90 | - * @param int $currentOffset |
|
91 | - */ |
|
92 | - public function setCurrentOffset($currentOffset) { |
|
93 | - $this->currentOffset = $currentOffset; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Number of items per page. |
|
98 | - * |
|
99 | - * @param int $perPage |
|
100 | - */ |
|
101 | - public function setPerPage($perPage) { |
|
102 | - $this->perPage = $perPage; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * returns the total number of items |
|
107 | - * @return int |
|
108 | - */ |
|
109 | - public function getTotalItemCount() { |
|
110 | - return $this->totalItemCount; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Method to set the total number of items in the pagination |
|
115 | - * |
|
116 | - * @param int $totalItemCount |
|
117 | - */ |
|
118 | - public function setTotalItemCount($totalItemCount) { |
|
119 | - $this->totalItemCount = $totalItemCount; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the total number of pages needed to display all content which |
|
124 | - * is paginatable |
|
125 | - * |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - public function getTotalPagesCount() { |
|
129 | - return ceil($this->getTotalItemCount() / $this->getPerPage()); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * This method is used to caluclate the label for a pageoffset, |
|
134 | - * in normal cases its the internal offset + 1 |
|
135 | - * |
|
136 | - * @param int $pageoffset |
|
137 | - * @return int |
|
138 | - */ |
|
139 | - protected function getLabelForPageOffset($pageoffset) { |
|
140 | - return $pageoffset + 1; |
|
141 | - } |
|
27 | + /** |
|
28 | + * @var string template path |
|
29 | + */ |
|
30 | + protected $template = 'EXT:crawler/template/pagination.php'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var int $perpage number of items perPage |
|
34 | + */ |
|
35 | + protected $perPage; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int $currentOffset current offset |
|
39 | + */ |
|
40 | + protected $currentOffset; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int $totalItemCount number of total item |
|
44 | + */ |
|
45 | + protected $totalItemCount; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $baseUrl |
|
49 | + */ |
|
50 | + protected $baseUrl; |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Method to render the view. |
|
57 | + * |
|
58 | + * @return string html content |
|
59 | + */ |
|
60 | + public function render() { |
|
61 | + ob_start(); |
|
62 | + $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->template); |
|
63 | + include($this->template); |
|
64 | + $content = ob_get_contents(); |
|
65 | + ob_end_clean(); |
|
66 | + |
|
67 | + return $content; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the currently configured offset- |
|
72 | + * @return int |
|
73 | + */ |
|
74 | + public function getCurrentOffset() { |
|
75 | + return $this->currentOffset; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Method to read the number of items per page |
|
80 | + * |
|
81 | + * @return int |
|
82 | + */ |
|
83 | + public function getPerPage() { |
|
84 | + return $this->perPage; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Method to set the current offset from start |
|
89 | + * |
|
90 | + * @param int $currentOffset |
|
91 | + */ |
|
92 | + public function setCurrentOffset($currentOffset) { |
|
93 | + $this->currentOffset = $currentOffset; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Number of items per page. |
|
98 | + * |
|
99 | + * @param int $perPage |
|
100 | + */ |
|
101 | + public function setPerPage($perPage) { |
|
102 | + $this->perPage = $perPage; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * returns the total number of items |
|
107 | + * @return int |
|
108 | + */ |
|
109 | + public function getTotalItemCount() { |
|
110 | + return $this->totalItemCount; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Method to set the total number of items in the pagination |
|
115 | + * |
|
116 | + * @param int $totalItemCount |
|
117 | + */ |
|
118 | + public function setTotalItemCount($totalItemCount) { |
|
119 | + $this->totalItemCount = $totalItemCount; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the total number of pages needed to display all content which |
|
124 | + * is paginatable |
|
125 | + * |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + public function getTotalPagesCount() { |
|
129 | + return ceil($this->getTotalItemCount() / $this->getPerPage()); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * This method is used to caluclate the label for a pageoffset, |
|
134 | + * in normal cases its the internal offset + 1 |
|
135 | + * |
|
136 | + * @param int $pageoffset |
|
137 | + * @return int |
|
138 | + */ |
|
139 | + protected function getLabelForPageOffset($pageoffset) { |
|
140 | + return $pageoffset + 1; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | } |
144 | 144 |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | if (!defined('TYPO3_cliMode')) { |
3 | - die('You cannot run this script directly!'); |
|
3 | + die('You cannot run this script directly!'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | $processManager = new tx_crawler_domain_process_manager(); |
7 | 7 | $timeout = isset($_SERVER['argv'][1] ) ? intval($_SERVER['argv'][1]) : 1800; |
8 | 8 | |
9 | 9 | try { |
10 | - $processManager->multiProcess($timeout); |
|
10 | + $processManager->multiProcess($timeout); |
|
11 | 11 | } catch (Exception $e) { |
12 | - echo PHP_EOL . $e->getMessage(); |
|
12 | + echo PHP_EOL . $e->getMessage(); |
|
13 | 13 | } |
@@ -27,175 +27,175 @@ |
||
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 | } |
@@ -24,397 +24,397 @@ |
||
24 | 24 | |
25 | 25 | class tx_crawler_view_process_list { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string template path |
|
29 | - */ |
|
30 | - protected $template = 'EXT:crawler/template/process/list.php'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string icon path |
|
34 | - */ |
|
35 | - protected $iconPath; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string Holds the path to start a cli process via command line |
|
39 | - */ |
|
40 | - protected $cliPath; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int Holds the total number of items pending in the queue to be processed |
|
44 | - */ |
|
45 | - protected $totalItemCount; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var boolean Holds the enable state of the crawler |
|
49 | - */ |
|
50 | - protected $isCrawlerEnabled; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var int Holds the number of active processes |
|
54 | - */ |
|
55 | - protected $activeProcessCount; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var int Holds the number of maximum active processes |
|
59 | - */ |
|
60 | - protected $maxActiveProcessCount; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var string Holds the mode state, can be simple or detail |
|
64 | - */ |
|
65 | - protected $mode; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var int Holds the current page id |
|
69 | - */ |
|
70 | - protected $pageId; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var int $totalItemCount number of total item |
|
74 | - */ |
|
75 | - protected $totalUnprocessedItemCount; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var int Holds the number of assigned unprocessed items |
|
79 | - */ |
|
80 | - protected $assignedUnprocessedItemCount; |
|
81 | - |
|
82 | - /** |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function getAssignedUnprocessedItemCount() { |
|
86 | - return $this->assignedUnprocessedItemCount; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return int |
|
91 | - */ |
|
92 | - public function getTotalUnprocessedItemCount() { |
|
93 | - return $this->totalUnprocessedItemCount; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param int $assignedUnprocessedItemCount |
|
98 | - */ |
|
99 | - public function setAssignedUnprocessedItemCount($assignedUnprocessedItemCount) { |
|
100 | - $this->assignedUnprocessedItemCount = $assignedUnprocessedItemCount; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param int $totalUnprocessedItemCount |
|
105 | - */ |
|
106 | - public function setTotalUnprocessedItemCount($totalUnprocessedItemCount) { |
|
107 | - $this->totalUnprocessedItemCount = $totalUnprocessedItemCount; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Set the page id |
|
112 | - * |
|
113 | - * @param int page id |
|
114 | - */ |
|
115 | - public function setPageId($pageId) { |
|
116 | - $this->pageId = $pageId; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Get the page id |
|
121 | - * |
|
122 | - * @return int page id |
|
123 | - */ |
|
124 | - public function getPageId() { |
|
125 | - return $this->pageId; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function getMode() { |
|
132 | - return $this->mode; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * @param string $mode |
|
137 | - */ |
|
138 | - public function setMode($mode) { |
|
139 | - $this->mode = $mode; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return int |
|
145 | - */ |
|
146 | - public function getMaxActiveProcessCount() { |
|
147 | - return $this->maxActiveProcessCount; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param int $maxActiveProcessCount |
|
152 | - */ |
|
153 | - public function setMaxActiveProcessCount($maxActiveProcessCount) { |
|
154 | - $this->maxActiveProcessCount = $maxActiveProcessCount; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return int |
|
160 | - */ |
|
161 | - public function getActiveProcessCount() { |
|
162 | - return $this->activeProcessCount; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @param int $activeProcessCount |
|
167 | - */ |
|
168 | - public function setActiveProcessCount($activeProcessCount) { |
|
169 | - $this->activeProcessCount = $activeProcessCount; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @return boolean |
|
174 | - */ |
|
175 | - public function getIsCrawlerEnabled() { |
|
176 | - return $this->isCrawlerEnabled; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @param boolean $isCrawlerEnabled |
|
181 | - */ |
|
182 | - public function setIsCrawlerEnabled($isCrawlerEnabled) { |
|
183 | - $this->isCrawlerEnabled = $isCrawlerEnabled; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Returns the path to start a cli process from the shell |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function getCliPath() { |
|
192 | - return $this->cliPath; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $cliPath |
|
197 | - */ |
|
198 | - public function setCliPath($cliPath) { |
|
199 | - $this->cliPath = $cliPath; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return int |
|
205 | - */ |
|
206 | - public function getTotalItemCount() { |
|
207 | - return $this->totalItemCount; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param int $totalItemCount |
|
212 | - */ |
|
213 | - public function setTotalItemCount($totalItemCount) { |
|
214 | - $this->totalItemCount = $totalItemCount; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Method to set the path to the icon from outside |
|
219 | - * |
|
220 | - * @param string $iconPath |
|
221 | - */ |
|
222 | - public function setIconPath($iconPath) { |
|
223 | - $this->iconPath = $iconPath; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Method to read the configured icon path |
|
228 | - * |
|
229 | - * @return string |
|
230 | - */ |
|
231 | - protected function getIconPath() { |
|
232 | - return $this->iconPath; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Method to set a collection of process objects to be displayed in |
|
237 | - * the list view. |
|
238 | - * |
|
239 | - * @param tx_crawler_domain_process_collection $processCollection |
|
240 | - */ |
|
241 | - public function setProcessCollection($processCollection) { |
|
242 | - $this->processCollection = $processCollection; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Returns a collection of processObjects. |
|
247 | - * |
|
248 | - * @return tx_crawler_domain_process_collection |
|
249 | - */ |
|
250 | - protected function getProcessCollection() { |
|
251 | - return $this->processCollection; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Formats a timestamp as date |
|
256 | - * |
|
257 | - * @param int $timestamp |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - protected function asDate($timestamp) { |
|
261 | - if ($timestamp > 0) { |
|
262 | - return date($this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:time.detailed'), $timestamp); |
|
263 | - } else { |
|
264 | - return ''; |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Converts seconds into minutes |
|
270 | - * |
|
271 | - * @param int $seconds |
|
272 | - * @return int |
|
273 | - */ |
|
274 | - protected function asMinutes($seconds) { |
|
275 | - return round($seconds / 60); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns the state icon for the current job |
|
280 | - * |
|
281 | - * @param string $state |
|
282 | - * @return string icon |
|
283 | - */ |
|
284 | - protected function getIconForState($state) { |
|
285 | - switch($state) { |
|
286 | - case 'running': |
|
287 | - $icon = 'bullet_orange'; |
|
288 | - $title = $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.running'); |
|
289 | - break; |
|
290 | - case 'completed': |
|
291 | - $icon = 'bullet_green'; |
|
292 | - $title = $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.success'); |
|
293 | - break; |
|
294 | - case 'cancelled': |
|
295 | - $icon = 'bullet_red'; |
|
296 | - $title = $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.cancelled'); |
|
297 | - break; |
|
298 | - } |
|
299 | - |
|
300 | - return $this->getIcon($icon, $title); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Returns a tag for the refresh icon |
|
305 | - * |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - protected function getRefreshIcon() { |
|
309 | - return $this->getIcon('arrow_refresh'); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Returns a tag for the refresh icon |
|
314 | - * |
|
315 | - * @return string |
|
316 | - */ |
|
317 | - protected function getRefreshLink() { |
|
318 | - return '<input onclick="window.location=\'' . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_info') . '&SET[crawlaction]=multiprocess&id=' . $this->pageId . '\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'arrow_refresh.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.refresh') . '" />'; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Returns an icon to stop all processes |
|
323 | - * |
|
324 | - * @return string html tag for stop icon |
|
325 | - */ |
|
326 | - protected function getStopIcon() { |
|
327 | - return $this->getIcon('stop'); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Returns a link for the panel to enable or disable the crawler |
|
332 | - * |
|
333 | - * @return string |
|
334 | - */ |
|
335 | - protected function getEnableDisableLink() { |
|
336 | - if ($this->getIsCrawlerEnabled()) { |
|
337 | - return '<input onclick="window.location+=\'&action=stopCrawling\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'control_stop_blue.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.disablecrawling') . '" />'; |
|
338 | - } else { |
|
339 | - return '<input onclick="window.location+=\'&action=resumeCrawling\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'control_play.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.enablecrawling') . '" />'; |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Get mode link |
|
345 | - * |
|
346 | - * @param void |
|
347 | - * @return string a-tag |
|
348 | - */ |
|
349 | - protected function getModeLink() { |
|
350 | - if ($this->getMode() == 'detail') { |
|
351 | - return '<input onclick="window.location+=\'&SET[processListMode]=simple\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'arrow_in.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.show.running') . '" />'; |
|
352 | - } elseif ($this->getMode() == 'simple') { |
|
353 | - return '<input onclick="window.location+=\'&SET[processListMode]=detail\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'arrow_out.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.show.all') . '" />'; |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Get add link |
|
359 | - * |
|
360 | - * @param void |
|
361 | - * @return string a-tag |
|
362 | - */ |
|
363 | - protected function getAddLink() { |
|
364 | - if ($this->getActiveProcessCount() < $this->getMaxActiveProcessCount() && $this->getIsCrawlerEnabled()) { |
|
365 | - return '<input onclick="window.location+=\'&action=addProcess\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'add.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.add') . '" />'; |
|
366 | - } else { |
|
367 | - return ''; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Returns the icon to add new crawler processes |
|
373 | - * |
|
374 | - * @return string html tag for image to add new processes |
|
375 | - */ |
|
376 | - protected function getAddIcon() { |
|
377 | - return $this->getIcon('add'); |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Returns an imagetag for an icon |
|
382 | - * |
|
383 | - * @param string $icon |
|
384 | - * @return string html tag for icon |
|
385 | - */ |
|
386 | - protected function getIcon($icon, $title='') { |
|
387 | - if (!empty($title)) { |
|
388 | - $title = ' title="'.$title.'"'; |
|
389 | - } |
|
390 | - return '<img src="'.$this->getIconPath().$icon.'.png" ' . $title . ' />'; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Method to render the view. |
|
395 | - * |
|
396 | - * @return string html content |
|
397 | - */ |
|
398 | - public function render() { |
|
399 | - ob_start(); |
|
400 | - $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->template); |
|
401 | - include($this->template); |
|
402 | - $content = ob_get_contents(); |
|
403 | - ob_end_clean(); |
|
404 | - return $content; |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * retrieve locallanglabel from environment |
|
409 | - * just a wrapper should be done in a cleaner way |
|
410 | - * later on |
|
411 | - * |
|
412 | - * @param $label |
|
413 | - * @return string |
|
414 | - */ |
|
415 | - protected function getLLLabel($label) { |
|
416 | - return $GLOBALS['LANG']->sL($label); |
|
417 | - } |
|
27 | + /** |
|
28 | + * @var string template path |
|
29 | + */ |
|
30 | + protected $template = 'EXT:crawler/template/process/list.php'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string icon path |
|
34 | + */ |
|
35 | + protected $iconPath; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string Holds the path to start a cli process via command line |
|
39 | + */ |
|
40 | + protected $cliPath; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int Holds the total number of items pending in the queue to be processed |
|
44 | + */ |
|
45 | + protected $totalItemCount; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var boolean Holds the enable state of the crawler |
|
49 | + */ |
|
50 | + protected $isCrawlerEnabled; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var int Holds the number of active processes |
|
54 | + */ |
|
55 | + protected $activeProcessCount; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var int Holds the number of maximum active processes |
|
59 | + */ |
|
60 | + protected $maxActiveProcessCount; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var string Holds the mode state, can be simple or detail |
|
64 | + */ |
|
65 | + protected $mode; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var int Holds the current page id |
|
69 | + */ |
|
70 | + protected $pageId; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var int $totalItemCount number of total item |
|
74 | + */ |
|
75 | + protected $totalUnprocessedItemCount; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var int Holds the number of assigned unprocessed items |
|
79 | + */ |
|
80 | + protected $assignedUnprocessedItemCount; |
|
81 | + |
|
82 | + /** |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function getAssignedUnprocessedItemCount() { |
|
86 | + return $this->assignedUnprocessedItemCount; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return int |
|
91 | + */ |
|
92 | + public function getTotalUnprocessedItemCount() { |
|
93 | + return $this->totalUnprocessedItemCount; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param int $assignedUnprocessedItemCount |
|
98 | + */ |
|
99 | + public function setAssignedUnprocessedItemCount($assignedUnprocessedItemCount) { |
|
100 | + $this->assignedUnprocessedItemCount = $assignedUnprocessedItemCount; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param int $totalUnprocessedItemCount |
|
105 | + */ |
|
106 | + public function setTotalUnprocessedItemCount($totalUnprocessedItemCount) { |
|
107 | + $this->totalUnprocessedItemCount = $totalUnprocessedItemCount; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Set the page id |
|
112 | + * |
|
113 | + * @param int page id |
|
114 | + */ |
|
115 | + public function setPageId($pageId) { |
|
116 | + $this->pageId = $pageId; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Get the page id |
|
121 | + * |
|
122 | + * @return int page id |
|
123 | + */ |
|
124 | + public function getPageId() { |
|
125 | + return $this->pageId; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function getMode() { |
|
132 | + return $this->mode; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * @param string $mode |
|
137 | + */ |
|
138 | + public function setMode($mode) { |
|
139 | + $this->mode = $mode; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return int |
|
145 | + */ |
|
146 | + public function getMaxActiveProcessCount() { |
|
147 | + return $this->maxActiveProcessCount; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param int $maxActiveProcessCount |
|
152 | + */ |
|
153 | + public function setMaxActiveProcessCount($maxActiveProcessCount) { |
|
154 | + $this->maxActiveProcessCount = $maxActiveProcessCount; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return int |
|
160 | + */ |
|
161 | + public function getActiveProcessCount() { |
|
162 | + return $this->activeProcessCount; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @param int $activeProcessCount |
|
167 | + */ |
|
168 | + public function setActiveProcessCount($activeProcessCount) { |
|
169 | + $this->activeProcessCount = $activeProcessCount; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @return boolean |
|
174 | + */ |
|
175 | + public function getIsCrawlerEnabled() { |
|
176 | + return $this->isCrawlerEnabled; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @param boolean $isCrawlerEnabled |
|
181 | + */ |
|
182 | + public function setIsCrawlerEnabled($isCrawlerEnabled) { |
|
183 | + $this->isCrawlerEnabled = $isCrawlerEnabled; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Returns the path to start a cli process from the shell |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function getCliPath() { |
|
192 | + return $this->cliPath; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $cliPath |
|
197 | + */ |
|
198 | + public function setCliPath($cliPath) { |
|
199 | + $this->cliPath = $cliPath; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return int |
|
205 | + */ |
|
206 | + public function getTotalItemCount() { |
|
207 | + return $this->totalItemCount; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param int $totalItemCount |
|
212 | + */ |
|
213 | + public function setTotalItemCount($totalItemCount) { |
|
214 | + $this->totalItemCount = $totalItemCount; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Method to set the path to the icon from outside |
|
219 | + * |
|
220 | + * @param string $iconPath |
|
221 | + */ |
|
222 | + public function setIconPath($iconPath) { |
|
223 | + $this->iconPath = $iconPath; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Method to read the configured icon path |
|
228 | + * |
|
229 | + * @return string |
|
230 | + */ |
|
231 | + protected function getIconPath() { |
|
232 | + return $this->iconPath; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Method to set a collection of process objects to be displayed in |
|
237 | + * the list view. |
|
238 | + * |
|
239 | + * @param tx_crawler_domain_process_collection $processCollection |
|
240 | + */ |
|
241 | + public function setProcessCollection($processCollection) { |
|
242 | + $this->processCollection = $processCollection; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Returns a collection of processObjects. |
|
247 | + * |
|
248 | + * @return tx_crawler_domain_process_collection |
|
249 | + */ |
|
250 | + protected function getProcessCollection() { |
|
251 | + return $this->processCollection; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Formats a timestamp as date |
|
256 | + * |
|
257 | + * @param int $timestamp |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + protected function asDate($timestamp) { |
|
261 | + if ($timestamp > 0) { |
|
262 | + return date($this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:time.detailed'), $timestamp); |
|
263 | + } else { |
|
264 | + return ''; |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Converts seconds into minutes |
|
270 | + * |
|
271 | + * @param int $seconds |
|
272 | + * @return int |
|
273 | + */ |
|
274 | + protected function asMinutes($seconds) { |
|
275 | + return round($seconds / 60); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns the state icon for the current job |
|
280 | + * |
|
281 | + * @param string $state |
|
282 | + * @return string icon |
|
283 | + */ |
|
284 | + protected function getIconForState($state) { |
|
285 | + switch($state) { |
|
286 | + case 'running': |
|
287 | + $icon = 'bullet_orange'; |
|
288 | + $title = $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.running'); |
|
289 | + break; |
|
290 | + case 'completed': |
|
291 | + $icon = 'bullet_green'; |
|
292 | + $title = $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.success'); |
|
293 | + break; |
|
294 | + case 'cancelled': |
|
295 | + $icon = 'bullet_red'; |
|
296 | + $title = $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.cancelled'); |
|
297 | + break; |
|
298 | + } |
|
299 | + |
|
300 | + return $this->getIcon($icon, $title); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Returns a tag for the refresh icon |
|
305 | + * |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + protected function getRefreshIcon() { |
|
309 | + return $this->getIcon('arrow_refresh'); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Returns a tag for the refresh icon |
|
314 | + * |
|
315 | + * @return string |
|
316 | + */ |
|
317 | + protected function getRefreshLink() { |
|
318 | + return '<input onclick="window.location=\'' . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_info') . '&SET[crawlaction]=multiprocess&id=' . $this->pageId . '\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'arrow_refresh.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.refresh') . '" />'; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Returns an icon to stop all processes |
|
323 | + * |
|
324 | + * @return string html tag for stop icon |
|
325 | + */ |
|
326 | + protected function getStopIcon() { |
|
327 | + return $this->getIcon('stop'); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Returns a link for the panel to enable or disable the crawler |
|
332 | + * |
|
333 | + * @return string |
|
334 | + */ |
|
335 | + protected function getEnableDisableLink() { |
|
336 | + if ($this->getIsCrawlerEnabled()) { |
|
337 | + return '<input onclick="window.location+=\'&action=stopCrawling\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'control_stop_blue.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.disablecrawling') . '" />'; |
|
338 | + } else { |
|
339 | + return '<input onclick="window.location+=\'&action=resumeCrawling\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'control_play.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.enablecrawling') . '" />'; |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Get mode link |
|
345 | + * |
|
346 | + * @param void |
|
347 | + * @return string a-tag |
|
348 | + */ |
|
349 | + protected function getModeLink() { |
|
350 | + if ($this->getMode() == 'detail') { |
|
351 | + return '<input onclick="window.location+=\'&SET[processListMode]=simple\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'arrow_in.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.show.running') . '" />'; |
|
352 | + } elseif ($this->getMode() == 'simple') { |
|
353 | + return '<input onclick="window.location+=\'&SET[processListMode]=detail\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'arrow_out.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.show.all') . '" />'; |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Get add link |
|
359 | + * |
|
360 | + * @param void |
|
361 | + * @return string a-tag |
|
362 | + */ |
|
363 | + protected function getAddLink() { |
|
364 | + if ($this->getActiveProcessCount() < $this->getMaxActiveProcessCount() && $this->getIsCrawlerEnabled()) { |
|
365 | + return '<input onclick="window.location+=\'&action=addProcess\';" type="button" style="padding:4px 4px 4px 20px; background-position: 3px 3px; background-image: url(\'' . $this->getIconPath() . 'add.png' . '\'); background-repeat: no-repeat;" value="' . $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.add') . '" />'; |
|
366 | + } else { |
|
367 | + return ''; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Returns the icon to add new crawler processes |
|
373 | + * |
|
374 | + * @return string html tag for image to add new processes |
|
375 | + */ |
|
376 | + protected function getAddIcon() { |
|
377 | + return $this->getIcon('add'); |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Returns an imagetag for an icon |
|
382 | + * |
|
383 | + * @param string $icon |
|
384 | + * @return string html tag for icon |
|
385 | + */ |
|
386 | + protected function getIcon($icon, $title='') { |
|
387 | + if (!empty($title)) { |
|
388 | + $title = ' title="'.$title.'"'; |
|
389 | + } |
|
390 | + return '<img src="'.$this->getIconPath().$icon.'.png" ' . $title . ' />'; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Method to render the view. |
|
395 | + * |
|
396 | + * @return string html content |
|
397 | + */ |
|
398 | + public function render() { |
|
399 | + ob_start(); |
|
400 | + $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->template); |
|
401 | + include($this->template); |
|
402 | + $content = ob_get_contents(); |
|
403 | + ob_end_clean(); |
|
404 | + return $content; |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * retrieve locallanglabel from environment |
|
409 | + * just a wrapper should be done in a cleaner way |
|
410 | + * later on |
|
411 | + * |
|
412 | + * @param $label |
|
413 | + * @return string |
|
414 | + */ |
|
415 | + protected function getLLLabel($label) { |
|
416 | + return $GLOBALS['LANG']->sL($label); |
|
417 | + } |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | ?> |