function set_last_action($timestamp = 0) { if ($this->id && $this->id != 'nobody') { if ($timestamp <= 0) { if (time() - $this->last_online_time < 180) { return 0; } $timestamp = time(); } try { $query = "INSERT INTO user_online (user_id, last_lifesign)\n VALUES (:user_id, UNIX_TIMESTAMP() - :time_delta)\n ON DUPLICATE KEY UPDATE last_lifesign = UNIX_TIMESTAMP() - :time_delta"; $stmt = DBManager::get()->prepare($query); $stmt->bindValue(':user_id', $this->id); $stmt->bindValue(':time_delta', time() - $timestamp, PDO::PARAM_INT); $stmt->execute(); } catch (PDOException $e) { require_once 'lib/migrations/db_schema_version.php'; $version = new DBSchemaVersion('studip'); if ($version->get() < 98) { Log::ALERT('Seminar_User::set_last_action() failed. Check migration no. 98!'); } else { throw $e; } } return $stmt->rowCount(); } }
/** * get the number of currently online users * * @param int $active_time filter: the time in minutes until last life-sign * * @return int */ function get_users_online_count($active_time = 5) { $cache = StudipCacheFactory::getCache(); $online_count = $cache->read('online_count'); if ($online_count === false) { $query = "SELECT COUNT(*) FROM user_online\n WHERE last_lifesign > ?"; $statement = DBManager::get()->prepare($query); try { $statement->execute(array(time() - $active_time * 60)); } catch (PDOException $e) { require_once 'lib/migrations/db_schema_version.php'; $version = new DBSchemaVersion('studip'); if ($version->get() < 98) { Log::ALERT('get_users_online_count() failed. Check migration no. 98!'); } else { throw $e; } } $online_count = $statement->fetchColumn(); $cache->write('online_count', $online_count, 180); } if ($GLOBALS['user']->id && $GLOBALS['user']->id != 'nobody') { --$online_count; } return $online_count > 0 ? $online_count : 0; }
$_SESSION['_language'] = get_accepted_languages(); } $_language_path = init_i18n($_SESSION['_language']); include 'lib/include/html_head.inc.php'; $path = $GLOBALS['STUDIP_BASE_PATH'] . '/db/migrations'; $verbose = true; $target = NULL; FileLock::setDirectory($GLOBALS['TMP_PATH']); $lock = new FileLock('web-migrate'); if ($lock->isLocked() && Request::int('release_lock')) { $lock->release(); } if (Request::int('target')) { $target = (int) Request::int('target'); } $version = new DBSchemaVersion('studip'); $migrator = new Migrator($path, $version, $verbose); if (Request::submitted('start')) { ob_start(); set_time_limit(0); $lock->lock(array('timestamp' => time(), 'user_id' => $GLOBALS['user']->id)); $migrator->migrate_to($target); $lock->release(); $announcements = ob_get_clean(); $message = MessageBox::Success(_("Die Datenbank wurde erfolgreich migriert."), explode("\n", $announcements)); } $current = $version->get(); $migrations = $migrator->relevant_migrations($target); $template = $template_factory->open('web_migrate'); $template->set_attribute('current_page', _('Datenbank-Migration')); $template->set_attribute('current', $current);
/** * Fetch migration information plugins. This method * returns for each plugin: * current schema version and top migration version, if available. * * @return array */ public function getMigrationInfo() { $info = array(); $plugin_manager = PluginManager::getInstance(); $plugins = $plugin_manager->getPluginInfos(); $basepath = get_config('PLUGINS_PATH'); foreach ($plugins as $id => $plugin) { $plugindir = $basepath . '/' . $plugin['path'] . '/'; if (is_dir($plugindir . '/migrations')) { $schema_version = new DBSchemaVersion($plugin['name']); $migrator = new Migrator($plugindir . '/migrations', $schema_version); $info[$id]['migration_top_version'] = $migrator->top_version(); $info[$id]['schema_version'] = $schema_version->get(); } } return $info; }