Changeset 20945 for branches/version-2_11-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php
- Timestamp:
- 2011/05/19 23:45:07 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php
r20911 r20945 51 51 var $exec; 52 52 var $tpl_count_mtb_zip; 53 54 /** CSV の更新日時 */ 55 var $tpl_csv_datetime; 56 57 /** ZIP アーカイブファイルの取得元 */ 58 var $zip_download_url = 'http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip'; 59 60 /** 日本郵便から取得した ZIP アーカイブファイルの保管パス */ 61 var $zip_csv_temp_realfile; 53 62 54 63 // }}} … … 70 79 $this->tpl_mode = $this->getMode(); 71 80 $this->exec = (boolean)$_GET['exec']; 81 $this->zip_csv_temp_realfile = DATA_REALDIR . 'downloads/tmp/ken_all.zip'; 72 82 } 73 83 … … 105 115 $this->lfAutoCommitZip(); 106 116 break; 107 // 手動登録117 // DB手動登録 108 118 case 'manual': 109 119 $this->insertMtbZip($this->arrForm['startRowNum']); … … 114 124 115 125 switch ($this->tpl_mode) { 116 // 手動削除126 // 削除 117 127 case 'delete': 118 128 $this->lfDeleteZip(); … … 120 130 // 進捗・完了画面を表示しない 121 131 $this->tpl_mode = null; 122 132 break; 133 134 // 郵便番号CSV更新 135 case 'update_csv'; 136 $this->lfDownloadZipFileFromJp(); 137 $this->lfExtractZipFile(); 138 139 // 進捗・完了画面を表示しない 140 $this->tpl_mode = null; 123 141 break; 124 142 } … … 126 144 $this->tpl_line = $this->countZipCsv(); 127 145 $this->tpl_count_mtb_zip = $this->countMtbZip(); 146 $this->tpl_csv_datetime = $this->lfGetCsvDatetime(); 147 // XXX PHP4 を切捨てたら、ダウンロードの必要性チェックなども行いたい 148 // $arrHeader = get_headers($this->zip_download_url, 1); 128 149 } 129 150 … … 140 161 $objQuery =& SC_Query_Ex::getSingletonInstance(); 141 162 163 $this->lfDownloadZipFileFromJp(); 164 $this->lfExtractZipFile(); 165 142 166 $objQuery->begin(); 143 $ objQuery->delete('mtb_zip');167 $this->lfDeleteZip(); 144 168 $this->insertMtbZip(); 145 169 $objQuery->commit(); 146 170 } 147 171 172 /** 173 * テーブルデータと UTF-8 変換済みの郵便番号 CSV を削除 174 * 175 * @return void 176 */ 148 177 function lfDeleteZip() { 149 178 $objQuery =& SC_Query_Ex::getSingletonInstance(); 150 179 180 // DB 151 181 $objQuery->delete('mtb_zip'); 182 183 // UTF-8 変換済みの郵便番号 CSV 184 unlink(ZIP_CSV_UTF8_REALFILE); 152 185 } 153 186 … … 179 212 </head> 180 213 <body> 181 <p> 進捗状況</p>214 <p>DB 登録進捗状況</p> 182 215 <div style="background-color: #494E5F;"> 183 216 <?php … … 271 304 272 305 function openZipCsv() { 273 // http://www.post.japanpost.jp/zipcode/dl/kogaki/lzh/ken_all.lzh274 306 $this->convertZipCsv(); 275 307 $fp = fopen(ZIP_CSV_UTF8_REALFILE, 'r'); … … 325 357 return $line; 326 358 } 359 360 /** 361 * 日本郵便から郵便番号 CSV の ZIP アーカイブファイルを取得 362 * 363 * @return void 364 */ 365 function lfDownloadZipFileFromJp() { 366 $res = copy($this->zip_download_url, $this->zip_csv_temp_realfile); 367 if (!$res) { 368 SC_Utils_Ex::sfDispException($this->zip_download_url . ' の取得または ' . $this->zip_csv_temp_realfile . ' への書き込みに失敗しました。'); 369 } 370 } 371 372 /** 373 * ZIP アーカイブファイルを展開して、郵便番号 CSV を上書き 374 * 375 * @return void 376 */ 377 function lfExtractZipFile() { 378 if (!function_exists('zip_open')) { 379 SC_Utils_Ex::sfDispException('PHP 拡張モジュール「zip」を有効にしてください。'); 380 } 381 382 $zip = zip_open($this->zip_csv_temp_realfile); 383 if (!is_resource($zip)) { 384 SC_Utils_Ex::sfDispException($this->zip_csv_temp_realfile . ' をオープンできません。'); 385 } 386 387 do { 388 $entry = zip_read($zip); 389 } while ($entry && zip_entry_name($entry) != 'KEN_ALL.CSV'); 390 391 if (!$entry) { 392 SC_Utils_Ex::sfDispException($this->zip_csv_temp_realfile . ' に対象ファイルが見つかりません。'); 393 } 394 395 // 展開時の破損を考慮し、別名で一旦展開する。 396 $tmp_csv_realfile = ZIP_CSV_REALFILE . '.tmp'; 397 398 $res = zip_entry_open($zip, $entry, 'rb'); 399 if (!$res) { 400 SC_Utils_Ex::sfDispException($this->zip_csv_temp_realfile . ' の展開に失敗しました。'); 401 } 402 403 $fp = fopen($tmp_csv_realfile, 'w'); 404 if (!$fp) { 405 SC_Utils_Ex::sfDispException($tmp_csv_realfile . ' を開けません。'); 406 } 407 408 $res = fwrite($fp, zip_entry_read($entry, zip_entry_filesize($entry))); 409 if ($res === FALSE) { 410 SC_Utils_Ex::sfDispException($tmp_csv_realfile . ' の書き込みに失敗しました。'); 411 } 412 413 fclose($fp); 414 zip_close($zip); 415 416 // CSV 削除 417 $res = unlink(ZIP_CSV_REALFILE); 418 if (!$res) { 419 SC_Utils_Ex::sfDispException(ZIP_CSV_REALFILE . ' を削除できません。'); 420 } 421 422 // CSV ファイル名変更 423 $res = rename($tmp_csv_realfile, ZIP_CSV_REALFILE); 424 if (!$res) { 425 SC_Utils_Ex::sfDispException('ファイル名を変更できません。: ' . $tmp_csv_realfile . ' -> ' . ZIP_CSV_REALFILE); 426 } 427 } 428 429 /** 430 * CSV の更新日時を取得 431 * 432 * @return string CSV の更新日時 (整形済みテキスト) 433 */ 434 function lfGetCsvDatetime() { 435 return date('Y/m/d H:i:s', filemtime(ZIP_CSV_REALFILE)); 436 } 327 437 } 328 438 ?>
Note: See TracChangeset
for help on using the changeset viewer.