Ejemplo n.º 1
0
 /**
  * Performs the actual export functions.
  */
 public function runSubmit()
 {
     // Initialize exporter
     $exporterName = $_POST['Export']['exporter'];
     $exporter = new $exporterName($this->mode);
     $extension = strtolower($exporter->getTitle());
     if (isset($_POST['Export']['objects'])) {
         // Load items and assign to exporter
         $items = (array) $_POST['Export']['objects'];
         $exporter->setItems($items, $this->schema);
     } elseif (isset($_POST['Export']['rows'])) {
         // Load rows and assign to exporter
         $rowAttributes = (array) CJSON::decode($_POST['Export']['rows'], true);
         $rows = array();
         foreach ($rowAttributes as $row) {
             $rows[] = Row::model()->findByAttributes($row);
         }
         $exporter->setRows($rows, $this->table, $this->schema);
     }
     // Calculate step count
     $exporter->calculateStepCount();
     // If it was not an ajax request, we have to serve the file for download
     if (!Yii::app()->getRequest()->isAjaxRequest) {
         if ($this->compression == 'gzip' && function_exists('gzencode')) {
             $mimeType = 'application/x-gzip';
             $filenameSuffix = '.gz';
         } elseif ($this->compression == 'bzip2' && function_exists('bzcompress')) {
             $mimeType = 'application/x-bzip2';
             $filenameSuffix = '.bz2';
         } else {
             $mimeType = 'text/plain';
             $filenameSuffix = '';
         }
         $filename = $this->schema . "_" . date("Y_m_d");
         // Send headers
         header('Content-type: ' . $mimeType);
         header('Content-disposition: attachment; filename="' . $filename . "." . $extension . $filenameSuffix . '"');
         // Set handlers
         if ($this->compression == 'gzip' && function_exists('gzencode')) {
             ob_start(array('ExportPage', 'gzEncode'), $this->compressionChunkSize);
         } elseif ($this->compression == 'bzip2' && function_exists('bzcompress')) {
             ob_start(array('ExportPage', 'bz2Encode'), $this->compressionChunkSize);
         }
         $collect = false;
     } else {
         $collect = true;
     }
     // Disable XDebug
     if (function_exists('xdebug_disable')) {
         @xdebug_disable();
     }
     // Time limit 0
     @set_time_limit(0);
     // Run step 0, we only support 1-step-expots by now
     $exporter->runStep(0, $collect);
     // Die after file output when downloading ...
     if (!$collect) {
         ob_end_flush();
         die;
     }
     // Save result
     $this->result = $exporter->getResult();
 }