当前位置: 首页>>代码示例>>PHP>>正文


PHP moodle_database::update_record方法代码示例

本文整理汇总了PHP中moodle_database::update_record方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_database::update_record方法的具体用法?PHP moodle_database::update_record怎么用?PHP moodle_database::update_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在moodle_database的用法示例。


在下文中一共展示了moodle_database::update_record方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handler_read

 /**
  * Read session handler
  *
  * {@see http://php.net/manual/en/function.session-set-save-handler.php}
  *
  * @param string $sid
  * @return string
  */
 public function handler_read($sid)
 {
     global $CFG;
     if ($this->record and $this->record->sid != $sid) {
         error_log('Weird error reading database session - mismatched sid');
         $this->failed = true;
         return '';
     }
     try {
         // Do not fetch full record yet, wait until it is locked.
         if (!($record = $this->database->get_record('sessions', array('sid' => $sid), 'id, userid'))) {
             $record = new stdClass();
             $record->state = 0;
             $record->sid = $sid;
             $record->sessdata = null;
             $record->userid = 0;
             $record->timecreated = $record->timemodified = time();
             $record->firstip = $record->lastip = getremoteaddr();
             $record->id = $this->database->insert_record_raw('sessions', $record);
         }
     } catch (Exception $ex) {
         // do not rethrow exceptions here, we need this to work somehow before 1.9.x upgrade and during install
         error_log('Can not read or insert database sessions');
         $this->failed = true;
         return '';
     }
     try {
         if (!empty($CFG->sessionlockloggedinonly) and (isguestuser($record->userid) or empty($record->userid))) {
             // No session locking for guests and not-logged-in users,
             // these users mostly read stuff, there should not be any major
             // session race conditions. Hopefully they do not access other
             // pages while being logged-in.
         } else {
             $this->database->get_session_lock($record->id, SESSION_ACQUIRE_LOCK_TIMEOUT);
         }
     } catch (Exception $ex) {
         // This is a fatal error, better inform users.
         // It should not happen very often - all pages that need long time to execute
         // should close session soon after access control checks
         error_log('Can not obtain session lock');
         $this->failed = true;
         throw $ex;
     }
     // Finally read the full session data because we know we have the lock now.
     if (!($record = $this->database->get_record('sessions', array('id' => $record->id)))) {
         error_log('Cannot read session record');
         $this->failed = true;
         return '';
     }
     // verify timeout
     if ($record->timemodified + $CFG->sessiontimeout < time()) {
         $ignoretimeout = false;
         if (!empty($record->userid)) {
             // skips not logged in
             if ($user = $this->database->get_record('user', array('id' => $record->userid))) {
                 // Refresh session if logged as a guest
                 if (isguestuser($user)) {
                     $ignoretimeout = true;
                 } else {
                     $authsequence = get_enabled_auth_plugins();
                     // auths, in sequence
                     foreach ($authsequence as $authname) {
                         $authplugin = get_auth_plugin($authname);
                         if ($authplugin->ignore_timeout_hook($user, $record->sid, $record->timecreated, $record->timemodified)) {
                             $ignoretimeout = true;
                             break;
                         }
                     }
                 }
             }
         }
         if ($ignoretimeout) {
             //refresh session
             $record->timemodified = time();
             try {
                 $this->database->update_record('sessions', $record);
             } catch (Exception $ex) {
                 // very unlikely error
                 error_log('Can not refresh database session');
                 $this->failed = true;
                 throw $ex;
             }
         } else {
             //time out session
             $record->state = 0;
             $record->sessdata = null;
             $record->userid = 0;
             $record->timecreated = $record->timemodified = time();
             $record->firstip = $record->lastip = getremoteaddr();
             try {
                 $this->database->update_record('sessions', $record);
             } catch (Exception $ex) {
//.........这里部分代码省略.........
开发者ID:neogic,项目名称:moodle,代码行数:101,代码来源:sessionlib.php


注:本文中的moodle_database::update_record方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。