============================================================== CTblHist から CDDriver へコード移転 [1] -------------------------------------------------------------- class CTblHist extends CTblBase { const TBL_NAME = "hist"; const ID_NAME = "hist_id"; public function __construct( $prt ) { parent::__construct( $prt ); => $cfg = CEnv::config("poll/block"); => $this->sig_expire = $this->getSigExpire($cfg); } => private function getSigExpire( $cfg ) { => if ( empty($cfg["sig-expire"]) ) { return 0; } => $days = $cfg["sig-expire"]; => return ( substr($days,-1) == "s" ) ? => intval(substr($days,0,-1)) : => intval($days)*(60*60*24); => } -------------------------------------------------------------- add "getSigExpireInterval" to CDDriver class CDDriver { public function getSigExpireInterval() { $cfg = CEnv::config("poll/block"); if ( empty($cfg["sig-expire"]) ) { return 0; } $days = $cfg["sig-expire"]; return ( substr($days,-1) == "s" ) ? intval(substr($days,0,-1)) : intval($days)*(60*60*24); } } ============================================================== CTblHist から CDDriver へコード移転 [2] -------------------------------------------------------------- public function expire( $data ) { => if ( $this->sig_expire <= 0 ) { return; } => $now = $this->prt->getDateTime(); => $str_limit = $this->prt->getDateTimeStr($now-$this->sig_expire); //-- delete expired records $clx = array(); $clx[] = CSql::clDelete(self::TBL_NAME); $cond = array(); $cond[] = CSql::clCond("dt_create","<",$str_limit); $clx[] = CSql::clWhere("AND",$cond); CSql::query($clx); } -------------------------------------------------------------- public function expire( $data, $threshold ) { $clx = array(); $clx[] = CSql::clDelete(self::TBL_NAME); $cond = array(); $cond[] = CSql::clCond("dt_create","<",$threshold); $clx[] = CSql::clWhere("AND",$cond); CSql::query($clx); } -------------------------------------------------------------- modify "expire" of CDDriver add "getSigExpireThreshold" to CDDriver class CDDriver { public function expire( $data ) { $threshold = $this->getSigExpireThreshold(); if ( is_null($threshold) ) { return; } $this->tbl_hist->expire($data,$threshold); } public function getSigExpireThreshold() { $interval = $this->getSigExpireInterval(); if ( $interval <= 0 ) { return null; } $now = $this->getDateTime(); return $this->getDateTimeStr($now-$interval); } } -------------------------------------------------------------- modify "expire" of CDDriver add "expire" to CTblVoter class CDDriver { public function expire( $data ) { $threshold = $this->getSigExpireThreshold(); if ( is_null($threshold) ) { return; } $this->tbl_hist->expire($data,$threshold); $this->tbl_voter->expire($data,$threshold); } } class CTblVoter extends CTblBase { public function getSigExpireThreshold() { $interval = $this->getSigExpireInterval(); if ( $interval <= 0 ) { return null; } $now = $this->getDateTime(); return $this->getDateTimeStr($now-$interval); } } -------------------------------------------------------------- add "expiration threshold" code to CTblVoter::findVoter add "expiration threshold" code to CTblHist::loadSelsx and CTblHist::loadSels //-- expiration threshold $threshold = $this->prt->getSigExpireThreshold(); if ( !is_null($threshold) ) { $cond[] = CSql::clCond("dt_create",">=",$threshold); } -------------------------------------------------------------- 驚くべきことに、CTblVoterは、最初のバージョンから、投票ごとにdt_createをアップデートしている。