Inheritance: extends Gc\Db\AbstractTable
Esempio n. 1
0
 /**
  * Download database as gzip
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadDatabaseAction()
 {
     $what = $this->params()->fromPost('what');
     if (empty($what)) {
         return $this->redirect()->toRoute('module/backup');
     }
     $model = null;
     $configuration = $this->getServiceLocator()->get('Config');
     switch ($configuration['db']['driver']) {
         case 'pdo_pgsql':
             $model = new Model\Database\Pgsql();
             break;
         case 'pdo_mysql':
             $model = new Model\Database\Mysql();
             break;
     }
     if (empty($model)) {
         return $this->redirect()->toRoute('module/backup');
     }
     $content = $model->export($what);
     $filename = 'database-backup-' . date('Y-m-d-H-i-s') . '.sql.gz';
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/download')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }