HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UrlCleanup.php
Go to the documentation of this file.
1 <?php
2 
7 class UrlCleanup
8 {
9  protected $operation = "Cleanup";
10  protected $opLog = "URL_CLEANUP";
11  protected $dType = 1;
12 
26  public function cleanupUrlInfo($siteId, $url, $urlType, $state, $status)
27  {// Create request JSON
28  $json = array(
29  array(
30  "siteId" => $siteId,
31  "delayedType" => $this->dType,
32  "url" => $url,
33  "urlType" => $urlType,
34  "state" => $state,
35  "status" => $status,
36  "criterions" => array(
37  "LIMIT" => 1,
38  "WHERE" => "`URL`=$url",
39  "ORDER BY" => "URL"
40  ),
41  )
42  );
43  Logger::log("Opertion ->" . $this->opLog, false);
44  $json = CJSON::encode($json);
45  Logger::log("Request ->\n" . $json, true);
46 // Create temporary file
47  $reqFile = tempnam(Yii::app()->getBasePath() . '/json_temp', '');
48  $request = fopen($reqFile, "w");
49  fwrite($request, $json);
50  fclose($request);
51  $this->commandCleanup($reqFile);
52 // Remove temporary file
53  unlink($reqFile);
54  }
55 
64  public function commandCleanup($reqFile)
65  {
66 // Path to this application
67  $api = Yii::app()->params['api'];
68 // Path to folder with shell scripts
69  $path = Yii::app()->getBasePath() . '/shell/';
70  $cmd = "sh " . $path . "url_cleanup.sh $api $reqFile";
71 //Execute bash script, and get response JSON
72  $json = shell_exec($cmd);
73  $error = Errors::isError($json);
74  if ($error !== 0) {
75  Yii::app()->user->setFlash('error1', $this->operation . ' ERROR: ' . $error);
76  } else {
77  Yii::app()->user->setFlash('success1', $this->operation . ': SUCCESS');
78  }
79  Logger::log("Response ->\n" . $json);
80  }
81 }