1
|
|
|
<?php |
2
|
|
|
/*************************************************************** |
3
|
|
|
* Copyright notice |
4
|
|
|
* |
5
|
|
|
* (c) 2009 AOE media ([email protected]) |
6
|
|
|
* All rights reserved |
7
|
|
|
* |
8
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
9
|
|
|
* free software; you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* The GNU General Public License can be found at |
15
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
16
|
|
|
* |
17
|
|
|
* This script is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
23
|
|
|
***************************************************************/ |
24
|
|
|
|
25
|
|
|
class tx_crawler_domain_process extends tx_crawler_domain_lib_abstract_dbobject |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string table name |
30
|
|
|
*/ |
31
|
|
|
protected static $tableName = 'tx_crawler_process'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns the activity state for this process |
35
|
|
|
* |
36
|
|
|
* @param void |
37
|
|
|
* @return boolean |
38
|
|
|
*/ |
39
|
|
|
public function getActive() |
40
|
|
|
{ |
41
|
|
|
return $this->row['active']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the identifier for the process |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
1 |
|
public function getProcess_id() |
50
|
|
|
{ |
51
|
1 |
|
return $this->row['process_id']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the timestamp of the exectime for the first relevant queue item. |
56
|
|
|
* This can be used to determine the runtime |
57
|
|
|
* |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
|
|
public function getTimeForFirstItem() |
61
|
|
|
{ |
62
|
|
|
$queueRepository = new tx_crawler_domain_queue_repository(); |
63
|
|
|
$entry = $queueRepository->findYoungestEntryForProcess($this); |
64
|
|
|
|
65
|
|
|
return $entry->getExecutionTime(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns the timestamp of the exectime for the last relevant queue item. |
70
|
|
|
* This can be used to determine the runtime |
71
|
|
|
* |
72
|
|
|
* @return int |
73
|
|
|
*/ |
74
|
|
|
public function getTimeForLastItem() |
75
|
|
|
{ |
76
|
|
|
$queueRepository = new tx_crawler_domain_queue_repository(); |
77
|
|
|
$entry = $queueRepository->findOldestEntryForProcess($this); |
78
|
|
|
|
79
|
|
|
return $entry->getExecutionTime(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the difference between first and last processed item |
84
|
|
|
* |
85
|
|
|
* @return int |
86
|
|
|
*/ |
87
|
|
|
public function getRuntime() |
88
|
|
|
{ |
89
|
|
|
return $this->getTimeForLastItem() - $this->getTimeForFirstItem(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns the ttl of the process |
94
|
|
|
* |
95
|
|
|
* @return int |
96
|
|
|
*/ |
97
|
|
|
public function getTTL() |
98
|
|
|
{ |
99
|
|
|
return $this->row['ttl']; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Counts the number of items which need to be processed |
104
|
|
|
* |
105
|
|
|
* @param void |
106
|
|
|
* @return int |
107
|
|
|
*/ |
108
|
|
|
public function countItemsProcessed() |
109
|
|
|
{ |
110
|
|
|
$queueRepository = new tx_crawler_domain_queue_repository(); |
111
|
|
|
return $queueRepository->countExtecutedItemsByProcess($this); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Counts the number of items which still need to be processed |
116
|
|
|
* |
117
|
|
|
* @param void |
118
|
|
|
* @return int |
119
|
|
|
*/ |
120
|
|
|
public function countItemsToProcess() |
121
|
|
|
{ |
122
|
|
|
$queueRepository = new tx_crawler_domain_queue_repository(); |
123
|
|
|
return $queueRepository->countNonExecutedItemsByProcess($this); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns the Progress of a crawling process as a percentage value |
128
|
|
|
* |
129
|
|
|
* @param void |
130
|
|
|
* @return float |
131
|
|
|
*/ |
132
|
|
|
public function getProgress() |
133
|
|
|
{ |
134
|
|
|
$all = $this->countItemsAssigned(); |
135
|
|
|
if ($all > 0) { |
136
|
|
|
$res = round((100 / $all) * $this->countItemsProcessed()); |
137
|
|
|
} else { |
138
|
|
|
$res = 0; |
139
|
|
|
} |
140
|
|
|
return $res; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Returns the number of assigned Entrys |
145
|
|
|
* |
146
|
|
|
* @return int |
147
|
|
|
*/ |
148
|
|
|
public function countItemsAssigned() |
149
|
|
|
{ |
150
|
|
|
return $this->row['assigned_items_count']; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Return the processes current state |
155
|
|
|
* |
156
|
|
|
* @param void |
157
|
|
|
* @return string 'running'|'cancelled'|'completed' |
158
|
|
|
*/ |
159
|
|
|
public function getState() |
160
|
|
|
{ |
161
|
|
|
// TODO: use class constants for these states |
162
|
|
|
if ($this->getActive() && $this->getProgress() < 100) { |
163
|
|
|
$stage = 'running'; |
164
|
|
|
} elseif (!$this->getActive() && $this->getProgress() < 100) { |
165
|
|
|
$stage = 'cancelled'; |
166
|
|
|
} else { |
167
|
|
|
$stage = 'completed'; |
168
|
|
|
} |
169
|
|
|
return $stage; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|