Example #1
0
 /**
  * Синглтон
  *
  * @return Modules_Service_Model_Backup
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 public function update($skip_backup = false, $skip_zetta = false)
 {
     $client = new Zend_Http_Client(self::URL_UPDATE);
     $client->setParameterPost(array('host' => HTTP_HOST, 'version' => $this->currentVersion(), 'key' => Zend_Registry::get('config')->Db->staticSalt));
     $response = $client->request('POST');
     if (stristr($response->getHeader('Content-type'), 'application')) {
         // доступно новое обновление
         preg_match('/filename=".+\\.(.+)"/', $response->getHeader('Content-disposition'), $matches);
         $archiveType = $matches[1] == 'zip' ? 'zip' : 'tgz';
         // делаем резервную копию сайта
         if (false == $skip_backup) {
             Modules_Service_Model_Backup::getInstance()->backup($skip_zetta);
         }
         file_put_contents($this->_updateDir . DS . 'update.' . $archiveType, $response->getBody());
         // разархивируем данные
         exec('cd ' . $this->_updateDir . ($archiveType == 'zip' ? ' && unzip -o update.zip -d .' : ' && tar -xvf update.tgz .') . ' && rm update.' . $archiveType);
         if (is_file($this->_updateDir . DS . 'zetta.' . $archiveType) && false == $skip_zetta) {
             // обновляем библиотеку
             exec('cd ' . SYSTEM_PATH . ' && rm -rf ./* ' . ($archiveType == 'zip' ? ' && unzip -o ' . $this->_updateDir . DS . 'zetta.zip  -d .' : ' && tar -xvf ' . $this->_updateDir . DS . 'zetta.tgz .') . ' && rm ' . $this->_updateDir . DS . 'zetta.' . $archiveType);
         } else {
             exec('rm ' . $this->_updateDir . DS . 'zetta.' . $archiveType);
         }
         if (is_file($this->_updateDir . DS . 'files.' . $archiveType)) {
             // обновляем данные по сайту
             exec('cd ' . FILE_PATH . ($archiveType == 'zip' ? ' && unzip -o ' . $this->_updateDir . DS . 'files.zip  -d .' : ' && tar -xvf ' . $this->_updateDir . DS . 'files.tgz .') . ' && rm ' . $this->_updateDir . DS . 'files.' . $archiveType);
         }
         if (is_file($post_install = $this->_updateDir . DS . 'install.php')) {
             // запускаем  скрипт постобновления
             require_once $post_install;
             unlink($post_install);
         }
         $version = $this->currentVersion();
         Zend_Registry::get('Logger')->info($str = 'Автоматическое обновление завершено, текущая версия ZettaCMS: ' . $version);
         // пробуем обновиться на следующую версию
         $this->update(true, $skip_zetta);
     }
 }
 public function indexAction()
 {
     Modules_Service_Model_Backup::getInstance()->backup($this->getParam('skip_zetta'));
 }
 /**
  * Восстановить из резервной копии
  *
  */
 public function restoreAction()
 {
     if ($this->getRequest()->isPost() && $this->hasParam('dir')) {
         Modules_Service_Model_Backup::getInstance()->restore($this->getParam('dir'));
     }
 }