HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UrlsView.php
Go to the documentation of this file.
1 <?php
2 
3 class UrlsView
4 {
5  private $operation = 'URL_FETCH';
6 
7  public function fetch($userId, $params, $one = false)
8  {
9  $data = array();
10  $this->createRequest($userId, $params, $one);
11  $this->sendRequest($userId);
12  $json = $this->getResponse($userId);
13  Logger::log("Response -> \n" . $json, false);
14  $error = Errors::isError($json);
15  if ($error !== 0) {
16  $data['manError']['isError'] = true;
17  $data['manError']['errorBody'] = $error;
18  return $data;
19  }
20  if ($one !== false) {
21  return $this->getSingleData($userId, $json);
22  }
23  return $this->getMultiData($userId, $json);
24  }
25 
26  public function createRequest($userId, $params, $one = false)
27  {
28  if ($one != false) {
29  $json = array(
30  0 => array(
31  'algorithm' => 0,
32  'maxURLs' => 1,
33  'sitesCriterions' => array(
34  'ORDER BY' => 'CDate DESC'
35  ),
36  'sitesList' => array(),
37  'urlUpdate' => null,
38  'urlsCriterions' => array(
39  'WHERE' => "`urlMd5`='$params'",
40  'LIMIT' => 1,
41  'ORDER BY' => 'CDate ASC'
42  )
43  )
44  );
45  } else {
46  $conditions = $this->getConditions($params);
47  $orderConditions = $this->getOrderConditions($params);
48  $json = array(
49  0 => array(
50  'algorithm' => 0,
51  'maxURLs' => $params['limit'],
52  'sitesCriterions' => array(
53  'WHERE' => "`Id`='{$params['siteId']}'",
54  ),
55  'sitesList' => array(),
56  'urlUpdate' => null,
57  'urlsCriterions' => array(
58  'WHERE' => "$conditions",
59  'ORDER BY' => $orderConditions
60  )
61  )
62  );
63  if (isset($params['limit'])) {
64  $from = $params['pN']*$params['limit']-$params['limit'];
65  $json[0]['maxURLs'] = $params['limit'];
66  $json[0]['urlsCriterions']['LIMIT'] = "$from, {$params['limit']}";
67 
68  }
69  }
70 
71  $json = json_encode($json);
72  Logger::log("Opertion ->" . $this->operation, false);
73  Logger::log("Request -> \n" . $json, true);
74  $path = Yii::app()->getBasePath() . '/json_temp/';
75  $file = fopen($path . $userId . '_request.json', 'w');
76  fwrite($file, $json);
77  }
78 
79  public function getOrderConditions($params)
80  {
81  $orderByConditions = '';
82  if ($params['sortBy'] == '') {
83  $orderByConditions .= 'UDate';
84  } else {
85  $orderByConditions .= $params['sortBy'];
86  }
87  if ($params['sortDirection'] == '') {
88  $orderByConditions .= ' DESC';
89  } else {
90  $orderByConditions .= ' ' . $params['sortDirection'];
91  }
92  return $orderByConditions;
93  }
94 
95  public function getConditions($form)
96  {
97  $conditions = '';
98  if ($form['status'] == '') {
99  $conditions .= "`Status`>=0";
100  }
101  foreach ($form as $name => $value) {
102  if (trim($value) != '') {
103  switch ($name) {
104  case 'status':
105  $conditions .= "`Status`=$value";
106  break;
107  case 'resourceURL':
108  $conditions .= " AND `URL` LIKE '" . trim($value) . "%'";
109  break;
110  case 'resourceId':
111  $conditions .= " AND `URLMd5`='" . trim($value) . "'";
112  break;
113  case 'contentType':
114  $conditions .= " AND `ContentType`='" . trim($value) . "'";
115  break;
116  case 'state':
117  $conditions .= " AND `State`='" . trim($value) . "'";
118  break;
119  case 'type':
120  $conditions .= " AND `Type`='" . trim($value) . "'";
121  break;
122  case 'parentUrl':
123  $conditions .= " AND `ParentMd5`='" . md5(trim($value)) . "'";
124  break;
125  case 'errorMask':
126  $conditions .= " AND `ErrorMask`='" . trim($value) . "'";
127  break;
128  case 'tagsMask':
129  $conditions .= " AND `TagsMask`&" . trim($value);
130  break;
131  case 'tagsCount':
132  $conditions .= " AND `TagsCount`='" . trim($value) . "'";
133  break;
134  case 'httpCode':
135  $conditions .= " AND `HttpCode`='" . trim($value) . "'";
136  break;
137  case 'errorMask':
138  $conditions .= " AND `ErrorMask`='" . trim($value) . "'";
139  break;
140  case 'tcDateFrom':
141  $conditions .= " AND `TcDate`>='" . $form['tcDateFrom'] . ' ' . $form['tcTimeFrom']. "'";
142  break;
143  case 'tcDateTo':
144  $conditions .= " AND `TcDate` <='" . $form['tcDateTo'] . ' ' . $form['tcTimeTo'] . "'";
145  break;
146  case 'cDateFrom':
147  $conditions .= " AND `CDate`>='" . $form['cDateFrom'] . ' ' . $form['cTimeFrom']. "'";
148  break;
149  case 'cDateTo':
150  $conditions .= " AND `CDate` <='" . $form['cDateTo'] . ' ' . $form['cTimeTo'] . "'";
151  break;
152  case 'pDateFrom':
153  $conditions .= " AND `PDate`>='" . $form['pDateFrom'] . ' ' . $form['pTimeFrom']. "'";
154  break;
155  case 'pDateTo':
156  $conditions .= " AND `PDate` <='" . $form['pDateTo'] . ' ' . $form['pTimeTo'] . "'";
157  break;
158  case 'depthFrom':
159  $conditions .= " AND `Depth`>='" . $form['depthFrom'] . "'";
160  break;
161  case 'depthTo':
162  $conditions .= " AND `Depth`<='" . $form['depthTo'] . "'";
163  break;
164  case 'onlyRoot':
165  $conditions .= " AND `parentMd5` = ''";
166  break;
167 
168  default:
169  break;
170  }
171  }
172  }
173  return $conditions;
174  }
175 
176  public function sendRequest($userId)
177  {
178  $api = Yii::app()->params['api'];
179  $path = Yii::app()->getBasePath() . '/shell/';
180  $pathJson = Yii::app()->getBasePath() . '/json_temp/';
181  $cmd = "sh " . $path . "url_fetch.sh $api $pathJson $userId";
182  $json = shell_exec($cmd);
183  $file = fopen($pathJson . $userId . '_response.json', 'w');
184  fwrite($file, $json);
185  fclose($file);
186  }
187 
188  public function getResponse($userId)
189  {
190  $path = Yii::app()->getBasePath() . '/json_temp/';
191  return file_get_contents($path . $userId . '_response.json');
192  }
193 
194  public function getSingleData($userId, $json, $hl = true)
195  {
196  $toReturn = array();
197  $data = array();
198  $dataProvider = CJSON::decode($json);
199  $data = $dataProvider["itemsList"][0]["itemObject"];
200  if (empty($data)) {
201  $id = Yii::app()->getRequest()->getParam('urlId');
202  throw new CHttpException('404', "Resource with ID<br>$id<br>was not found...");
203  }
204  $toReturn['manError']['isError'] = false;
205  $toReturn[] = $data;
206  foreach ($data[0] as $i => $value) {
207  if ($value === '') {
208  $data[0][$i] = '<div class="none" title="&quot;' . $i
209  . '&quot;: &quot;&quot;,"><span title="">none</span></div>';
210  }
211  if ($value === null) {
212  $data[0][$i] = '<div class="none" title="&quot;' . $i
213  . '&quot;: null,"><span title="">null</span></div>';
214  }
215  }
216  $data[0] = array_replace($data[0], $this->getCounters($userId, $data[0]['urlMd5']));
217  $data[0]['state_str'] = $this->getStrValues($userId, 0)['state'];
218  $data[0]['status_str'] = $this->getStrValues($userId, 0)['status'];
219  $data[0]['url_act'] = '<a target = "_blank" href="'.$data[0]['url'].'">'.$data[0]['url'].'</a>';
220  $toReturn[] = $data;
221  return $toReturn;
222  }
223 
224  public function getCounters($userId, $urlId)
225  {
226  $counters = array();
227  $counters['crawled'] = 0;
228  $counters['processed'] = 0;
229  $counters['linksI'] = 0;
230  $counters['linksE'] = 0;
231  $counters['tagsCount'] = 0;
232  $counters['freq'] = 0;
233  $counters['crawlingTime'] = 0;
234  $counters['processingTime'] = 0;
235  $counters['totalTime'] = 0;
236  $counters['size'] = 0;
237  $counters['mRate'] = 0;
238  $counters['mRateCNT'] = 0;
239  $json = CJSON::decode($this->getResponse($userId));
240  foreach ($json['itemsList'] as $item) {
241  foreach ($item['itemObject'] as $siteItem) {
242  if ($siteItem['urlMd5'] == $urlId) {
243  $counters['crawled'] += $siteItem['crawled'];
244  $counters['processed'] += $siteItem['processed'];
245  $counters['linksI'] += $siteItem['linksI'];
246  $counters['linksE'] += $siteItem['linksE'];
247  $counters['tagsCount'] += $siteItem['tagsCount'];
248  $counters['freq'] += $siteItem['freq'];
249  $counters['crawlingTime'] += $siteItem['crawlingTime'];
250  $counters['processingTime'] += $siteItem['processingTime'];
251  $counters['totalTime'] += $siteItem['totalTime'];
252  $counters['size'] += $siteItem['size'];
253  $counters['mRate'] += $siteItem['mRate'];
254  $counters['mRateCNT']++;
255  }
256  }
257  }
258  $counters['mRate'] = $counters['mRate'] / $counters['mRateCNT'];
259  return $counters;
260  }
261 
262  public function getStrValues($userId, $n)
263  {
264  $ret = array();
265  $json = $this->getResponse($userId);
266  $data = CJSON::decode($json);
267  $state = $data['itemsList'][0]['itemObject'][$n]['state'];
268  $status = $data['itemsList'][0]['itemObject'][$n]['status'];
269  switch ($state) {
270  case '0':
271  $ret['state'] = 'Enabled';
272  break;
273  case '1':
274  $ret['state'] = 'Disabled';
275  break;
276  case '2':
277  $ret['state'] = 'Error';
278  break;
279  }
280  switch ($status) {
281  case '0':
282  $ret['status'] = 'Undefined';
283  break;
284  case '1':
285  $ret['status'] = 'New';
286  break;
287  case '2':
288  $ret['status'] = 'Selected for crawling';
289  break;
290  case '3':
291  $ret['status'] = 'Crawling';
292  break;
293  case '4':
294  $ret['status'] = 'Crawled';
295  break;
296  case '5':
297  $ret['status'] = 'Selected to process';
298  break;
299  case '6':
300  $ret['status'] = 'Processing';
301  break;
302  case '7':
303  $ret['status'] = 'Processed';
304  break;
305  case '8':
306  $ret['status'] = 'Selected for crawling (incremental)';
307  break;
308  }
309  return $ret;
310  }
311 
312  public function getMultiData($userId, $json)
313  {
314  $data = array();
315  $dataProvider = CJSON::decode($json);
316  $items = $dataProvider["itemsList"][0]["itemObject"];
317  foreach ($items as $i => $urlItem) {
318  $data[$i] = array_replace($urlItem, $this->getCounters($userId, $urlItem['urlMd5']));
319  if (isset($data[$i])) {
320  $data[$i]['state_str'] = $this->getStrValues($userId, $i)['state'];
321  $data[$i]['status_str'] = $this->getStrValues($userId, $i)['status'];
322  }
323  }
324  $data['manError']['isError'] = false;
325  return $data;
326  }
327 
328  public function getLimits($userId)
329  {
330  $limitsProvider = array();
331  $json = $this->getResponse($userId);
332  $data = CJSON::decode($json);
333  $limitsProvider[] = array(
334  'limit_name' => 'Priority',
335  'limit_value' => $data['itemsList'][0]['itemObject'][0]['priority'],
336  'limit_name_f' => 'priority'
337  );
338  $limitsProvider[] = array(
339  'limit_name' => 'Max URLs from page',
340  'limit_value' => $data['itemsList'][0]['itemObject'][0]['maxURLsFromPage'],
341  'limit_name_f' => 'maxURLsFromPage'
342  );
343  $limitsProvider[] = array(
344  'limit_name' => 'Processing delay, ms',
345  'limit_value' => $data['itemsList'][0]['itemObject'][0]['processingDelay'],
346  'limit_name_f' => 'processingDelay'
347  );
348  $limitsProvider[] = array(
349  'limit_name' => 'Request delay, ms',
350  'limit_value' => $data['itemsList'][0]['itemObject'][0]['requestDelay'],
351  'limit_name_f' => 'requestDelay'
352  );
353  $limitsProvider[] = array(
354  'limit_name' => 'HTTP Timeout, ms',
355  'limit_value' => $data['itemsList'][0]['itemObject'][0]['httpTimeout'],
356  'limit_name_f' => 'httpTimeout'
357  );
358  return new CArrayDataProvider($limitsProvider, array(
359  'keyField' => 'limit_name',
360  'pagination' => false
361  ));
362  }
363 
364  public function getErrorsTypes($userId)
365  {
366  $eTypes = array();
367  $json = $this->getResponse($userId);
368  $data = CJSON::decode($json);
369  $mask = $data['itemsList'][0]['itemObject'][0]['errorMask'];
370  for ($power = 0; $power <= 64; $power++) {
371  $error = $mask & pow(2, $power);
372  if ($error != 0) {
373  $eTypes[] = $power;
374  }
375  }
376  $errors = Dictionary::getErrorsByMask($eTypes);
377  return new CArrayDataProvider($errors, array(
378  'keyField' => 'errorType',
379  'pagination' => false
380  ));
381  }
382 
383  public function getTagsTypes($userId)
384  {
385  $tTypes = array();
386  $json = $this->getResponse($userId);
387  $data = CJSON::decode($json);
388  $mask = $data['itemsList'][0]['itemObject'][0]['tagsMask'];
389  // $mask = 5555;
390  for ($power = 0; $power <= 64; $power++) {
391  $tag = $mask & pow(2, $power);
392  if ($tag != 0) {
393  $tTypes[] = $power;
394  }
395  }
396  $tags = Dictionary::getTagsByMask($tTypes);
397  return new CArrayDataProvider($tags, array(
398  'keyField' => 'tag',
399  'pagination' => false
400  ));
401  }
402 
403  public function getContentParams($data)
404  {
405  return array(
406  'siteId' => $data['siteId'],
407  'url' => $data['url'],
408  'urlMd5' => $data['urlMd5'],
409  );
410  }
411 
412  public static function getContents($userId)
413  {
414  $request = Yii::app()->request;
415  $json[] = array(
416  'contentTypeMask' => 4095,
417  'siteId' => $request->getParam("siteId"),
418  'url' => $request->getParam("url"),
419  'urlFetch' => null,
420  'urlMd5' => $request->getParam("urlMd5"),
421  );
422  $json = CJSON::encode($json);
423  $path = Yii::app()->getBasePath() . '/json_temp/';
424  $file = fopen($path . $userId . '_request_content.json', 'w');
425  fwrite($file, $json);
426  $api = Yii::app()->params['api'];
427  $path = Yii::app()->getBasePath() . '/shell/';
428  $pathFile = Yii::app()->getBasePath() . '/json_temp/' . $userId . '_request_content.json';
429  $cmd = "sh " . $path . "url_content.sh $api $pathFile";
430  $json = shell_exec($cmd);
431  $path = Yii::app()->getBasePath() . '/json_temp/';
432  $file = fopen($path . $userId . '_response_content.json', 'w+');
433  fwrite($file, $json);
434  fclose($file);
435  $response = file_get_contents($path . $userId . '_response_content.json');
436  // return $response;
437  $respDecoded = CJSON::decode($response);
438  if ($request->getParam("t") == 0) {
439  if(!isset($respDecoded['itemsList'][0]['itemObject'][0]['rawContents'][0])) {
440  $rawContent = 'No contents found...';
441  } else {
442  $rawContent = base64_decode($respDecoded['itemsList'][0]['itemObject'][0]['rawContents'][0]['buffer']);
443  }
444  $contentItem['type'] = 'raw';
445  $contentItem['contents'] = '<textarea id = "url-content">' . CHtml::encode($rawContent) . '</textarea>';
446  return $contentItem;
447  }
448  if(!isset($respDecoded['itemsList'][0]['itemObject'][0]['processedContents'][0])) {
449  $proContent = '{"Sorry...": "...no contents found"}';
450  $contentItem['type'] = 'processed';
451  $contentItem['contents'] = $proContent;
452  } else {
453  $proContent = base64_decode($respDecoded['itemsList'][0]['itemObject'][0]['processedContents'][0]['buffer']);
454  $contentDecoded = CJSON::decode($proContent);
455  $contentItem['type'] = 'processed';
456  $contentItem['contents'] = $contentDecoded;
457  $contentItem['contents'] = CJSON::encode($contentItem['contents']);
458  }
459  return $contentItem;
460  }
461  public function getHistory($userId = 1)
462  {
463  $nodes = array();
464 // $request = Yii::app()->request;
465 // $json[] = array(
466 // 'contentTypeMask' => 4095,
467 // 'siteId' => $request->getParam("siteId"),
468 // 'url' => $request->getParam("url"),
469 // 'urlFetch' => null,
470 // 'urlMd5' => $request->getParam("urlMd5"),
471 // );
472 // $json = CJSON::encode($json);
473 // $path = Yii::app()->getBasePath() . '/json_temp/';
474 // $request = tempnam($path, '');
475 // $file = fopen($request, 'w');
476 // fwrite($file, $json);
477 // $api = Yii::app()->params['api'];
478 // $path = Yii::app()->getBasePath() . '/shell/';
479 // $cmd = "sh " . $path . "url_history.sh $api $request";
480 // $json = shell_exec($cmd);
481 // unlink($request);
482 // $path = Yii::app()->getBasePath() . '/json_temp/';
483 // $response = tempnam($path, '');
484 // $file = fopen($response', 'w+');
485 // fwrite($file, $json);
486 // fclose($file);
487 // $response = file_get_contents($response);
488 // $history = CJSON::decode($response);
489 // unlink($response);
490  $history = array(
491  array(
492  "errorCode"=> 0,
493  "errorMessage"=> "",
494  "host"=> "HOST0",
495  "id"=> 1434090582,
496  "itemObject"=> array(
497  array(
498  "someURLMd5",
499  20,
500  '{
501  "criterions": null,
502  "delayedType": 1,
503  "reason": 0,
504  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
505  "url": "701ccc5c1c589041d31d13dae8dce90d",
506  "urlType": 1
507 }',
508  "2015-06-26 17:46:44",
509  "2015-06-26 17:46:44",
510  ),
511  array(
512  "someURLMd5",
513  21,
514  '{
515  "criterions": null,
516  "delayedType": 1,
517  "reason": 0,
518  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
519  "url": "701ccc5c1c589041d31d13dae8dce90d",
520  "urlType": 1
521 }',
522  "2015-06-26 17:46:44",
523  "2015-06-26 17:46:44",
524  ),
525  array(
526  "someURLMd5",
527  22,
528  '{
529  "criterions": null,
530  "delayedType": 1,
531  "reason": 0,
532  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
533  "url": "701ccc5c1c589041d31d13dae8dce90d",
534  "urlType": 1
535 }',
536  "2015-06-26 17:46:44",
537  "2015-06-26 17:46:44",
538  ),
539  array(
540  "someURLMd5",
541  23,
542  '{
543  "criterions": null,
544  "delayedType": 1,
545  "reason": 0,
546  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
547  "url": "701ccc5c1c589041d31d13dae8dce90d",
548  "urlType": 1
549 }',
550  "2015-06-26 17:46:44",
551  "2015-06-26 17:46:44",
552  ),
553  array(
554  "someURLMd5",
555  24,
556  '{
557  "criterions": null,
558  "delayedType": 1,
559  "reason": 0,
560  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
561  "url": "701ccc5c1c589041d31d13dae8dce90d",
562  "urlType": 1
563 }',
564  "2015-06-26 17:46:44",
565  "2015-06-26 17:46:44",
566  ),
567  array(
568  "someURLMd5",
569  25,
570  '{
571  "criterions": null,
572  "delayedType": 1,
573  "reason": 0,
574  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
575  "url": "701ccc5c1c589041d31d13dae8dce90d",
576  "urlType": 1
577 }',
578  "2015-06-26 17:46:44",
579  "2015-06-26 17:46:44",
580  ),
581  ),
582  "node"=> "NODE0",
583  "port"=> "PORT0",
584  "time"=> 0
585  ),
586  array(
587  "errorCode"=> 0,
588  "errorMessage"=> "",
589  "host"=> "HOST1",
590  "id"=> 1434090583,
591  "itemObject"=> array(
592  array(
593  "someURLMd5",
594  2,
595  '{
596  "criterions": null,
597  "delayedType": 1,
598  "reason": 0,
599  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
600  "url": "701ccc5c1c589041d31d13dae8dce90d",
601  "urlType": 1
602 }',
603  "2015-06-26 17:46:44",
604  "2015-06-26 17:46:44",
605  ),
606  array(
607  "someURLMd5",
608  3,
609  '{
610  "criterions": null,
611  "delayedType": 1,
612  "reason": 0,
613  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
614  "url": "701ccc5c1c589041d31d13dae8dce90d",
615  "urlType": 1
616 }',
617  "2015-06-26 17:46:44",
618  "2015-06-26 17:46:44",
619  ),
620  array(
621  "someURLMd5",
622  5,
623  '{
624  "criterions": null,
625  "delayedType": 1,
626  "reason": 0,
627  "siteId": "b85ab149a528bd0a024fa0f43e80b5fc",
628  "url": "701ccc5c1c589041d31d13dae8dce90d",
629  "urlType": 1
630 }',
631  "2015-06-26 17:46:44",
632  "2015-06-26 17:46:44",
633  ),
634  ),
635  "node"=> "NODE1",
636  "port"=> "PORT1",
637  "time"=> 0
638  ),
639  );
640  foreach($history as $node) {
641  foreach ($node['itemObject'] as $i => $operation) {
642  foreach ($node['itemObject'][$i] as $k => $v) {
643  $node['itemObject'][$i]["0".$k] = $v;
644  unset($node['itemObject'][$i][$k]);
645  }
646  $node['itemObject'][$i]['OpText'] = $this->getOpByCode($operation[1]);
647  $Object = CJSON::decode($operation[2]);
648  if (isset($Object['reason']) && $operation[1] == 21) {
649  $node['itemObject'][$i]['Reason'] = $this->getReasonByCode($Object['reason']);
650  } else {
651  $node['itemObject'][$i]['Reason'] = '';
652  }
653  }
654  $nodes[$node['node']] = new CArrayDataProvider($node['itemObject'], array(
655  'keyField' => '00',
656  'pagination' => false
657  ));
658  }
659  return $nodes;
660  }
661  private function getOpByCode($opCode)
662  {
663  /* URL:
664  20 - Insert,
665  21 - Delete,
666  22 - Update,
667  23 - Cleanup,
668  24 - Aging,
669  25 - Content;
670  Status:
671  1 - New,
672  2 - Selected to crawl,
673  3 - Crawling,
674  4 - Crawled,
675  5 - Selected to process,
676  6 - Processing,
677  7 - Processed
678  */
679  switch ($opCode) {
680  case 20:
681  return "URL: Insert";
682  break;
683  case 21:
684  return "URL: Delete";
685  break;
686  case 22:
687  return "URL: Update URL";
688  break;
689  case 23:
690  return "URL: Cleanup URL";
691  break;
692  case 24:
693  return "URL: Aging";
694  break;
695  case 25:
696  return "URL: Content";
697  break;
698  case 1:
699  return "Status: New";
700  break;
701  case 2:
702  return "Status: Selected to crawl";
703  break;
704  case 3:
705  return "Status: Crawling";
706  break;
707  case 4:
708  return "Status: Crawled";
709  break;
710  case 5:
711  return "Status: Selected to process";
712  break;
713  case 6:
714  return "Status: Processing";
715  break;
716  case 7:
717  return "Status: Processed";
718  break;
719 
720  }
721  }
722  private function getReasonByCode($reason)
723  {
724  /*
725  REASON_USER_REQUEST = 0
726  REASON_AGING = 1
727  REASON_SITE_LIMITS = 2
728  REASON_SELECT_TO_CRAWL_TTL = 3
729  REASON_SELECT_TO_PROCESS_TTL = 4
730  REASON_RECRAWL = 5
731  REASON_CRAWLER_AUTOREMOVE = 6
732  REASON_SITE_UPDATE_ROOT_URLS = 7
733  REASON_RT_FINALIZER = 10
734  REASON_PROCESSOR_DUPLICATE = 11
735  */
736  switch ($reason) {
737  case 0:
738  return "REASON_USER_REQUEST ";
739  break;
740  case 1:
741  return "REASON_AGING";
742  break;
743  case 2:
744  return "REASON_SITE_LIMITS";
745  break;
746  case 3:
747  return "REASON_SELECT_TO_CRAWL_TTL";
748  break;
749  case 4:
750  return "REASON_SELECT_TO_PROCESS_TTL";
751  break;
752  case 5:
753  return "REASON_RECRAWL";
754  break;
755  case 6:
756  return "REASON_CRAWLER_AUTOREMOVE";
757  break;
758  case 7:
759  return "REASON_SITE_UPDATE_ROOT_URLS";
760  break;
761  case 10:
762  return "REASON_RT_FINALIZER";
763  break;
764  case 11:
765  return "REASON_PROCESSOR_DUPLICATE";
766  break;
767 
768  }
769  }
770 }