Esempio n. 1
0
 /**
  * Perform update
  *
  * @param array   $post
  * @param boolean $cli
  * @return void
  */
 public function getUpdate($post = array(), $cli = false)
 {
     $docRoot = __DIR__ . '/../../../../../..';
     // If system is writable for updates
     if (!isset($post['submit'])) {
         switch ($post['type']) {
             case 'system':
                 $remoteFile = 'http://update.phirecms.org/system/latest.' . $post['format'];
                 break;
             case 'module':
                 $remoteFile = 'http://update.phirecms.org/modules/' . strtolower($post['name']) . '/latest.' . $post['format'];
                 break;
             case 'theme':
                 $remoteFile = 'http://update.phirecms.org/themes/' . strtolower($post['name']) . '/latest.' . $post['format'];
                 break;
         }
         $remoteContents = @file_get_contents($remoteFile);
         if ($remoteContents !== false) {
             $localFile = $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format'];
             file_put_contents($localFile, $remoteContents);
             $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update');
             unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $msg = null;
             if ($post['type'] == 'module') {
                 if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) {
                     $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                     $dir->emptyDir(null, true);
                     rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                 }
                 $msg = $this->i18n->__('The %1 module has been updated.', $post['name']);
             } else {
                 if ($post['type'] == 'theme') {
                     if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) {
                         $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                         $dir->emptyDir(null, true);
                         rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                     }
                     $msg = $this->i18n->__('The %1 theme has been updated.', $post['name']);
                 } else {
                     if ($post['type'] == 'system') {
                         if ($cli) {
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms', $docRoot . DIRECTORY_SEPARATOR . 'phire-cms-new');
                             $config = Table\Config::findById('updated_on');
                             $config->value = date('Y-m-d H:i:s');
                             $config->update();
                             $msg = $this->i18n->__('The system has been updated.');
                         } else {
                             $time = time();
                             mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time);
                             // Move old files into archive folder
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'config');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'module');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'script');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'vendor');
                             // Move new files into main application path
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor');
                             $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms');
                             $dir->emptyDir(null, true);
                             $config = Table\Config::findById('updated_on');
                             $config->value = date('Y-m-d H:i:s');
                             $config->update();
                             $msg = $this->i18n->__('The system has been updated.');
                         }
                     }
                 }
             }
             $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>';
         } else {
             $this->data['error'] = '<span style="color: #a00b0b">' . $this->i18n->__('The update file was not found.') . '</span>';
         }
         // Else use cURL/FTP
     } else {
         unset($post['submit']);
         $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php');
         $curl->setPost(true);
         $curl->setFields($post);
         $curl->execute();
         $response = json_decode($curl->getBody());
         unset($curl);
         if ($response->error == 0) {
             $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update');
             unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             if ($post['type'] == 'system') {
                 chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/phire-cms', 0777);
             } else {
                 if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'])) {
                     chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], 0777);
                 }
             }
             $post['complete'] = 1;
             $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php');
             $curl->setPost(true);
             $curl->setFields($post);
             $curl->execute();
             $complete = json_decode($curl->getBody());
             if ($complete->error == 0) {
                 switch ($complete->type) {
                     case 'system':
                         $config = Table\Config::findById('updated_on');
                         $config->value = date('Y-m-d H:i:s');
                         $config->update();
                         $msg = $this->i18n->__('The system has been updated.');
                         chmod($docRoot . APP_PATH, 0755);
                         break;
                     case 'module':
                         if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) {
                             $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                             $dir->emptyDir(null, true);
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                         }
                         $msg = $this->i18n->__('The %1 module has been updated.', $complete->name);
                         break;
                     case 'theme':
                         if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) {
                             $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                             $dir->emptyDir(null, true);
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                         }
                         $msg = $this->i18n->__('The %1 theme has been updated.', $complete->name);
                         break;
                 }
                 $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>';
             } else {
                 $this->data['error'] = '<span style="color: #a00b0b">' . $complete->message . '</span>';
             }
         } else {
             $this->data['error'] = '<span style="color: #a00b0b">' . $response->message . '</span>';
         }
     }
     $this->postUpdate($post);
 }
Esempio n. 2
0
 /**
  * Update site
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function update(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $site = Table\Sites::findById($fields['id']);
     $docRoot = substr($fields['document_root'], -1) == '/' && substr($fields['document_root'], -1) == "\\" ? substr($fields['document_root'], 0, -1) : $fields['document_root'];
     $oldDocRoot = $site->document_root;
     $docRoot = str_replace('\\', '/', $docRoot);
     if ($fields['base_path'] != '') {
         $basePath = substr($fields['base_path'], 0, 1) != '/' && substr($fields['base_path'], 0, 1) != "\\" ? '/' . $fields['base_path'] : $fields['base_path'];
         if (substr($basePath, -1) == '/' && substr($basePath, -1) == "\\") {
             $basePath = substr($basePath, 0, -1);
         }
     } else {
         $basePath = '';
     }
     $basePath = str_replace('\\', '/', $basePath);
     $site->domain = $fields['domain'];
     $site->document_root = $docRoot;
     $site->base_path = $basePath;
     $site->title = $fields['title'];
     $site->force_ssl = (int) $fields['force_ssl'];
     $site->live = (int) $fields['live'];
     $site->update();
     $this->data['id'] = $site->id;
     FieldValue::update($fields, $site->id);
     if ($oldDocRoot != $docRoot) {
         $this->createFolders($docRoot, $basePath);
         // Copy any themes over
         $themes = Table\Extensions::findAll(null, array('type' => 0));
         if (isset($themes->rows[0])) {
             $themePath = $docRoot . $basePath . CONTENT_PATH . '/extensions/themes';
             foreach ($themes->rows as $theme) {
                 if (!file_exists($themePath . '/' . $theme->name)) {
                     copy($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . BASE_PATH . DIRECTORY_SEPARATOR . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme->file, $themePath . '/' . $theme->file);
                     $archive = new \Pop\Archive\Archive($themePath . '/' . $theme->file);
                     $archive->extract($themePath . '/');
                     if ((stripos($theme->file, 'gz') || stripos($theme->file, 'bz')) && file_exists($themePath . '/' . $theme->name . '.tar')) {
                         unlink($themePath . '/' . $theme->name . '.tar');
                     }
                 }
             }
         }
     }
 }