示例#1
0
 /**
  * Writes current values for user back to the database.
  *
  * @return bool true on success or false on failure
  *
  * @access private
  */
 function _updateUserData()
 {
     if (!array_key_exists('lastlogin', $this->tables['users']['fields'])) {
         return true;
     }
     $index = 0;
     foreach ($this->userObj->children as $value) {
         if ($value->name == $this->alias['lastlogin']) {
             $el =& $this->userObj->getElement(array($index));
             $el->setContent($this->currentLogin);
         }
         $index++;
     }
     $success = false;
     do {
         if (!is_writable($this->file)) {
             $errorMsg = 'Auth freeze failure. Cannot write to the xml file';
             break;
         }
         $fp = fopen($this->file, 'wb');
         if (!$fp) {
             $errorMsg = "Auth freeze failure. Failed to open the xml file.";
             break;
         }
         if (!flock($fp, LOCK_EX)) {
             $errorMsg = "Auth freeze failure. Couldn't get an exclusive lock on the file.";
             break;
         }
         if (!fwrite($fp, $this->tree->get())) {
             $errorMsg = "Auth freeze failure. Write error when writing back the file.";
             break;
         }
         @fflush($fp);
         $success = true;
     } while (false);
     @flock($fp, LOCK_UN);
     @fclose($fp);
     if (!$success) {
         $this->stack->push(LIVEUSER_ERROR, 'exception', array(), 'Cannot read XML Auth file: ' . $errorMsg);
     }
     return $success;
 }