1 | <?php |
||
22 | class Nexcessnet_Turpentine_Helper_Cron extends Mage_Core_Helper_Abstract { |
||
|
|||
23 | |||
24 | /** |
||
25 | * Key to store the URL queue under in the cache |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | const CRAWLER_URLS_CACHE_ID = 'turpentine_crawler_url_queue'; |
||
30 | |||
31 | /** |
||
32 | * Crawler client singleton |
||
33 | * |
||
34 | * @var Varien_Http_Client |
||
35 | */ |
||
36 | protected $_crawlerClient = null; |
||
37 | |||
38 | /** |
||
39 | * Get the execution time used so far |
||
40 | * |
||
41 | * @return int |
||
42 | */ |
||
43 | public function getRunTime() { |
||
44 | $usage = getrusage(); |
||
45 | return $usage['ru_utime.tv_sec']; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get the max execution time (or 0 if unlimited) |
||
50 | * |
||
51 | * @return int |
||
52 | */ |
||
53 | public function getAllowedRunTime() { |
||
54 | return (int) ini_get('max_execution_time'); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Add a single URL to the queue, returns whether it was actually added |
||
59 | * to the queue or not (false if it was already in the queue) |
||
60 | * |
||
61 | * @param string $url |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function addUrlToCrawlerQueue($url) { |
||
67 | |||
68 | /** |
||
69 | * Add a list of URLs to the queue, returns how many unique URLs were |
||
70 | * actually added to the queue |
||
71 | * |
||
72 | * @param array $urls |
||
73 | * @return int |
||
74 | */ |
||
75 | public function addUrlsToCrawlerQueue(array $urls) { |
||
89 | |||
90 | /** |
||
91 | * Pop a URL to crawl off the queue, or null if no URLs left |
||
92 | * |
||
93 | * @return string|null |
||
94 | */ |
||
95 | public function getNextUrl() { |
||
101 | |||
102 | /** |
||
103 | * Get the current URL queue |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function getUrlQueue() { |
||
108 | return $this->_readUrlQueue(); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Get the crawler http client |
||
113 | * |
||
114 | * @return Varien_Http_Client |
||
115 | */ |
||
116 | public function getCrawlerClient() { |
||
129 | |||
130 | /** |
||
131 | * Get if the crawler is enabled |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function getCrawlerEnabled() { |
||
136 | return Mage::getStoreConfig('turpentine_varnish/general/crawler_enable'); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Get if crawler debugging is enabled |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function getCrawlerDebugEnabled() { |
||
145 | return Mage::getStoreConfig('turpentine_varnish/general/crawler_debug'); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Get number of urls to crawl per batch |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | public function getCrawlerBatchSize() { |
||
156 | |||
157 | /** |
||
158 | * Get time in seconds to wait between url batches |
||
159 | * |
||
160 | * @return int |
||
161 | */ |
||
162 | public function getCrawlerWaitPeriod() { |
||
165 | |||
166 | /** |
||
167 | * Get the list of all URLs |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | public function getAllUrls() { |
||
204 | |||
205 | /** |
||
206 | * Add URLs to the queue by product model |
||
207 | * |
||
208 | * @param Mage_Catalog_Model_Product $product |
||
209 | * @return int |
||
210 | */ |
||
211 | public function addProductToCrawlerQueue($product) { |
||
229 | |||
230 | /** |
||
231 | * Add URLs to the queue by category model |
||
232 | * |
||
233 | * @param Mage_Catalog_Model_Category $category |
||
234 | * @return int |
||
235 | */ |
||
236 | public function addCategoryToCrawlerQueue($category) { |
||
246 | |||
247 | /** |
||
248 | * Add URLs to queue by CMS page ID |
||
249 | * |
||
250 | * @param int $cmsPageId |
||
251 | * @return int |
||
252 | */ |
||
253 | public function addCmsPageToCrawlerQueue($cmsPageId) { |
||
266 | |||
267 | /** |
||
268 | * Get the crawler URL queue from the cache |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | protected function _readUrlQueue() { |
||
285 | |||
286 | /** |
||
287 | * Save the crawler URL queue to the cache |
||
288 | * |
||
289 | * @param array $urls |
||
290 | * @return null |
||
291 | */ |
||
292 | protected function _writeUrlQueue(array $urls) { |
||
296 | } |
||
297 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.