Exemple #1
0
 /**
  * 解锁记录
  * @param boolean $noMatterByWho 是否无条件解锁(哪怕被其他人锁定)
  */
 public function unlock($noMatterByWho = false)
 {
     $where = $this->pkey;
     if ($noMatterByWho === false) {
         $where[$this->fieldName_lockmsg] = $this->lock->toString();
     }
     $nextId = \Sooh\DB\Base\SQLDefine::nextCircledInt($this->r[$this->fieldName_verid]);
     $dbDisk = $this->db();
     $tbDisk = $this->tbname();
     if ($this->cacheWhenVerIDIs) {
         $dbCache = $this->db(true);
         $tbCache = $this->tbname(true);
     }
     if ($this->cacheWhenVerIDIs == 0) {
         $ret = $dbDisk->updRecords($tbDisk, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => ''), $where);
         $unlocked = $ret == 1;
     } elseif ($this->cacheWhenVerIDIs == 1) {
         $ret = $dbCache->updRecords($tbCache, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => ''), $where);
         $unlocked = $ret == 1;
         if ($unlocked) {
             $dbDisk->updRecords($tbDisk, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => ''), $where);
         }
     } else {
         $ret = $dbCache->updRecords($tbCache, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => ''), $where);
         $unlocked = $ret == 1;
     }
     if ($unlocked) {
         $this->r[$this->fieldName_verid] = $nextId;
         $this->r[$this->fieldName_lockmsg] = '';
         return true;
     } else {
         error_log('unlock failed:' . implode("\n", \Sooh\DB\Broker::lastCmd(false)));
         return false;
     }
 }