XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
autoinstall.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
4 require_once(_XE_PATH_ . 'modules/autoinstall/autoinstall.lib.php');
5 
12 {
13 
17  function init()
18  {
19 
20  }
21 
29  function checkFileCheckSum($file, $checksum)
30  {
31  $local_checksum = md5_file(FileHandler::getRealPath($file));
32  return ($local_checksum === $checksum);
33  }
34 
42  {
43  FileHandler::removeDir($obj->download_path);
44  }
45 
52  {
53  $this->_updateinfo();
54  $this->setMessage("success_updated", 'update');
55  $this->setRedirectUrl(Context::get('error_return_url'));
56  }
57 
63  function _updateinfo()
64  {
65  $oModel = getModel('autoinstall');
66  $item = $oModel->getLatestPackage();
67  if($item)
68  {
69  $params["updatedate"] = $item->updatedate;
70  }
71 
72  $params["act"] = "getResourceapiUpdate";
73  $body = XmlGenerater::generate($params);
74  $buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
75  $xml = new XmlParser();
76  $xmlDoc = $xml->parse($buff);
77  $this->updateCategory($xmlDoc);
78  $this->updatePackages($xmlDoc);
79  $this->checkInstalled();
80 
82  $output = $oAdminController->cleanFavorite();
83  }
84 
90  function checkInstalled()
91  {
92  executeQuery("autoinstall.deleteInstalledPackage");
93  $oModel = getModel('autoinstall');
94  $packages = $oModel->getPackages();
95  foreach($packages as $package)
96  {
97  $real_path = FileHandler::getRealPath($package->path);
98  if(!file_exists($real_path))
99  {
100  continue;
101  }
102 
103  $type = $oModel->getTypeFromPath($package->path);
104  if($type == "core")
105  {
106  $version = __XE_VERSION__;
107  }
108  else
109  {
110  $config_file = NULL;
111  switch($type)
112  {
113  case "m.layout":
114  $type = "layout";
115  case "module":
116  case "addon":
117  case "layout":
118  case "widget":
119  $config_file = "/conf/info.xml";
120  break;
121  case "component":
122  $config_file = "/info.xml";
123  break;
124  case "style":
125  case "m.skin":
126  $type = "skin";
127  case "skin":
128  case "widgetstyle":
129  $config_file = "/skin.xml";
130  break;
131  case "drcomponent":
132  $config_file = "/info.xml";
133  $type = "component";
134  break;
135  case "theme":
136  $config_file = "/conf/info.xml";
137  $type = "theme";
138  break;
139  }
140 
141  if(!$config_file)
142  {
143  continue;
144  }
145 
146  $xml = new XmlParser();
147  $xmlDoc = $xml->loadXmlFile($real_path . $config_file);
148 
149  if(!$xmlDoc)
150  {
151  continue;
152  }
153 
154  $version = $xmlDoc->{$type}->version->body;
155  }
156 
157  $args = new stdClass();
158  $args->package_srl = $package->package_srl;
159  $args->version = $package->version;
160  $args->current_version = $version;
161  if(version_compare($args->version, $args->current_version, ">"))
162  {
163  $args->need_update = "Y";
164  }
165  else
166  {
167  $args->need_update = "N";
168  }
169 
170  $output = executeQuery("autoinstall.insertInstalledPackage", $args);
171  }
172  }
173 
180  {
181  @set_time_limit(0);
182  $package_srls = Context::get('package_srl');
183  $oModel = getModel('autoinstall');
184  $oAdminModel = getAdminModel('autoinstall');
185  $packages = explode(',', $package_srls);
186  $ftp_info = Context::getFTPInfo();
187  if(!$_SESSION['ftp_password'])
188  {
189  $ftp_password = Context::get('ftp_password');
190  }
191  else
192  {
193  $ftp_password = $_SESSION['ftp_password'];
194  }
195 
196  $isSftpSupported = function_exists(ssh2_sftp);
197  foreach($packages as $package_srl)
198  {
199  $package = $oModel->getPackage($package_srl);
200  if($oAdminModel->checkUseDirectModuleInstall($package)->toBool())
201  {
202  $oModuleInstaller = new DirectModuleInstaller($package);
203  }
204  else if($ftp_info->sftp && $ftp_info->sftp == 'Y' && $isSftpSupported)
205  {
206  $oModuleInstaller = new SFTPModuleInstaller($package);
207  }
208  else if(function_exists(ftp_connect))
209  {
210  $oModuleInstaller = new PHPFTPModuleInstaller($package);
211  }
212  else
213  {
214  $oModuleInstaller = new FTPModuleInstaller($package);
215  }
216 
217  $oModuleInstaller->setServerUrl(_XE_DOWNLOAD_SERVER_);
218  $oModuleInstaller->setPassword($ftp_password);
219  $output = $oModuleInstaller->install();
220  if(!$output->toBool())
221  {
222  return $output;
223  }
224  }
225 
226  $this->_updateinfo();
227 
228  $this->setMessage('success_installed', 'update');
229 
230  if(Context::get('return_url'))
231  {
232  $this->setRedirectUrl(Context::get('return_url'));
233  }
234  else
235  {
236  $this->setRedirectUrl(preg_replace('/act=[^&]*/', 'act=dispAutoinstallAdminIndex', Context::get('error_return_url')));
237  }
238  }
239 
246  function updatePackages(&$xmlDoc)
247  {
248  $oModel = getModel('autoinstall');
249  if(!$xmlDoc->response->packages->item)
250  {
251  return;
252  }
253  if(!is_array($xmlDoc->response->packages->item))
254  {
255  $xmlDoc->response->packages->item = array($xmlDoc->response->packages->item);
256  }
257  $targets = array('package_srl', 'updatedate', 'latest_item_srl', 'path', 'version', 'category_srl', 'have_instance');
258  foreach($xmlDoc->response->packages->item as $item)
259  {
260  $args = new stdClass();
261  foreach($targets as $target)
262  {
263  $args->{$target} = $item->{$target}->body;
264  }
265  if($oModel->getPackage($args->package_srl))
266  {
267  $output = executeQuery("autoinstall.updatePackage", $args);
268  }
269  else
270  {
271  $output = executeQuery("autoinstall.insertPackage", $args);
272  if(!$output->toBool())
273  {
274  $output = executeQuery("autoinstall.deletePackage", $args);
275  $output = executeQuery("autoinstall.insertPackage", $args);
276  }
277  }
278  }
279  }
280 
287  function updateCategory(&$xmlDoc)
288  {
289  executeQuery("autoinstall.deleteCategory");
290  $oModel = getModel('autoinstall');
291  if(!is_array($xmlDoc->response->categorylist->item))
292  {
293  $xmlDoc->response->categorylist->item = array($xmlDoc->response->categorylist->item);
294  }
295  $list_order = 0;
296  foreach($xmlDoc->response->categorylist->item as $item)
297  {
298  $args = new stdClass();
299  $args->category_srl = $item->category_srl->body;
300  $args->parent_srl = $item->parent_srl->body;
301  $args->title = $item->title->body;
302  $args->list_order = $list_order++;
303  $output = executeQuery("autoinstall.insertCategory", $args);
304  }
305  }
306 
313  {
314  $package_srl = Context::get('package_srl');
315 
316  $output = $this->uninstallPackageByPackageSrl($package_srl);
317  if($output->toBool()==FALSE)
318  {
319  return $output;
320  }
321 
322  if(Context::get('return_url'))
323  {
324  $this->setRedirectUrl(Context::get('return_url'));
325  }
326  else
327  {
328  $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAutoinstallAdminInstalledPackages'));
329  }
330  }
331 
337  function uninstallPackageByPackageSrl($package_srl)
338  {
339  $oModel = getModel('autoinstall');
340  $package = $oModel->getPackage($package_srl);
341 
342  return $this->_uninstallPackage($package);
343  }
344 
350  function uninstallPackageByPath($path)
351  {
352  $package->path = $path;
353  return $this->_uninstallPackage($package);
354  }
355 
356  private function _uninstallPackage($package)
357  {
358  $path = $package->path;
359 
360  $oAdminModel = getAdminModel('autoinstall');
361 
362  if(!$_SESSION['ftp_password'])
363  {
364  $ftp_password = Context::get('ftp_password');
365  }
366  else
367  {
368  $ftp_password = $_SESSION['ftp_password'];
369  }
370  $ftp_info = Context::getFTPInfo();
371 
372  $isSftpSupported = function_exists(ssh2_sftp);
373  if($oAdminModel->checkUseDirectModuleInstall($package)->toBool())
374  {
375  $oModuleInstaller = new DirectModuleInstaller($package);
376  }
377  else if($ftp_info->sftp && $ftp_info->sftp == 'Y' && $isSftpSupported)
378  {
379  $oModuleInstaller = new SFTPModuleInstaller($package);
380  }
381  else if(function_exists('ftp_connect'))
382  {
383  $oModuleInstaller = new PHPFTPModuleInstaller($package);
384  }
385  else
386  {
387  $oModuleInstaller = new FTPModuleInstaller($package);
388  }
389 
390  $oModuleInstaller->setServerUrl(_XE_DOWNLOAD_SERVER_);
391 
392  $oModuleInstaller->setPassword($ftp_password);
393  $output = $oModuleInstaller->uninstall();
394  if(!$output->toBool())
395  {
396  return $output;
397  }
398 
399  $this->_updateinfo();
400 
401  $this->setMessage('success_deleted', 'update');
402 
403  return new BaseObject();
404  }
405 
406 }
407 /* End of file autoinstall.admin.controller.php */
408 /* Location: ./modules/autoinstall/autoinstall.admin.controller.php */
setMessage($message= 'success', $type=NULL)
const __XE_VERSION__
Definition: config.inc.php:32
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
getNotEncodedUrl()
Definition: func.inc.php:316
getRemoteResource($url, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
const _XE_DOWNLOAD_SERVER_
Definition: config.inc.php:79
$args
Definition: ko.install.php:185
setRedirectUrl($url= './', $output=NULL)
getAdminModel($module_name)
Definition: func.inc.php:156
generate(&$params)
getRealPath($source)
const _XE_PATH_
Definition: config.inc.php:49
getModel($module_name)
Definition: func.inc.php:145
$oAdminController
Definition: ko.install.php:249
getAdminController($module_name)
Definition: func.inc.php:101
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203