Exemplo n.º 1
0
 public function restoreAction()
 {
     // Require
     require_once 'PEAR.php';
     require_once 'Archive/Tar.php';
     // Param
     $backup = $this->_getParam('backup');
     // Verify backup
     $archiveFilename = $this->_outputPath . DIRECTORY_SEPARATOR . $backup;
     if ('' == $backup || !is_file($archiveFilename)) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'index'));
     }
     // Check for vfs instance
     if (!$this->_vfs instanceof Engine_Vfs_Adapter_Abstract) {
         $this->_session->return = $_SERVER['REQUEST_URI'];
         return $this->_helper->redirector->gotoRoute(array('controller' => 'vfs', 'action' => 'index'));
     }
     // Check for database instance
     if (!($db = Zend_Registry::get('Zend_Db')) instanceof Zend_Db_Adapter_Abstract) {
         throw new Engine_Exception('No database instance');
     }
     // Confirm/Options
     $this->view->form = $form = new Install_Form_Backup_Restore();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // !!IMPORTANT!!
     set_time_limit(0);
     ignore_user_abort(true);
     // Errors
     $errors = array();
     // Make temporary folder
     $archiveOutputPath = substr($archiveFilename, 0, strrpos($archiveFilename, '.'));
     if (is_dir($archiveOutputPath)) {
         Engine_Package_Utilities::fsRmdirRecursive($archiveOutputPath, true);
     }
     if (!mkdir($archiveOutputPath, 0777, true)) {
         throw new Engine_Exception(sprintf('Unable to make path %s', $archiveOutputPath));
     }
     // Extract
     $archive = new Archive_Tar($archiveFilename);
     $archive->extract($archiveOutputPath);
     // Upload
     $path = APPLICATION_PATH;
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($it as $file) {
         $fullPath = $file->getPathname();
         $partialPath = ltrim(str_replace($path, '', $fullPath), '/\\');
         if (is_dir($fullPath)) {
             try {
                 $this->_vfs->makeDirectory($directory, true);
             } catch (Exception $e) {
                 $errors[] = $e->__toString();
             }
         } else {
             try {
                 $this->_vfs->put($partialPath, $fullPath);
             } catch (Exception $e) {
                 $errors[] = $e->__toString();
             }
         }
     }
     // Database
     //$db = new Zend_Db_Adapter_Mysqli();
     $queries = Engine_Package_Utilities::sqlSplit(file_get_contents($archiveOutputPath . '/database.sql'));
     foreach ($queries as $query) {
         try {
             $db->query($query);
         } catch (Exception $e) {
             $errors[] = $e->__toString();
         }
     }
     var_dump($errors);
     die('DONE!');
 }
 public function __sleep()
 {
     return array_merge(parent::__sleep(), array('_host', '_port', '_timeout', '_useSsl', '_username', '_password'));
 }