HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
SiteCleanup.php
Go to the documentation of this file.
1 <?php
2 
8 {
9  protected $operation = "Cleanup";
10  protected $opLog = "SITE_CLEANUP";
11 
21  public function cleanupSiteInfo($siteId, $taskType = 1)
22  {
23  Logger::log('CLEANUP: START');
24  $susp = Yii::app()->getRequest()->getPost('suspend');
25  $historyCleanupParam = Yii::app()->getRequest()->getPost('history');
26  $state = Yii::app()->getRequest()->getPost('state');
27  // If checked "Suspend site before cleanup"
28  // the state of current site will be changed to 3
29  if ($susp != null)
30  $this->suspendRunSite($siteId, 3);
31  if ($historyCleanupParam != null)
32  $historyClianup = 1;
33  // Create request JSON
34  $json = array(
35  "id" => $siteId,
36  "taskType" => $taskType,
37  "delayedType" => 0,
38  "saveRootURLs" => 1,
39  "moveURLs" => 0,
40  "state" => $state,
41 // "historyCleanupParam" => $historyCleanup,
42  );
43  Logger::log("Opertion ->" . $this->opLog, false);
44  $json = CJSON::encode($json);
45  Logger::log("Request ->\n" . $json, true);
46  // Logger::log('Request->'.$json, true);
47  // Create temporary file
48  $reqFile = tempnam(Yii::app()->getBasePath() . '/json_temp', '');
49  $request = fopen($reqFile, "w");
50  fwrite($request, $json);
51  fclose($request);
52  $this->commandCleanup($reqFile);
53  // Remove temporary file
54  unlink($reqFile);
55 // if ($susp != null)
56 // $this->suspendRunSite($siteId, 1);
57  }
58 
68  public function suspendRunSite($siteId, $state)
69  {
70  if ($state == 3) {
71  $this->operation = "Suspend site";
72  } elseif ($state == 1) {
73  $this->operation = "Run site";
74  }
75  // Create request JSON
76  $json = array(
77  "cDate" => null,
78  "description" => null,
79  "errorMask" => null,
80  "errors" => null,
81  "filters" => null,
82  "httpTimeout" => null,
83  "id" => $siteId,
84  "iterations" => null,
85  "maxErrors" => null,
86  "maxResourceSize" => null,
87  "maxResources" => null,
88  "maxURLs" => null,
89  "priority" => null,
90  "properties" => null,
91  "requestDelay" => null,
92  "resources" => null,
93  "state" => $state,
94  "tcDate" => null,
95  "uDate" => null,
96  "updateType" => null,
97  "urlType" => null,
98  "urls" => null,
99  "contents" => null,
100  "processingDelay" => null,
101  "size" => null,
102  "avgSpeed" => null,
103  "avgSpeedCounter" => null,
104  "maxURLsFromPage" => null,
105  "criterions" => array(
106  "WHERE" => "`State`<>$state"
107  ),
108  "userId" => null,
109  "recrawlPeriod" => null,
110  "recrawlDate" => null,
111  "collectedURLs" => null,
112  "fetchType" => null
113  );
114  Logger::log("Operation -> SITE_UPDATE", false);
115  Logger::log("Request ->\n" . print_r($json, true), false);
116  $json = CJSON::encode($json);
117  // Create temporary file
118  $reqFile = tempnam(Yii::app()->getBasePath() . '/json_temp', '');
119  $request = fopen($reqFile, "w");
120  fwrite($request, $json);
121  fclose($request);
122  // Path to this application
123  $api = Yii::app()->params['api'];
124  // Path to folder with shell scripts
125  $path = Yii::app()->getBasePath() . '/shell/';
126  $cmd = "sh " . $path . "rnd_site_update.sh $api $reqFile";
127  //Execute bash script, and get response JSON
128  $json = shell_exec($cmd);
129  $error = Errors::isError($json);
130  if ($error !== 0) {
131  Yii::app()->user->setFlash('error' . (string)$state, $this->operation . ' ERROR: ' . $error);
132  } else {
133  Yii::app()->user->setFlash('success' . (string)$state, $this->operation . ': SUCCESS');
134  }
135  Logger::log("Response ->\n" . $json);
136  // Remove temporary file
137  unlink($reqFile);
138  }
139 
148  public function commandCleanup($reqFile)
149  {
150  $this->operation = "Cleanup";
151  // Path to this application
152  $api = Yii::app()->params['api'];
153  // Path to folder with shell scripts
154  $path = Yii::app()->getBasePath() . '/shell/';
155  $cmd = "sh " . $path . "rnd_site_cleanup.sh $api $reqFile";
156  //Execute bash script, and get response JSON
157  $json = shell_exec($cmd);
158  $error = Errors::isError($json);
159  if ($error !== 0) {
160  Yii::app()->user->setFlash('error2', $this->operation . ' ERROR: ' . $error);
161  } else {
162  Yii::app()->user->setFlash('success2', $this->operation . ': SUCCESS');
163  }
164  Logger::log("Response ->\n" . $json);
165  return true;
166  }
167 }