cleaned up some queries
This commit is contained in:
parent
d8e3b5b0a0
commit
e679b342bd
12 changed files with 33 additions and 44 deletions
|
@ -26,13 +26,11 @@ class ActionCode
|
|||
|
||||
// Insert it
|
||||
DB::table('actioncodes')
|
||||
->insert(
|
||||
[
|
||||
'code_action' => $action,
|
||||
'user_id' => $user,
|
||||
'action_code' => $code,
|
||||
]
|
||||
);
|
||||
->insert([
|
||||
'code_action' => $action,
|
||||
'user_id' => $user,
|
||||
'action_code' => $code,
|
||||
]);
|
||||
|
||||
// Return the code
|
||||
return $code;
|
||||
|
|
|
@ -82,12 +82,10 @@ class Comment
|
|||
// Get comment data from the database
|
||||
$data = DB::table('comments')
|
||||
->where('comment_id', $id)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Check if anything was returned and assign data
|
||||
if ($data) {
|
||||
$data = $data[0];
|
||||
|
||||
$this->id = $data->comment_id;
|
||||
$this->category = $data->comment_category;
|
||||
$this->time = $data->comment_timestamp;
|
||||
|
|
|
@ -96,11 +96,10 @@ class File
|
|||
// Attempt to get the database row
|
||||
$fileRow = DB::table('uploads')
|
||||
->where('file_id', $fileId)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// If anything was returned populate the variables
|
||||
if ($fileRow) {
|
||||
$fileRow = $fileRow[0];
|
||||
$this->id = $fileRow->file_id;
|
||||
$this->user = User::construct($fileRow->user_id);
|
||||
$this->data = file_get_contents(ROOT . config('file.uploads_dir') . $fileRow->file_id . ".bin");
|
||||
|
@ -116,7 +115,11 @@ class File
|
|||
*/
|
||||
public function delete()
|
||||
{
|
||||
unlink(ROOT . config('file.uploads_dir') . $this->id . ".bin");
|
||||
$filename = ROOT . config('file.uploads_dir') . $this->id . ".bin";
|
||||
|
||||
if (file_exists($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
DB::table('uploads')
|
||||
->where('file_id', $this->id)
|
||||
|
|
|
@ -103,14 +103,13 @@ class Forum
|
|||
// Get the row from the database
|
||||
$forumRow = DB::table('forums')
|
||||
->where('forum_id', $forumId)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Create permissions object
|
||||
$this->permissionsCache = new Perms(Perms::FORUM);
|
||||
|
||||
// Populate the variables
|
||||
if ($forumRow) {
|
||||
$forumRow = $forumRow[0];
|
||||
$this->id = intval($forumRow->forum_id);
|
||||
$this->order = intval($forumRow->forum_order);
|
||||
$this->name = $forumRow->forum_name;
|
||||
|
@ -223,10 +222,10 @@ class Forum
|
|||
->where('forum_id', $this->id)
|
||||
->orderBy('post_id')
|
||||
->limit(1)
|
||||
->get(['post_id']);
|
||||
->first(['post_id']);
|
||||
|
||||
// Create the post object
|
||||
$post = new Post(empty($firstPost) ? 0 : $firstPost[0]->post_id);
|
||||
$post = new Post($firstPost->post_id ?? 0);
|
||||
|
||||
// Assign it to a "cache" variable
|
||||
$this->firstPostCache = $post;
|
||||
|
@ -251,10 +250,10 @@ class Forum
|
|||
->where('forum_id', $this->id)
|
||||
->orderBy('post_id', 'desc')
|
||||
->limit(1)
|
||||
->get(['post_id']);
|
||||
->first(['post_id']);
|
||||
|
||||
// Create the post object
|
||||
$post = new Post(empty($lastPost) ? 0 : $lastPost[0]->post_id);
|
||||
$post = new Post($lastPost->post_id ?? 0);
|
||||
|
||||
// Assign it to a "cache" variable
|
||||
$this->lastPostCache = $post;
|
||||
|
|
|
@ -100,11 +100,10 @@ class Post
|
|||
// Attempt to get the database row
|
||||
$postRow = DB::table('posts')
|
||||
->where('post_id', $postId)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Assign data if a row was returned
|
||||
if ($postRow) {
|
||||
$postRow = $postRow[0];
|
||||
$this->id = intval($postRow->post_id);
|
||||
$this->topic = intval($postRow->topic_id);
|
||||
$this->forum = intval($postRow->forum_id);
|
||||
|
|
|
@ -113,11 +113,10 @@ class Topic
|
|||
// Attempt to get the database row
|
||||
$topicRow = DB::table('topics')
|
||||
->where('topic_id', $topicId)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Assign data if a row was returned
|
||||
if ($topicRow) {
|
||||
$topicRow = $topicRow[0];
|
||||
$this->id = intval($topicRow->topic_id);
|
||||
$this->forum = intval($topicRow->forum_id);
|
||||
$this->hidden = boolval($topicRow->topic_hidden);
|
||||
|
@ -262,10 +261,10 @@ class Topic
|
|||
->where('topic_id', $this->id)
|
||||
->orderBy('post_id')
|
||||
->limit(1)
|
||||
->get(['post_id']);
|
||||
->first(['post_id']);
|
||||
|
||||
// Create the post class
|
||||
$post = new Post($post ? $post[0]->post_id : 0);
|
||||
$post = new Post($post->post_id ?? 0);
|
||||
|
||||
// Assign it to the cache var
|
||||
$this->firstPostCache = $post;
|
||||
|
@ -290,10 +289,10 @@ class Topic
|
|||
->where('topic_id', $this->id)
|
||||
->orderBy('post_id', 'desc')
|
||||
->limit(1)
|
||||
->get(['post_id']);
|
||||
->first(['post_id']);
|
||||
|
||||
// Create the post class
|
||||
$post = new Post($post ? $post[0]->post_id : 0);
|
||||
$post = new Post($post->post_id ?? 0);
|
||||
|
||||
// Assign it to the cache var
|
||||
$this->lastPostCache = $post;
|
||||
|
|
|
@ -79,12 +79,10 @@ class Post
|
|||
// Get comment data from the database
|
||||
$data = DB::table('news')
|
||||
->where('news_id', $id)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Check if anything was returned and assign data
|
||||
if ($data) {
|
||||
$data = $data[0];
|
||||
|
||||
$this->id = $data->news_id;
|
||||
$this->category = $data->news_category;
|
||||
$this->user = $data->user_id;
|
||||
|
|
|
@ -76,12 +76,10 @@ class Notification
|
|||
// Get notification data from the database
|
||||
$data = DB::table('notifications')
|
||||
->where('alert_id', $id)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Check if anything was returned and assign data
|
||||
if ($data) {
|
||||
$data = $data[0];
|
||||
|
||||
$this->id = intval($data->alert_id);
|
||||
$this->user = intval($data->user_id);
|
||||
$this->time = intval($data->alert_timestamp);
|
||||
|
|
|
@ -103,11 +103,10 @@ class Rank
|
|||
// Get the rank database row
|
||||
$rankRow = DB::table('ranks')
|
||||
->where('rank_id', $rankId)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Check if the rank actually exists
|
||||
if ($rankRow) {
|
||||
$rankRow = $rankRow[0];
|
||||
$this->id = $rankRow->rank_id;
|
||||
$this->name = $rankRow->rank_name;
|
||||
$this->hierarchy = $rankRow->rank_hierarchy;
|
||||
|
|
|
@ -113,7 +113,7 @@ class Session
|
|||
$session = DB::table('sessions')
|
||||
->where('user_id', $this->userId)
|
||||
->where('session_key', $this->sessionId)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
// Check if we actually got something in return
|
||||
if (!$session) {
|
||||
|
@ -121,7 +121,7 @@ class Session
|
|||
}
|
||||
|
||||
// Check if the session expired
|
||||
if ($session[0]->session_expire < time()) {
|
||||
if ($session->session_expire < time()) {
|
||||
// ...and return false
|
||||
return 0;
|
||||
}
|
||||
|
@ -130,13 +130,13 @@ class Session
|
|||
good thing is i can probably do CIDR based checking */
|
||||
|
||||
// If the remember flag is set extend the session time
|
||||
if ($session[0]->session_remember) {
|
||||
if ($session->session_remember) {
|
||||
DB::table('sessions')
|
||||
->where('session_id', $session[0]->session_id)
|
||||
->update(['session_expire' => time() + 604800]);
|
||||
}
|
||||
|
||||
// Return 2 if the remember flag is set and return 1 if not
|
||||
return $session[0]->session_remember ? 2 : 1;
|
||||
return $session->session_remember ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class Template
|
|||
$key = basename($dir);
|
||||
|
||||
if ($key === self::$name) {
|
||||
$key = '__main__';
|
||||
$loader->addPath($dir, '__main__');
|
||||
}
|
||||
|
||||
$loader->addPath($dir, $key);
|
||||
|
|
|
@ -292,12 +292,11 @@ class User
|
|||
// Get the user database row
|
||||
$userRow = DB::table('users')
|
||||
->where('user_id', $userId)
|
||||
->orWhere('username_clean', clean_string($userId, true, true))
|
||||
->get();
|
||||
->orWhere('username_clean', clean_string($userId, true))
|
||||
->first();
|
||||
|
||||
// Populate the variables
|
||||
if ($userRow) {
|
||||
$userRow = $userRow[0];
|
||||
$this->id = intval($userRow->user_id);
|
||||
$this->username = $userRow->username;
|
||||
$this->usernameClean = $userRow->username_clean;
|
||||
|
@ -500,7 +499,6 @@ class User
|
|||
->where('poster_id', $this->id)
|
||||
->distinct()
|
||||
->groupBy('topic_id')
|
||||
->orderBy('post_time')
|
||||
->count();
|
||||
|
||||
return [
|
||||
|
|
Reference in a new issue