- Timestamp:
- 2007/12/02 21:05:29 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/batch/SC_Batch_Update.php
r16786 r16862 44 44 * 除外するファイル名をカンマ区切りで羅列. 45 45 */ 46 var $excludes = "distinfo.php ,update.php";46 var $excludes = "distinfo.php"; 47 47 48 48 /** … … 53 53 */ 54 54 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 56 72 $includeArray = explode(',', $this->includes); 57 73 $excludeArray = explode(',', $this->excludes); … … 77 93 // 除外ファイルをスキップ 78 94 if (in_array($fileName, $excludeArray)) { 79 $arrLog[ ] = "excludes by " . $path . "\n";95 $arrLog['ok'][] = "次のファイルは除外されました: " . $path; 80 96 continue; 81 97 } … … 84 100 $sha1 = sha1_file($path); 85 101 86 $arrLog[] = $sha1 . " => " . $path . "\n"; 87 102 //$arrLog[] = $sha1 . " => " . $path; 88 103 89 104 // 変換対象を順に処理 … … 98 113 $out = $distinfo[$sha1]; 99 114 } 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; 102 141 } 103 142 … … 109 148 $handle = @fopen($out, "w"); 110 149 if (!$handle) { 111 $arrLog[ ] = "Cannot open file (". $out . ")\n";150 $arrLog['err'][] = "コピー先に書き込み権限がありません: " . $out; 112 151 continue; 113 152 } … … 116 155 // 取得した内容を書き込む 117 156 if (fwrite($handle, $contents) === false) { 118 $arrLog[ ] = "Cannot write to file (" . $out . ")\n";157 $arrLog['err'][] = "コピー先に書き込み権限がありません: " . $out; 119 158 continue; 120 159 } 121 160 122 $arrLog[ ] = "copyed " . $out . "\n";161 $arrLog['ok'][] = "ファイルのコピーに成功しました: " . $out; 123 162 // ファイルを閉じる 124 163 fclose($handle); … … 127 166 } 128 167 } 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); 130 178 return $arrLog; 131 179 } … … 165 213 $dir .= $n . '/'; 166 214 if(!file_exists($dir)) { 167 if (!@mkdir($dir)) return;215 if (!@mkdir($dir)) break; 168 216 } 169 217 } 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 } 171 229 } 172 230 ?>
Note: See TracChangeset
for help on using the changeset viewer.
