PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/downloader/Maged/Controller.php

https://bitbucket.org/andrewjleavitt/magestudy
PHP | 944 lines | 509 code | 108 blank | 327 comment | 73 complexity | 4c816f2586a56a999f0df9bc98f2c915 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Connect
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Class Controller
  28. *
  29. * @category Mage
  30. * @package Mage_Connect
  31. * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  32. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  33. */
  34. final class Maged_Controller
  35. {
  36. /**
  37. * Request key of action
  38. */
  39. const ACTION_KEY = 'A';
  40. /**
  41. * Instance of class
  42. *
  43. * @var Maged_Controller
  44. */
  45. private static $_instance;
  46. /**
  47. * Current action name
  48. *
  49. * @var string
  50. */
  51. private $_action;
  52. /**
  53. * Controller is dispathed flag
  54. *
  55. * @var bool
  56. */
  57. private $_isDispatched = false;
  58. /**
  59. * Redirect to URL
  60. *
  61. * @var string
  62. */
  63. private $_redirectUrl;
  64. /**
  65. * Downloader dir path
  66. *
  67. * @var string
  68. */
  69. private $_rootDir;
  70. /**
  71. * Magento root dir path
  72. *
  73. * @var string
  74. */
  75. private $_mageDir;
  76. /**
  77. * View instance
  78. *
  79. * @var Maged_View
  80. */
  81. private $_view;
  82. /**
  83. * Config instance
  84. *
  85. * @var Maged_Model_Config
  86. */
  87. private $_config;
  88. /**
  89. * Config instance
  90. *
  91. * @var Maged_Model_Config
  92. */
  93. private $_localConfig;
  94. /**
  95. * Session instance
  96. *
  97. * @var Maged_Model_Session
  98. */
  99. private $_session;
  100. /**
  101. * Root dir is writable flag
  102. *
  103. * @var bool
  104. */
  105. private $_writable;
  106. /**
  107. * Use maintenance flag
  108. *
  109. * @var bool
  110. */
  111. protected $_maintenance;
  112. /**
  113. * Maintenance file path
  114. *
  115. * @var string
  116. */
  117. protected $_maintenanceFile;
  118. /**
  119. * Register array for singletons
  120. *
  121. * @var array
  122. */
  123. protected $_singletons = array();
  124. //////////////////////////// ACTIONS
  125. /**
  126. * Get ftp string from post data
  127. *
  128. * @param array $post post data
  129. * @return string FTP Url
  130. */
  131. private function getFtpPost($post){
  132. if (empty($post['ftp_host'])) {
  133. $_POST['ftp'] = '';
  134. return '';
  135. }
  136. $ftp = 'ftp://';
  137. $post['ftp_proto'] = 'ftp://';
  138. if (!empty($post['ftp_path']) && strlen(trim($post['ftp_path'], '\\/'))>0) {
  139. $post['ftp_path'] = '/' . trim($post['ftp_path'], '\\/') . '/';
  140. } else {
  141. $post['ftp_path'] = '/';
  142. }
  143. $start = stripos($post['ftp_host'],'ftp://');
  144. if ($start !== false){
  145. $post['ftp_proto'] = 'ftp://';
  146. $post['ftp_host'] = substr($post['ftp_host'], $start+6-1);
  147. }
  148. $start = stripos($post['ftp_host'],'ftps://');
  149. if ($start !== false){
  150. $post['ftp_proto'] = 'ftps://';
  151. $post['ftp_host'] = substr($post['ftp_host'], $start+7-1);
  152. }
  153. $post['ftp_host'] = trim($post['ftp_host'], '\\/');
  154. if (!empty($post['ftp_login']) && !empty($post['ftp_password'])){
  155. $ftp = sprintf("%s%s:%s@%s%s",
  156. $post['ftp_proto'],
  157. $post['ftp_login'],
  158. $post['ftp_password'],
  159. $post['ftp_host'],
  160. $post['ftp_path']
  161. );
  162. } elseif (!empty($post['ftp_login'])) {
  163. $ftp = sprintf("%s%s@%s%s", $post['ftp_proto'], $post['ftp_login'],$post['ftp_host'],$post['ftp_path']);
  164. } else {
  165. $ftp = $post['ftp_proto'] . $post['ftp_host'] . $post['ftp_path'];
  166. }
  167. $_POST['ftp'] = $ftp;
  168. return $ftp;
  169. }
  170. /**
  171. * NoRoute
  172. *
  173. */
  174. public function norouteAction()
  175. {
  176. header("HTTP/1.0 404 Invalid Action");
  177. echo $this->view()->template('noroute.phtml');
  178. }
  179. /**
  180. * Login
  181. *
  182. */
  183. public function loginAction()
  184. {
  185. $this->view()->set('username', !empty($_GET['username']) ? $_GET['username'] : '');
  186. echo $this->view()->template('login.phtml');
  187. }
  188. /**
  189. * Logout
  190. *
  191. */
  192. public function logoutAction()
  193. {
  194. $this->session()->logout();
  195. $this->redirect($this->url());
  196. }
  197. /**
  198. * Index
  199. *
  200. */
  201. public function indexAction()
  202. {
  203. $config = $this->config();
  204. if (!$this->isInstalled()) {
  205. $this->view()->set('mage_url', dirname(dirname($_SERVER['SCRIPT_NAME'])));
  206. $this->view()->set('use_custom_permissions_mode', $config->__get('use_custom_permissions_mode')?$config->__get('use_custom_permissions_mode'):'0');
  207. $this->view()->set('mkdir_mode', decoct($config->__get('global_dir_mode')));
  208. $this->view()->set('chmod_file_mode', decoct($config->__get('global_file_mode')));
  209. $this->view()->set('protocol', $config->__get('protocol'));
  210. $this->channelConfig()->setInstallView($config,$this->view());
  211. echo $this->view()->template('install/download.phtml');
  212. } elseif (!$config->sync_pear) {
  213. $this->model('connect', true)->connect()->run('sync');
  214. $this->forward('connectPackages');
  215. } else {
  216. $this->forward('connectPackages');
  217. }
  218. }
  219. /**
  220. * Empty Action
  221. *
  222. */
  223. public function emptyAction()
  224. {
  225. $this->model('connect', true)->connect()->runHtmlConsole('Please wait, preparing for updates...');
  226. }
  227. /**
  228. * Install all magento
  229. *
  230. */
  231. public function connectInstallAllAction()
  232. {
  233. $p = &$_POST;
  234. $ftp = $this->getFtpPost($p);
  235. $errors = $this->model('connect', true)->validateConfigPost($p);
  236. /* todo show errors */
  237. if ($errors) {
  238. $message = "CONNECT ERROR: ";
  239. foreach ($errors as $err) {
  240. $message .= $err . "\n";
  241. }
  242. $this->model('connect', true)->connect()->runHtmlConsole($message);
  243. $this->model('connect', true)->connect()->showConnectErrors($errors);
  244. return;
  245. }
  246. if( 1 == $p['inst_protocol']){
  247. $this->model('connect', true)->connect()->setRemoteConfig($this->getFtpPost($p));
  248. }
  249. $this->channelConfig()->setPostData($this->config(),$p);
  250. $chan = $this->config()->__get('root_channel');
  251. $this->model('connect', true)->saveConfigPost($_POST);
  252. $this->channelConfig()->setSettingsSession($_POST, $this->session());
  253. $this->model('connect', true)->installAll(!empty($_GET['force']), $chan);
  254. $p = null;
  255. }
  256. /**
  257. * Connect packages
  258. *
  259. */
  260. public function connectPackagesAction()
  261. {
  262. $connect = $this->model('connect', true);
  263. if (isset($_GET['loggedin'])) {
  264. $connect->connect()->run('sync');
  265. }
  266. $this->view()->set('connect', $connect);
  267. $this->view()->set('channel_config', $this->channelConfig());
  268. $remoteConfig = $this->config()->remote_config;
  269. if (!$this->isWritable() && empty($remoteConfig)) {
  270. $this->view()->set('writable_warning', true);
  271. }
  272. echo $this->view()->template('connect/packages.phtml');
  273. }
  274. /**
  275. * Connect packages POST
  276. *
  277. */
  278. public function connectPackagesPostAction()
  279. {
  280. $actions = isset($_POST['actions']) ? $_POST['actions'] : array();
  281. $ignoreLocalModification = isset($_POST['ignore_local_modification'])?$_POST['ignore_local_modification']:'';
  282. $this->model('connect', true)->applyPackagesActions($actions, $ignoreLocalModification);
  283. }
  284. /**
  285. * Prepare package to install, get dependency info.
  286. *
  287. */
  288. public function connectPreparePackagePostAction()
  289. {
  290. if (!$_POST) {
  291. echo "INVALID POST DATA";
  292. return;
  293. }
  294. $prepareResult = $this->model('connect', true)->prepareToInstall($_POST['install_package_id']);
  295. $packages = isset($prepareResult['data'])? $prepareResult['data']:array();
  296. $errors = isset($prepareResult['errors'])? $prepareResult['errors']:array();
  297. $this->view()->set('packages', $packages);
  298. $this->view()->set('errors', $errors);
  299. $this->view()->set('package_id', $_POST['install_package_id']);
  300. echo $this->view()->template('connect/packages_prepare.phtml');
  301. }
  302. /**
  303. * Install package
  304. *
  305. */
  306. public function connectInstallPackagePostAction()
  307. {
  308. if (!$_POST) {
  309. echo "INVALID POST DATA";
  310. return;
  311. }
  312. $this->model('connect', true)->installPackage($_POST['install_package_id']);
  313. }
  314. /**
  315. * Install uploaded package
  316. *
  317. */
  318. public function connectInstallPackageUploadAction()
  319. {
  320. if (!$_FILES) {
  321. echo "No file was uploaded";
  322. return;
  323. }
  324. if(empty($_FILES['file'])) {
  325. echo "No file was uploaded";
  326. return;
  327. }
  328. $info =& $_FILES['file'];
  329. if(0 !== intval($info['error'])) {
  330. echo "File upload problem";
  331. return;
  332. }
  333. $target = $this->_mageDir . DS . "var/".uniqid().$info['name'];
  334. $res = move_uploaded_file($info['tmp_name'], $target);
  335. if(false === $res) {
  336. echo "Error moving uploaded file";
  337. return;
  338. }
  339. $this->model('connect', true)->installUploadedPackage($target);
  340. @unlink($target);
  341. }
  342. /**
  343. * Settings
  344. *
  345. */
  346. public function settingsAction()
  347. {
  348. $config = $this->config();
  349. $this->view()->set('preferred_state', $config->__get('preferred_state'));
  350. $this->view()->set('protocol', $config->__get('protocol'));
  351. $this->view()->set('use_custom_permissions_mode', $config->__get('use_custom_permissions_mode'));
  352. $this->view()->set('mkdir_mode', decoct($config->__get('global_dir_mode')));
  353. $this->view()->set('chmod_file_mode', decoct($config->__get('global_file_mode')));
  354. $this->channelConfig()->setSettingsView($this->session(), $this->view());
  355. $fs_disabled=!$this->isWritable();
  356. $ftpParams=$config->__get('remote_config')?@parse_url($config->__get('remote_config')):'';
  357. $this->view()->set('fs_disabled', $fs_disabled);
  358. $this->view()->set('deployment_type', ($fs_disabled||!empty($ftpParams)?'ftp':'fs'));
  359. if(!empty($ftpParams)){
  360. $this->view()->set('ftp_host', sprintf("%s://%s",$ftpParams['scheme'],$ftpParams['host']));
  361. $this->view()->set('ftp_login', $ftpParams['user']);
  362. $this->view()->set('ftp_password', $ftpParams['pass']);
  363. $this->view()->set('ftp_path', $ftpParams['path']);
  364. }
  365. echo $this->view()->template('settings.phtml');
  366. }
  367. /**
  368. * Settings post
  369. *
  370. */
  371. public function settingsPostAction()
  372. {
  373. if ($_POST) {
  374. $ftp=$this->getFtpPost($_POST);
  375. $errors = $this->model('connect', true)->validateConfigPost($_POST);
  376. if ($errors) {
  377. foreach ($errors as $err) {
  378. $this->session()->addMessage('error', $err);
  379. }
  380. $this->redirect($this->url('settings'));
  381. return;
  382. }
  383. try {
  384. if( 'ftp' == $_POST['deployment_type']&&!empty($_POST['ftp_host'])){
  385. $this->model('connect', true)->connect()->setRemoteConfig($ftp);
  386. }else{
  387. $this->model('connect', true)->connect()->setRemoteConfig('');
  388. $_POST['ftp'] = '';
  389. }
  390. $this->channelConfig()->setPostData($this->config(), $_POST);
  391. $this->model('connect', true)->saveConfigPost($_POST);
  392. $this->channelConfig()->setSettingsSession($_POST, $this->session());
  393. $this->model('connect', true)->connect()->run('sync');
  394. } catch (Exception $e) {
  395. $this->session()->addMessage('error', "Unable to save settings: ".$e->getMessage());
  396. }
  397. }
  398. $this->redirect($this->url('settings'));
  399. }
  400. //////////////////////////// ABSTRACT
  401. /**
  402. * Constructor
  403. *
  404. */
  405. public function __construct()
  406. {
  407. $this->_rootDir = dirname(dirname(__FILE__));
  408. $this->_mageDir = dirname($this->_rootDir);
  409. }
  410. /**
  411. * Run
  412. *
  413. */
  414. public static function run()
  415. {
  416. try {
  417. self::singleton()->dispatch();
  418. } catch (Exception $e) {
  419. echo $e->getMessage();
  420. //echo self::singleton()->view()->set('exception', $e)->template("exception.phtml");
  421. }
  422. }
  423. /**
  424. * Initialize object of class
  425. *
  426. * @return Maged_Controller
  427. */
  428. public static function singleton()
  429. {
  430. if (!self::$_instance) {
  431. self::$_instance = new self;
  432. if (self::$_instance->isDownloaded() && self::$_instance->isInstalled()) {
  433. Mage::app();
  434. Mage::getSingleton('adminhtml/url')->turnOffSecretKey();
  435. }
  436. }
  437. return self::$_instance;
  438. }
  439. /**
  440. * Retrieve Downloader root dir
  441. *
  442. * @return string
  443. */
  444. public function getRootDir()
  445. {
  446. return $this->_rootDir;
  447. }
  448. /**
  449. * Retrieve Magento root dir
  450. *
  451. * @return string
  452. */
  453. public function getMageDir()
  454. {
  455. return $this->_mageDir;
  456. }
  457. /**
  458. * Retrieve Mage Class file path
  459. *
  460. * @return string
  461. */
  462. public function getMageFilename()
  463. {
  464. $ds = DIRECTORY_SEPARATOR;
  465. return $this->getMageDir() . $ds . 'app' . $ds . 'Mage.php';
  466. }
  467. /**
  468. * Retrieve path for Varien_Profiler
  469. *
  470. * @return string
  471. */
  472. public function getVarFilename()
  473. {
  474. $ds = DIRECTORY_SEPARATOR;
  475. return $this->getMageDir() . $ds . 'lib' . $ds . 'Varien' . $ds . 'Profiler.php';
  476. }
  477. /**
  478. * Retrieve downloader file path
  479. *
  480. * @param string $name
  481. * @return string
  482. */
  483. public function filepath($name = '')
  484. {
  485. $ds = DIRECTORY_SEPARATOR;
  486. return rtrim($this->getRootDir() . $ds . str_replace('/', $ds, $name), $ds);
  487. }
  488. /**
  489. * Retrieve object of view
  490. *
  491. * @return Maged_View
  492. */
  493. public function view()
  494. {
  495. if (!$this->_view) {
  496. $this->_view = new Maged_View;
  497. }
  498. return $this->_view;
  499. }
  500. /**
  501. * Retrieve object of model
  502. *
  503. * @param string $model
  504. * @param boolean $singleton
  505. * @return Maged_Model
  506. */
  507. public function model($model = null, $singleton = false)
  508. {
  509. if ($singleton && isset($this->_singletons[$model])) {
  510. return $this->_singletons[$model];
  511. }
  512. if (is_null($model)) {
  513. $class = 'Maged_Model';
  514. } else {
  515. $class = 'Maged_Model_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $model)));
  516. if (!class_exists($class, false)) {
  517. include_once str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  518. }
  519. }
  520. $object = new $class();
  521. if ($singleton) {
  522. $this->_singletons[$model] = $object;
  523. }
  524. return $object;
  525. }
  526. /**
  527. * Retrieve object of config
  528. *
  529. * @return Mage_Connect_Config
  530. */
  531. public function config()
  532. {
  533. if (!$this->_config) {
  534. //$this->_config = $this->model('config')->load();
  535. $this->_config = $this->model('connect', true)->connect()->getConfig();
  536. }
  537. return $this->_config;
  538. }
  539. /**
  540. * Retrieve object of channel config
  541. *
  542. * @return Maged_Model_Config_Interface
  543. */
  544. public function channelConfig()
  545. {
  546. if (!$this->_localConfig) {
  547. $this->_localConfig = $this->model('config', true)->getChannelConfig();
  548. }
  549. return $this->_localConfig;
  550. }
  551. /**
  552. * Retrieve object of session
  553. *
  554. * @return Maged_Model_Session
  555. */
  556. public function session()
  557. {
  558. if (!$this->_session) {
  559. $this->_session = $this->model('session')->start();
  560. }
  561. return $this->_session;
  562. }
  563. /**
  564. * Set Controller action
  565. *
  566. * @param string $action
  567. * @return Maged_Controller
  568. */
  569. public function setAction($action=null)
  570. {
  571. if (is_null($action)) {
  572. if (!empty($this->_action)) {
  573. return $this;
  574. }
  575. $action = !empty($_GET[self::ACTION_KEY]) ? $_GET[self::ACTION_KEY] : 'index';
  576. }
  577. if (empty($action) || !is_string($action) || !method_exists($this, $this->getActionMethod($action))) {
  578. //$action = 'noroute';
  579. $action = 'index';
  580. }
  581. $this->_action = $action;
  582. return $this;
  583. }
  584. /**
  585. * Retrieve Controller action name
  586. *
  587. * @return string
  588. */
  589. public function getAction()
  590. {
  591. return $this->_action;
  592. }
  593. /**
  594. * Set Redirect to URL
  595. *
  596. * @param string $url
  597. * @param bool $force
  598. * @return Maged_Controller
  599. */
  600. public function redirect($url, $force = false)
  601. {
  602. $this->_redirectUrl = $url;
  603. if ($force) {
  604. $this->processRedirect();
  605. }
  606. return $this;
  607. }
  608. /**
  609. * Precess redirect
  610. *
  611. * @return Maged_Controller
  612. */
  613. public function processRedirect()
  614. {
  615. if ($this->_redirectUrl) {
  616. if (headers_sent()) {
  617. echo '<script type="text/javascript">location.href="'.$this->_redirectUrl.'"</script>';
  618. exit;
  619. } else {
  620. header("Location: ".$this->_redirectUrl);
  621. exit;
  622. }
  623. }
  624. return $this;
  625. }
  626. /**
  627. * Forward to action
  628. *
  629. * @param string $action
  630. * @return Maged_Controller
  631. */
  632. public function forward($action)
  633. {
  634. $this->setAction($action);
  635. $this->_isDispatched = false;
  636. return $this;
  637. }
  638. /**
  639. * Retrieve action method by action name
  640. *
  641. * @param string $action
  642. * @return string
  643. */
  644. public function getActionMethod($action = null)
  645. {
  646. $method = (!is_null($action) ? $action : $this->_action).'Action';
  647. return $method;
  648. }
  649. /**
  650. * Generate URL for action
  651. *
  652. * @param string $action
  653. * @param array $params
  654. */
  655. public function url($action = '', $params = array())
  656. {
  657. $args = array();
  658. foreach ($params as $k => $v) {
  659. $args[] = sprintf('%s=%s', rawurlencode($k), rawurlencode($v));
  660. }
  661. $args = $args ? join('&', $args) : '';
  662. return sprintf('%s?%s=%s%s', $_SERVER['SCRIPT_NAME'], self::ACTION_KEY, rawurlencode($action), $args);
  663. }
  664. /**
  665. * Dispatch process
  666. *
  667. */
  668. public function dispatch()
  669. {
  670. header('Content-type: text/html; charset=UTF-8');
  671. $this->setAction();
  672. if (!$this->isInstalled()) {
  673. if (!in_array($this->getAction(), array('index', 'connectInstallAll', 'empty'))) {
  674. $this->setAction('index');
  675. }
  676. } else {
  677. $this->session()->authenticate();
  678. }
  679. while (!$this->_isDispatched) {
  680. $this->_isDispatched = true;
  681. $method = $this->getActionMethod();
  682. //echo($method);exit();
  683. $this->$method();
  684. }
  685. $this->processRedirect();
  686. }
  687. /**
  688. * Check root dir is writable
  689. *
  690. * @return bool
  691. */
  692. public function isWritable()
  693. {
  694. if (is_null($this->_writable)) {
  695. $this->_writable = is_writable($this->getMageDir() . DIRECTORY_SEPARATOR)
  696. && is_writable($this->filepath())
  697. && (!file_exists($this->filepath('config.ini') || is_writable($this->filepath('config.ini'))));
  698. }
  699. return $this->_writable;
  700. }
  701. /**
  702. * Check is Magento files downloaded
  703. *
  704. * @return bool
  705. */
  706. public function isDownloaded()
  707. {
  708. return file_exists($this->getMageFilename()) && file_exists($this->getVarFilename());
  709. }
  710. /**
  711. * Check is Magento installed
  712. *
  713. * @return bool
  714. */
  715. public function isInstalled()
  716. {
  717. if (!$this->isDownloaded()) {
  718. return false;
  719. }
  720. if (!class_exists('Mage', false)) {
  721. if (!file_exists($this->getMageFilename())) {
  722. return false;
  723. }
  724. include_once $this->getMageFilename();
  725. Mage::setIsDownloader();
  726. }
  727. return Mage::isInstalled();
  728. }
  729. /**
  730. * Retrieve Maintenance flag
  731. *
  732. * @return bool
  733. */
  734. protected function _getMaintenanceFlag()
  735. {
  736. if (is_null($this->_maintenance)) {
  737. $this->_maintenance = !empty($_REQUEST['maintenance']) && $_REQUEST['maintenance'] == '1' ? true : false;
  738. }
  739. return $this->_maintenance;
  740. }
  741. /**
  742. * Retrieve Maintenance Flag file path
  743. *
  744. * @return string
  745. */
  746. protected function _getMaintenanceFilePath()
  747. {
  748. if (is_null($this->_maintenanceFile)) {
  749. $path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR;
  750. $this->_maintenanceFile = $path . 'maintenance.flag';
  751. }
  752. return $this->_maintenanceFile;
  753. }
  754. /**
  755. * Begin install package(s)
  756. *
  757. */
  758. public function startInstall()
  759. {
  760. if ($this->_getMaintenanceFlag()) {
  761. $maintenance_filename='maintenance.flag';
  762. $config = $this->config();
  763. if(!$this->isWritable()||strlen($config->__get('remote_config'))>0){
  764. $ftpObj = new Mage_Connect_Ftp();
  765. $ftpObj->connect($config->__get('remote_config'));
  766. $tempFile = tempnam(sys_get_temp_dir(),'maintenance');
  767. @file_put_contents($tempFile, 'maintenance');
  768. $ret=$ftpObj->upload($maintenance_filename, $tempFile);
  769. $ftpObj->close();
  770. }else{
  771. @file_put_contents($this->_getMaintenanceFilePath(), 'maintenance');
  772. }
  773. }
  774. }
  775. /**
  776. * End install package(s)
  777. *
  778. */
  779. public function endInstall()
  780. {
  781. if ($this->isInstalled()) {
  782. try {
  783. if (!empty($_GET['clean_sessions'])) {
  784. Mage::app()->cleanAllSessions();
  785. }
  786. Mage::app()->cleanCache();
  787. } catch (Exception $e) {
  788. $this->session()->addMessage('error', "Exception during cache and session cleaning: ".$e->getMessage());
  789. }
  790. // reinit config and apply all updates
  791. Mage::app()->getConfig()->reinit();
  792. Mage_Core_Model_Resource_Setup::applyAllUpdates();
  793. Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
  794. }
  795. if ($this->_getMaintenanceFlag()) {
  796. $maintenance_filename='maintenance.flag';
  797. $config = $this->config();
  798. if(!$this->isWritable()&&strlen($config->__get('remote_config'))>0){
  799. $ftpObj = new Mage_Connect_Ftp();
  800. $ftpObj->connect($config->__get('remote_config'));
  801. $ftpObj->delete($maintenance_filename);
  802. $ftpObj->close();
  803. }else{
  804. @unlink($this->_getMaintenanceFilePath());
  805. }
  806. }
  807. }
  808. /**
  809. * Gets the current Magento Connect Manager (Downloader) version string
  810. * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
  811. *
  812. * @return string
  813. */
  814. public static function getVersion()
  815. {
  816. $i = self::getVersionInfo();
  817. return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "") . "-{$i['stability']}{$i['number']}", '.-');
  818. }
  819. /**
  820. * Gets the detailed Magento Connect Manager (Downloader) version information
  821. * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
  822. *
  823. * @return array
  824. */
  825. public static function getVersionInfo()
  826. {
  827. return array(
  828. 'major' => '1',
  829. 'minor' => '5',
  830. 'revision' => '0',
  831. 'patch' => '1',
  832. 'stability' => '',
  833. 'number' => '',
  834. );
  835. }
  836. }