Ignore:
Timestamp:
2014/05/01 16:34:42 (10 years ago)
Author:
Seasoft
Message:

#2534 (CSV 出力で一時ファイルが異常な状態で放置されることがある)
#2535 (CSV 生成の独自処理を減らす)
#2448 (typo修正・ソース整形・ソースコメントの改善 for 2.13.2)

  • 下記メソッドは不要となったが、マイナーバージョンアップまでは前方互換用に残す。
    • SC_Helper_CSV#sfArrayToCsv
    • SC_Helper_CSV#lfDownloadCsv
    • SC_Helper_CSV#lfDownloadCSVFile
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/class/pages/admin/system/LC_Page_Admin_System_Bkup.php

    r23124 r23388  
    4242    ); 
    4343 
     44    /** ヘッダーを出力するか (cbOutputCSV 用) */ 
     45    private $output_header = false; 
     46 
    4447    /** 
    4548     * Page を初期化する. 
     
    185188 
    186189                    // ダウンロード開始 
    187                     Header("Content-disposition: attachment; filename=${filename}"); 
    188                     Header("Content-type: application/octet-stream; name=${filename}"); 
    189                     header('Content-Length: ' .filesize($dl_file)); 
    190                     readfile ($dl_file); 
    191                     exit(); 
     190                    SC_Response_Ex::headerForDownload($filename); 
     191                    header('Content-Length: ' . filesize($dl_file)); 
     192                    readfile($dl_file); 
     193                    SC_Response_Ex::actionExit(); 
    192194                    break; 
    193195                } 
     
    289291            // dataをCSV出力 
    290292            $csv_file = $work_dir . $table . '.csv'; 
    291             $fp = fopen($csv_file, 'w'); 
    292             if (!$fp) { 
     293            $this->fpOutput = fopen($csv_file, 'w');; 
     294            if (!$this->fpOutput) { 
    293295                return __LINE__; 
    294296            } 
     
    297299            $sql = 'SELECT * FROM ' . $objQuery->conn->quoteIdentifier($table); 
    298300 
    299             $this->fpOutput =& $fp; 
    300             $this->first_line = true; 
     301            $this->output_header = true; 
    301302            $success = $objQuery->doCallbackAll(array(&$this, 'cbOutputCSV'), $sql); 
    302             unset($this->fpOutput); 
     303 
     304            fclose($this->fpOutput); 
    303305 
    304306            if ($success === false) { 
    305307                return __LINE__; 
    306308            } 
    307  
    308             fclose($fp); 
    309309 
    310310            // タイムアウトを防ぐ 
     
    351351    public function cbOutputCSV($data) 
    352352    { 
    353         $line = ''; 
    354         if ($this->first_line) { 
    355             // カラム名 
    356             $line .= SC_Helper_CSV_Ex::sfArrayToCsv(array_keys($data)) . "\n"; 
    357             $this->first_line = false; 
    358         } 
    359         $line .= SC_Helper_CSV_Ex::sfArrayToCsv($data); 
    360         $line .= "\n"; 
     353        // 1行目のみヘッダーを出力する 
     354        if ($this->output_header) { 
     355            fputcsv($this->fpOutput, array_keys($data)); 
     356            $this->output_header = false; 
     357        } 
     358        fputcsv($this->fpOutput, $data); 
    361359        SC_Utils_Ex::extendTimeOut(); 
    362360 
    363         return fwrite($this->fpOutput, $line); 
     361        return true; 
    364362    } 
    365363 
Note: See TracChangeset for help on using the changeset viewer.