HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
SiteRecrawl.php
Go to the documentation of this file.
1 <?php
2 
4 {
5  protected $operation = 'Re-crawl';
6  protected $opLog = 'SITE_RECRAWL (Based on SITE_UPDATE)';
7 
8  public function recrawl()
9  {
10  $siteId = Yii::app()->getRequest()->getPost('id');
11  $iterations = Yii::app()->getRequest()->getPost('iterations');
12  $cleanup = Yii::app()->getRequest()->getPost('cleanup');
13  if (isset($cleanup)) {
14  $command = new SiteCleanup;
15  $command->cleanupSiteInfo($siteId);
16  unset($command);
17  }
18  $json = array(
19  "cDate" => null,
20  "description" => null,
21  "errorMask" => null,
22  "errors" => null,
23  "filters" => null,
24  "httpTimeout" => null,
25  "id" => $siteId,
26  "iterations" => null,
27  "maxErrors" => null,
28  "maxResourceSize" => null,
29  "maxResources" => null,
30  "maxURLs" => null,
31  "priority" => null,
32  "properties" => null,
33  "requestDelay" => null,
34  "resources" => null,
35  "state" => 1,
36  "tcDate" => null,
37  "uDate" => null,
38  "updateType" => 0,
39  "urlType" => null,
40  "urls" => null,
41  "contents" => null,
42  "processingDelay" => null,
43  "size" => null,
44  "avgSpeed" => null,
45  "avgSpeedCounter" => null,
46  "maxURLsFromPage" => null,
47  "criterions" => null,
48  "userId" => null,
49  "recrawlPeriod" => null,
50  "recrawlDate" => 'NOW()',
51  "collectedURLs" => null,
52  "fetchType" => null
53  );
54  Logger::log("Operation ->" . $this->opLog, false);
55  $json = CJSON::encode($json);
56  Logger::log("Request ->\n" . $json, true);
57  $reqFile = tempnam(Yii::app()->getBasePath() . '/json_temp', '');
58  $request = fopen($reqFile, "w");
59  fwrite($request, $json);
60  fclose($request);
61  $this->commandRecrawl($reqFile);
62  unlink($reqFile);
63  return true;
64  }
65 
66  public function commandRecrawl($reqFile)
67  {
68  $api = Yii::app()->params['api'];
69  $path = Yii::app()->getBasePath() . '/shell/';
70  $cmd = "sh " . $path . "rnd_site_update.sh $api $reqFile";
71  $json = shell_exec($cmd);
72  $error = Errors::isError($json);
73  if ($error !== 0) {
74  Yii::app()->user->setFlash('error1', $this->operation . ' WARNING: ' . $error);
75  } else {
76  Yii::app()->user->setFlash('success1', $this->operation . ': SUCCESS');
77  }
78  Logger::log("Response ->\n" . $json);
79  return true;
80  }
81 }