1 | <?php |
||
37 | class ProcessRepository extends AbstractRepository |
||
38 | { |
||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $tableName = 'tx_crawler_process'; |
||
43 | |||
44 | /** |
||
45 | * This method is used to find all cli processes within a limit. |
||
46 | * |
||
47 | * @param string $orderField |
||
48 | * @param string $orderDirection |
||
49 | * @param integer $itemCount |
||
50 | * @param integer $offset |
||
51 | * @param string $where |
||
52 | * |
||
53 | * @return ProcessCollection |
||
54 | */ |
||
55 | 7 | public function findAll($orderField = '', $orderDirection = 'DESC', $itemCount = null, $offset = null, $where = '') |
|
56 | { |
||
57 | /** @var ProcessCollection $collection */ |
||
58 | 7 | $collection = GeneralUtility::makeInstance(ProcessCollection::class); |
|
59 | |||
60 | 7 | $orderField = trim($orderField); |
|
61 | 7 | $orderField = empty($orderField) ? 'process_id' : $orderField; |
|
62 | |||
63 | 7 | $orderDirection = strtoupper(trim($orderDirection)); |
|
64 | 7 | $orderDirection = in_array($orderDirection, ['ASC', 'DESC']) ? $orderDirection : 'DESC'; |
|
65 | |||
66 | 7 | $rows = $this->getDB()->exec_SELECTgetRows( |
|
67 | 7 | '*', |
|
68 | 7 | $this->tableName, |
|
69 | 7 | $where, |
|
70 | 7 | '', |
|
71 | 7 | htmlspecialchars($orderField) . ' ' . htmlspecialchars($orderDirection), |
|
72 | 7 | self::getLimitFromItemCountAndOffset($itemCount, $offset) |
|
73 | ); |
||
74 | |||
75 | 7 | if (is_array($rows)) { |
|
76 | 7 | foreach ($rows as $row) { |
|
77 | 7 | $collection->append(GeneralUtility::makeInstance(Process::class, $row)); |
|
78 | } |
||
79 | } |
||
80 | |||
81 | 7 | return $collection; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * This method is used to count all processes in the process table. |
||
86 | * |
||
87 | * @param string $where Where clause |
||
88 | * |
||
89 | * @return integer |
||
90 | */ |
||
91 | 5 | public function countAll($where = '1 = 1') |
|
92 | { |
||
93 | 5 | return $this->countByWhere($where); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Returns the number of active processes. |
||
98 | * |
||
99 | * @return integer |
||
100 | */ |
||
101 | 1 | public function countActive() |
|
102 | { |
||
103 | 1 | return $this->countByWhere('active = 1 AND deleted = 0'); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Returns the number of processes that live longer than the given timestamp. |
||
108 | * |
||
109 | * @param integer $ttl |
||
110 | * |
||
111 | * @return integer |
||
112 | */ |
||
113 | 1 | public function countNotTimeouted($ttl) |
|
114 | { |
||
115 | 1 | return $this->countByWhere('deleted = 0 AND ttl > ' . intval($ttl)); |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Get limit clause |
||
120 | * |
||
121 | * @param integer $itemCount |
||
122 | * @param integer $offset |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | 11 | public static function getLimitFromItemCountAndOffset($itemCount, $offset) |
|
134 | } |
||
135 |