HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UrlUpdate.php
Go to the documentation of this file.
1 <?php
2 
4 {
5  protected $operation = 'Update';
6  protected $opLog = 'URL_UPDATE';
7 
8  public function updateUrlInfo()
9  {
10  if (!$this->validateSite()) {
11  return false;
12  }
13  $userId = Yii::app()->user->id;
14 
15  $json = $this->getJson();
16 
17  Logger::log("Opertion ->" . $this->opLog, false);
18  foreach ($json[0] as $key => $value) {
19  if ($value == '') {
20  $value = null;
21  $json[0][$key] = $value;
22  }
23  }
24  $json = CJSON::encode($json);
25  Logger::log("Request ->\n" . $json, true);
26  $reqFile = tempnam(Yii::app()->getBasePath() . '/json_temp', '');
27  $request = fopen($reqFile, "w");
28  fwrite($request, $json);
29  fclose($request);
30  $response = $this->commandUpdate($reqFile);
31  $error = Errors::isError($response);
32  if ($error !== 0) {
33  Yii::app()->user->setFlash('error1', $this->operation . ' ERROR: ' . $error);
34  } else {
35  Yii::app()->user->setFlash('success1', $this->operation . ': SUCCESS');
36  }
37  unlink($reqFile);
38  $UsersSitesRights = new UsersSitesRights();
39  $UsersSitesRights->setRightsSingleRecord(
40  array(
41  'userId' => $userId,
42  ),
43  true
44  );
45 
46  return $response;
47  }
48 
49  public function getJson()
50  {
51  $request = Yii::app()->getRequest();
52  $json[] = array(
53  'CDate' => null,
54  'UDate' => 'NOW()',
55  'batchId' => null,
56  'charset' => $request->getPost('charset'),
57  'contentMask' => null,
58  'contentType' => $request->getPost('contentType'),
59  'contentURLMd5' => null,
60  'crawled' => null,
61  'crawlingTime' => null,
62  'depth' => null,
63  'eTag' => null,
64  'errorMask' => null,
65  'freq' => null,
66  'httpCode' => null,
67  'httpMethod' => $request->getPost('httpMethod'),
68  'httpTimeout' => $request->getPost('httpTimeout'),
69  'lastModified' => null,
70  'linksE' => null,
71  'linksI' => null,
72  'mRate' => null,
73  'mRateCounter' => null,
74  'maxURLsFromPage' => $request->getPost('maxURLsFromPage'),
75  'pDate' => null,
76  'parentMd5' => null,
77  'priority' => $request->getPost('priority'),
78  'processed' => null,
79  'processingDelay' => $request->getPost('processingDelay'),
80  'processingTime' => null,
81  'rawContentMd5' => null,
82  'requestDelay' => $request->getPost('requestDelay'),
83  'siteId' => $request->getPost('siteId'),
84  'siteSelect' => null,
85  'size' => null,
86  'state' => $request->getPost('state'),
87  'status' => $request->getPost('status'),
88  'tagsCount' => null,
89  'tagsMask' => null,
90  'tcDate' => null,
91  'totalTime' => null,
92  'type' => $request->getPost('type'),
93  'url' => $request->getPost('url'),
94  'urlMd5' => $request->getPost('urlMd5'),
95  'urlUpdate' => 1,
96  );
97  return $json;
98  }
99 
100  public function commandUpdate($reqFile)
101  {
102  $api = Yii::app()->params['api'];
103  $path = Yii::app()->getBasePath() . '/shell/';
104  $cmd = "sh " . $path . "url_update.sh $api $reqFile";
105  $json = shell_exec($cmd);
106  Logger::log("Response ->\n" . $json);
107  return $json;
108  }
109 }