/** * セッションのデータをDBに書き込む. * * @param string $id セッションID * @param string $sess_data セッションデータの値 * @return bool セッションの書き込みに成功した場合 true */ function write($id, $sess_data) { $id_key = $this->id_key; $data_key = $this->data_key; // セッションに値を設定 try { $insert = new Vizualizer_Query_Replace($this->table); $sqlval = array($id_key => $id, $data_key => $sess_data); $sqlval["create_time"] = $sqlval["update_time"] = Vizualizer_Data_Calendar::now()->date("Y-m-d H:i:s"); Vizualizer_Logger::writeDebug($insert->showQuery($sqlval)); $insert->execute($sqlval); return true; } catch (Exception $e) { return false; } }
/** * メッセージログを出力する。 * * @param string $prefix ログの種別 * @param string $message エラーメッセージ * @param Exception $exception エラーの原因となった例外オブジェクト */ private static function writeMessage($prefix, $message, $exception = null) { try { if (Vizualizer_Configure::get("site_code") !== null && Vizualizer_Configure::get("site_code") !== "") { $siteCode = self::$logFilePrefix . Vizualizer_Configure::get("site_code"); } else { $siteCode = self::$logFilePrefix . "default"; } // ログディレクトリが無い場合は自動的に作成 $logHome = Vizualizer_Configure::get("log_root") . DIRECTORY_SEPARATOR; if (!is_dir($logHome)) { mkdir($logHome); @chmod($logHome, 0777); } if (is_dir($logHome) && is_writable($logHome)) { // 現在のログファイルが10MB以上の場合ローテーションする。 if (file_exists($logHome . $siteCode . ".log") && filesize($logHome . $siteCode . ".log") > 1024 * 1024 * 10) { // 現行のログファイルをoldに移動させる。 if (($fp = fopen($logHome . $siteCode . ".log", "r")) !== FALSE) { if (flock($fp, LOCK_EX | LOCK_NB)) { @rename($logHome . $siteCode . ".log", $logHome . $siteCode . "_old.log"); flock($fp, LOCK_UN); fclose($fp); } if (file_exists($logHome . $siteCode . "_old.log")) { $logHistorys = Vizualizer_Configure::get("max_logs"); for ($index = $logHistorys - 1; $index > 0; $index--) { if (file_exists($logHome . $siteCode . "_" . $index . ".log")) { @rename($logHome . $siteCode . "_" . $index . ".log", $logHome . $siteCode . "_" . ($index + 1) . ".log"); } } @rename($logHome . $siteCode . "_old.log", $logHome . $siteCode . "_1.log"); } } } // ログファイルに記載 $logFile = $logHome . $siteCode . ".log"; if (($fp = fopen($logFile, "a+")) !== FALSE) { if (class_exists("VizualizerAdmin")) { $operator = Vizualizer_Session::get(VizualizerAdmin::SESSION_KEY); if (is_array($operator) && array_key_exists("operator_id", $operator) && $operator["operator_id"] > 0) { $prefix .= "][" . $operator["login_id"]; } } fwrite($fp, "[" . $_SERVER["SERVER_NAME"] . "][" . Vizualizer_Data_Calendar::now() . "][" . $prefix . "]" . $message . "\r\n"); if (self::$logOutputStandard) { echo "[" . $_SERVER["SERVER_NAME"] . "][" . Vizualizer_Data_Calendar::now() . "][" . $prefix . "]" . $message . "\r\n"; } if ($exception != null) { fwrite($fp, "[" . $_SERVER["SERVER_NAME"] . "][" . Vizualizer_Data_Calendar::now() . "][" . $prefix . "]" . $exception->getMessage() . "\r\n"); if (self::$logOutputStandard) { echo "[" . $_SERVER["SERVER_NAME"] . "][" . Vizualizer_Data_Calendar::now() . "][" . $prefix . "]" . $exception->getMessage() . "\r\n"; } fwrite($fp, "[" . $_SERVER["SERVER_NAME"] . "][" . Vizualizer_Data_Calendar::now() . "][" . $prefix . "]" . $exception->getTraceAsString()); if (self::$logOutputStandard) { echo "[" . $_SERVER["SERVER_NAME"] . "][" . Vizualizer_Data_Calendar::now() . "][" . $prefix . "]" . $exception->getTraceAsString(); } } fclose($fp); @chmod($logFile, 0666); } } } catch (Exception $e) { // エラーログ出力に失敗した場合は無限ネストの可能性があるため、例外を無効にする。 } }
/** * 登録日時や登録オペレータなどを設定する内部処理です。 */ protected function updateRegisterInfo() { // オペレータIDを設定する。 $this->updateOperatorInfo(); // データ作成日/更新日は自動的に設定する。 $this->create_time = $this->update_time = Vizualizer_Data_Calendar::now()->date("Y-m-d H:i:s"); }
/** * 指定したトランザクション内にて主キーベースでデータの保存を行う。 * 主キーが存在しない場合は何もしない。 * また、モデル内のカラムがDBに無い場合はスキップする。 * データ作成日/更新日は自動的に設定される。 */ public function saveAll($list) { // 主キーのデータが無かった場合はInsert $insert = new Vizualizer_Query_InsertIgnore($this->access); foreach ($list as $index => $data) { // データ作成日/更新日は自動的に設定する。 $data["create_time"] = $data["update_time"] = Vizualizer_Data_Calendar::now()->date("Y-m-d H:i:s"); $insert->execute($data); foreach ($this->primary_keys as $key) { if (empty($data[$key])) { $list[$index][$key] = $insert->lastInsertId(); } } } return $list; }