/** * @return string */ public static function listUsers(Database &$database) { $query = $database->query('SELECT name, email FROM users'); $table = '<table><tr><th>Name</th><th>E-mail</th></tr>'; while ($value = $query->fetch(Database::FETCH_BOTH)) { $table .= '<tr><td>' . $value[0] . '</td><td>' . $value[1] . '</td></tr>'; } $table .= '</table>'; return $table; }
// Log the process output if available $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); if ("{$stdout}{$stderr}") { $method = $stderr ? 'error' : 'info'; Log::$method(sprintf('Output captured from command line: %s', $process['command']), array_filter(array('stdout' => $stdout, 'stderr' => $stderr))); unset($method); } unset($stdout, $stderr); // Handles cleanup after process exit switch (strtolower($process['type'])) { // Permanent processes will be restarted upon death case 'permanent': core\Database::query('UPDATE `' . FRAMEWORK_COLLECTION_PROCESS . '` SET `pid` = NULL WHERE `id` = ?', $process['id']); Log::debug('Permanent process died, clearing pid.', [$res, $process]); break; // Sets pid to 0, prevents it fire again and double enqueue of the same time slot. // Sets pid to 0, prevents it fire again and double enqueue of the same time slot. case 'cron': core\Database::query('UPDATE `' . FRAMEWORK_COLLECTION_PROCESS . '` SET `pid` = 0 WHERE `id` = ?', $process['id']); break; // Deletes the process object upon exit // Deletes the process object upon exit default: $process = array_select($process, array(Node::FIELD_COLLECTION, 'id', 'pid')); $res = Node::delete($process); Log::debug("Deleting finished process, affected rows: {$res}.", [$res, $process]); break; } // Recursive process, spawn another worker. Process::spawnWorker(@$_SERVER['env']);
/** * Logout function, application terminating point. */ static function invalidate($sid = null) { if ($sid === null) { $sid = static::$currentSession['sid']; } $sid = util::packUuid($sid); $session = Node::getOne(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_SESSION, 'sid' => $sid)); Database::query('DELETE FROM `' . FRAMEWORK_COLLECTION_SESSION . '` WHERE `sid` = ?', array($sid)); Log::info(sprintf('Session invalidated', $session)); /* Clear reference */ static::$currentSession = null; }