Ignore:
Timestamp:
2007/12/02 21:05:29 (19 years ago)
Author:
adachi
Message:

バックアップ対応

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/batch/SC_Batch_Update.php

    r16786 r16862  
    4444     * 除外するファイル名をカンマ区切りで羅列. 
    4545     */ 
    46     var $excludes = "distinfo.php,update.php"; 
     46    var $excludes = "distinfo.php"; 
    4747 
    4848    /** 
     
    5353     */ 
    5454    function execute($target = ".") { 
    55         $arrLog = array(); 
     55        $oldMask = umask(0); 
     56        $bkupDistInfoArray = array(); //バックアップファイル用のdistinfoファイル内容 
     57        $bkupPath = DATA_PATH . 'downloads/backup/update_' . time() . '/'; 
     58        $bkupPathFile = $bkupPath . 'files/'; 
     59        $this->mkdir_p($bkupPathFile . 'dummy'); 
     60 
     61        $arrLog = array( 
     62            'err' =>  array(), 
     63            'ok'  => array(), 
     64            'buckup_path' => $bkupPath 
     65        ); 
     66 
     67        if (!is_writable($bkupPath) || !is_writable($bkupPathFile)) { 
     68            $arrLog['err'][] = 'バックアップディレクトリの作成に失敗しました'; 
     69            return $arrLog; 
     70        } 
     71 
    5672        $includeArray = explode(',', $this->includes); 
    5773        $excludeArray = explode(',', $this->excludes); 
     
    7793                // 除外ファイルをスキップ 
    7894                if (in_array($fileName, $excludeArray)) { 
    79                     $arrLog[] = "excludes by " . $path . "\n"; 
     95                    $arrLog['ok'][] = "次のファイルは除外されました: " . $path; 
    8096                    continue; 
    8197                } 
     
    84100                $sha1 = sha1_file($path); 
    85101 
    86                 $arrLog[] = $sha1 . " => " . $path . "\n"; 
    87  
     102                //$arrLog[] = $sha1 . " => " . $path; 
    88103 
    89104                // 変換対象を順に処理 
     
    98113                            $out = $distinfo[$sha1]; 
    99114                        } else { 
    100                             $arrLog[] = "ハッシュ値が一致しないため, コピー先が取得できません."; 
    101                             die(); 
     115                            $arrLog['err'][] = "ハッシュ値が一致しないため, コピー先が取得できません: " . $path; 
     116                            break 2; 
     117                        } 
     118 
     119                        // パーミッションチェック 
     120                        /** 
     121                        if ($check_only) { 
     122                            if(!is_writable($out)) { 
     123                                $this->mkdir_p($out); 
     124                                if (!is_writable($out)) { 
     125                                    $arrLog['err'][] = "コピー先に書き込み権限がありません: " . $out; 
     126                                } 
     127                            } 
     128                            continue; 
     129                        }**/ 
     130 
     131                        // バックアップを作成 
     132                        if (file_exists($out)) { 
     133                            $bkupTo = $bkupPathFile . pathinfo($out, PATHINFO_BASENAME); 
     134                            $bkupDistInfoArray[sha1_file($out)] = $path; 
     135 
     136                            if (!@copy($out, $bkupTo)) { 
     137                                $arrLog['err'][] = "バックアップファイルの作成に失敗しました: " . $bkupTo; 
     138                                break 2; 
     139                            } 
     140                            $arrLog['ok'][] = "バックアップファイルの作成に成功しました: " . $bkupTo; 
    102141                        } 
    103142 
     
    109148                            $handle = @fopen($out, "w"); 
    110149                            if (!$handle) { 
    111                                 $arrLog[] = "Cannot open file (". $out . ")\n"; 
     150                                $arrLog['err'][] = "コピー先に書き込み権限がありません: " . $out; 
    112151                                continue; 
    113152                            } 
     
    116155                        // 取得した内容を書き込む 
    117156                        if (fwrite($handle, $contents) === false) { 
    118                             $arrLog[] = "Cannot write to file (" . $out . ")\n"; 
     157                            $arrLog['err'][] = "コピー先に書き込み権限がありません: " . $out; 
    119158                            continue; 
    120159                        } 
    121160 
    122                         $arrLog[] =  "copyed " . $out . "\n"; 
     161                        $arrLog['ok'][] =  "ファイルのコピーに成功しました: " . $out; 
    123162                        // ファイルを閉じる 
    124163                        fclose($handle); 
     
    127166            } 
    128167        } 
    129         $arrLog[] = "Finished Successful!\n"; 
     168        $src = $this->makeDistInfo($bkupDistInfoArray); 
     169        if (is_writable($bkupPath)) { 
     170            $handle = @fopen($bkupPath . 'distinfo.php', "w"); 
     171            @fwrite($handle, $src); 
     172            @fclose($handle); 
     173            $arrLog['ok'][] =  "バックアップ用ファイルの作成に成功しました: " . $bkupPath . 'distinfo.php'; 
     174        } else { 
     175            $arrLog['err'][] = "バックアップ用ファイルの作成に成功しました: " . $bkupPath . 'distinfo.php'; 
     176        } 
     177        umask($oldMask); 
    130178        return $arrLog; 
    131179    } 
     
    165213            $dir .= $n . '/'; 
    166214            if(!file_exists($dir)) { 
    167                 if (!@mkdir($dir)) return; 
     215                if (!@mkdir($dir)) break; 
    168216            } 
    169217        } 
    170 } 
     218    } 
     219 
     220    function makeDistInfo($bkupDistInfoArray) { 
     221        $src = "<?php\n" 
     222             . '$distifo = array(' . "\n"; 
     223 
     224        foreach ($bkupDistInfoArray as $key => $value) { 
     225            $src .= "'${key}' => '${value}',\n"; 
     226        } 
     227        $src .= ");\n?>"; 
     228    } 
    171229} 
    172230?> 
Note: See TracChangeset for help on using the changeset viewer.