Changeset 16624
- Timestamp:
- 2007/10/30 20:56:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/pages/upgrade/LC_Page_Upgrade_AutoUpdate.php
r16582 r16624 24 24 // {{{ requires 25 25 require_once CLASS_PATH . 'pages/upgrade/LC_Page_Upgrade_Base.php'; 26 require_once 'utils/LC_Utils_Upgrade.php'; 27 require_once 'utils/LC_Utils_Upgrade_Log.php'; 26 28 27 29 /** … … 36 38 class LC_Page_Upgrade_AutoUpdate extends LC_Page_Upgrade_Base { 37 39 38 /** SC_Sessionオブジェクト */39 var $objSession = null;40 /** Services_Jsonオブジェクト */41 var $objJson = null;42 /** HTTP_Requestオブジェクト */43 var $objReq = null;44 /** SC_FromParamオブジェクト */45 var $objForm = null;46 47 40 // }}} 48 41 // {{{ functions … … 55 48 function init() { 56 49 $this->objJson = new Services_Json(); 57 $rhis->objReq = new HTTP_Request(); 50 $this->objLog = new LC_Utils_Upgrade_Log('Auto Update'); 51 58 52 $this->objForm = new SC_FormParam(); 59 53 $this->objForm->addParam('product_id', 'product_id', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); … … 67 61 */ 68 62 function process() { 69 $errFormat = '* error! code:%s / debug:%s'; 70 71 GC_Utils::gfPrintLog('###Auto Update Start###'); 63 $this->objLog->start(); 72 64 73 65 // IPチェック 74 GC_Utils::gfPrintLog('* ip check start'); 75 if ($this->isValidIP() !== true) { 76 $arrErr = array( 77 'status' => OWNERSSTORE_STATUS_ERROR, 78 'errcode' => '' 79 ); 80 echo $this->objJson->encode($arrErr); 81 GC_Utils::gfPrintLog( 82 sprintf($errFormat, $arrErr['errcode'], '') 83 ); 66 $this->objLog->log('* ip check start'); 67 if (LC_Utils_Upgrade::isValidIP() !== true) { 68 $arrErr = array( 69 'status' => OWNERSSTORE_STATUS_ERROR, 70 'errcode' => OWNERSSTORE_ERR_AU_INVALID_IP 71 ); 72 echo $this->objJson->encode($arrErr); 73 $this->objLog->errLog($arrErr['errcode'], $_SERVER['REMOTE_ADDR']); 84 74 exit; 85 75 } 86 76 87 77 // パラメーチェック 88 GC_Utils::gfPrintLog('* post parameter check start');78 $this->objLog->log('* post parameter check start'); 89 79 if ($this->objForm->checkError()) { 90 80 $arrErr = array( 91 81 'status' => OWNERSSTORE_STATUS_ERROER, 92 'errcode' => '', 93 ); 94 echo $this->objJson->encode($arrErr); 95 GC_Utils::gfPrintLog( 96 sprintf($errFormat, $arrErr['errcode'], serialize($_POST)) 97 ); 82 'errcode' => OWNERSSTORE_ERR_AU_POST_PARAM 83 ); 84 echo $this->objJson->encode($arrErr); 85 $this->objLog->errLog($arrErr['errcode'], $_POST); 98 86 exit; 99 87 } 100 88 101 89 // 自動アップデート設定の判定 102 GC_Utils::gfPrintLog('* auto update settings check start');90 $this->objLog->log('* auto update settings check start'); 103 91 if ($this->autoUpdateEnable() !== true) { 104 92 $arrErr = array( 105 93 'status' => OWNERSSTORE_STATUS_ERROER, 106 'errcode' => '', 107 ); 108 echo $this->objJson->encode($arrErr); 109 GC_Utils::gfPrintLog( 110 sprintf($errFormat, $arrErr['errcode'], serialize($product_id)) 111 ); 94 'errcode' => OWNERSSTORE_ERR_AU_NO_UPDATE, 95 ); 96 echo $this->objJson->encode($arrErr); 97 $this->objLog->errLog($arrErr['errcode']); 112 98 exit; 113 99 } 114 100 115 101 // ダウンロードリクエストを開始 116 GC_Utils::gfPrintLog('* http request start');117 $ resp = $this->request(102 $this->objLog->log('* http request start'); 103 $objReq = LC_Utils_Upgrade::request( 118 104 'download', 119 105 array('product_id' => $this->objForm->getValue('product_id')) … … 121 107 122 108 // リクエストのエラーチェック 123 GC_Utils::gfPrintLog('* http response check start'); 124 if (PEAR::isError($resp)) { 125 $arrErr = array( 126 'status' => OWNERSSTORE_STATUS_ERROR, 127 'errcode' => '', 128 ); 129 echo $this->objJson->encode($arrErr); 130 GC_Utils::gfPrintLog( 131 sprintf($errFormat, $arrErr['errcode'], serialize($resp)) 132 ); 109 $this->objLog->log('* http request check start'); 110 if (PEAR::isError($objReq)) { 111 $arrErr = array( 112 'status' => OWNERSSTORE_STATUS_ERROR, 113 'errcode' => OWNERSSTORE_ERR_AU_HTTP_REQ, 114 ); 115 echo $this->objJson->encode($arrErr); 116 $this->objLog->errLog($arrErr['errcode'], $objReq); 117 exit; 118 } 119 120 // レスポンスの検証 121 $this->objLog->log('* http response check start'); 122 if ($objReq->getResponseCode() !== 200) { 123 $arrErr = array( 124 'status' => OWNERSSTORE_STATUS_ERROR, 125 'errcode' => OWNERSSTORE_ERR_AU_HTTP_RESP_CODE, 126 ); 127 echo $this->objJson->encode($arrErr); 128 $this->objLog->errLog($arrErr['errcode'], $objReq); 133 129 exit; 134 130 } 135 131 136 132 // JSONデータの検証 137 $jsonData = $resp->getResponseBody(); 138 $objRet = $this->objJson->decode($resp->getResponseBody($jsonData)); 139 GC_Utils::gfPrintLog('* json data check start'); 133 $body = $objReq->getResponseBody(); 134 $objRet = $this->objJson->decode($body); 135 136 $this->objLog->log('* json data check start'); 140 137 if (empty($objRet)) { 141 138 $arrErr = array( 142 139 'status' => OWNERSSTORE_STATUS_ERROR, 143 'errcode' => '', 144 ); 145 echo $this->objJson->encode($arrErr); 146 GC_Utils::gfPrintLog( 147 sprintf($errFormat, $arrErr['errcode'], serialize($resp)) 148 ); 140 'errcode' => OWNERSSTORE_ERR_AU_INVALID_JSON_DATA, 141 ); 142 echo $this->objJson->encode($arrErr); 143 $this->objLog->errLog($arrErr['errcode'], $objReq); 149 144 exit; 150 145 } 151 146 // ダウンロードデータの保存 152 147 if ($objRet->status === OWNERSSTORE_STATUS_SUCCESS) { 153 GC_Utils::gfPrintLog('* save file start');148 $this->objLog->log('* save file start'); 154 149 $time = time(); 155 150 $dir = DATA_PATH . 'downloads/tmp/'; … … 164 159 $arrErr = array( 165 160 'status' => OWNERSSTORE_STATUS_ERROR, 166 'errcode' => '',161 'errcode' => OWNERSSTORE_ERR_AU_FILE_WRITE, 167 162 ); 168 163 echo $this->objJson->encode($arrErr); 169 GC_Utils::gfPrintLog( 170 sprintf($errFormat, $arrErr['errcode'], serialize($dir . $filename)) 171 ); 164 $this->objLog->errLog($arrErr['errcode'], $dir . $filename); 172 165 exit; 173 166 } … … 177 170 $arrErr = array( 178 171 'status' => OWNERSSTORE_STATUS_ERROR, 179 'errcode' => '',172 'errcode' => OWNERSSTORE_ERR_AU_MKDIR, 180 173 ); 181 174 echo $this->objJson->encode($arrErr); 182 GC_Utils::gfPrintLog( 183 sprintf($errFormat, $arrErr['errcode'], serialize($exract_dir)) 184 ); 175 $this->objLog->errLog($arrErr['errcode'], $exract_dir); 185 176 exit; 186 177 } … … 193 184 $arrCopyLog = $objBatch->execute($exract_dir); 194 185 195 $this->notifyDownload($resp->getResponseCookies(), $objRet->product_data);196 186 // テーブルの更新 197 // $this->updateMdlTable($objRet); 187 $this->updateMdlTable($objRet->product_data); 188 // サーバへ通知 189 $this->notifyDownload($objReq->getResponseCookies()); 198 190 199 191 echo $this->objJson->encode(array('status' => OWNERSSTORE_STATUS_SUCCESS)); 200 GC_Utils::gfPrintLog('* file save ok');192 $this->objLog->log('* file save ok'); 201 193 exit; 202 194 } else { 203 echo $jsonData; 204 GC_Utils::gfPrintLog( 205 sprintf($errFormat, $objRet->errcode, serialize(array($resp, $objRet))) 206 ); 195 echo $body; 196 $this->objLog->errLog($objRet->errcode, array($objRet, $objReq)); 207 197 exit; 208 198 } … … 215 205 */ 216 206 function destroy() { 217 GC_Utils::gfPrintLog('###Auto Update End###');207 $this->objLog->end(); 218 208 } 219 209 … … 225 215 function updateMdlTable($objRet) { 226 216 $table = 'dtb_module'; 217 $where = 'module_id = ?'; 227 218 $objQuery = new SC_Query; 228 219 229 $count = $objQuery->count($ objRet, 'module_id=?', array($objRet->product_id));220 $count = $objQuery->count($table, $where, array($objRet->product_id)); 230 221 if ($count) { 231 $arrUpdate = array(); 232 $objQuery->update($table, $arrUpdate); 222 $arrUpdate = array( 223 'module_name' => $objRet->name, 224 'update_date' => 'NOW()' 225 ); 226 $objQuery->update($table, $arrUpdate ,$where, array($objRet->product_id)); 233 227 } else { 234 $arrInsert = array(); 228 $arrInsert = array( 229 'module_id' => $objRet->product_id, 230 'module_name' => $objRet->name, 231 'auto_update_flg' => '0', 232 'create_date' => 'NOW()', 233 'update_date' => 'NOW()' 234 ); 235 235 $objQuery->insert($table, $arrInsert); 236 236 } … … 245 245 */ 246 246 function notifyDownload($arrCookies) { 247 $objReq = new HTTP_Request(); 248 $objReq->setUrl('http://cube-shopaccount/upgrade/index.php'); 249 $objReq->setMethod('POST'); 250 $objReq->addPostData('mode', 'download_log'); 251 252 // Cookie追加 253 foreach ($arrCookies as $cookie) { 254 $objReq->addCookie($cookie['name'], $cookie['value']); 255 } 256 257 $e = $objReq->sendRequest(); 258 } 259 260 /** 261 * ロックオンからのアクセスかどうかを確認する. 262 * 263 * @return boolesan 264 */ 265 function isValidIP() { 266 if (isset($_SERVER['REMOTE_ADDR']) 267 && $_SERVER['REMOTE_ADDR'] == '127.0.0.1') { 268 269 return true; 270 } 271 272 return false; 247 $objReq = LC_Utils_Upgrade::request('download_log', array(), $arrCookies); 248 249 return true; 273 250 } 274 251 … … 281 258 $product_id = $this->objForm->getValue('product_id'); 282 259 283 $where = ' product_id = ?';260 $where = 'module_id = ?'; 284 261 $objQuery = new SC_Query(); 285 262 $arrRet = $objQuery->select('auto_update_flg', 'dtb_module', $where, array($product_id));
Note: See TracChangeset
for help on using the changeset viewer.