summaryrefslogtreecommitdiffstats
path: root/application/models
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-10-10 20:57:15 +0200
committerFlorian Pritz <bluewind@xinu.at>2014-10-10 20:57:15 +0200
commitdbb2247b82ab49c50f424c904ac98702507f1a8e (patch)
tree8de007c3f61f621b02ecb93d4a2730e00d79c613 /application/models
parentba760ba7280265cb49e38a2b039c42d5bdfd6b9d (diff)
parentc902a13c01583e83fda7f8188130e01f2d3bb141 (diff)
Merge remote-tracking branch 'rafi/master' into rafi
Diffstat (limited to 'application/models')
-rw-r--r--application/models/mfile.php99
-rw-r--r--application/models/mmultipaste.php8
-rw-r--r--application/models/muser.php41
3 files changed, 77 insertions, 71 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index f23855bfd..be315b9e6 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -49,12 +49,11 @@ class Mfile extends CI_Model {
return false;
}
- $sql = '
- SELECT id
- FROM `files`
- WHERE `id` = ?
- LIMIT 1';
- $query = $this->db->query($sql, array($id));
+ $query = $this->db->select('id')
+ ->from('files')
+ ->where('id', $id)
+ ->limit(1)
+ ->get();
if ($query->num_rows() == 1) {
return true;
@@ -70,12 +69,12 @@ class Mfile extends CI_Model {
function get_filedata($id)
{
- $sql = '
- SELECT id, hash, filename, mimetype, date, user, filesize
- FROM `files`
- WHERE `id` = ?
- LIMIT 1';
- $query = $this->db->query($sql, array($id));
+ $query = $this->db
+ ->select('id, hash, filename, mimetype, date, user, filesize')
+ ->from('files')
+ ->where('id', $id)
+ ->limit(1)
+ ->get();
if ($query->num_rows() > 0) {
return $query->row_array();
@@ -125,11 +124,9 @@ class Mfile extends CI_Model {
{
$userid = $this->muser->get_userid();
- $this->db->query("
- UPDATE files
- SET user = ?
- WHERE id = ?
- ", array($userid, $id));
+ $this->db->set(array('user' => $userid ))
+ ->where('id', $id)
+ ->update('files');
}
// remove old/invalid/broken IDs
@@ -200,12 +197,11 @@ class Mfile extends CI_Model {
private function unused_file($hash)
{
- $sql = '
- SELECT id
- FROM `files`
- WHERE `hash` = ?
- LIMIT 1';
- $query = $this->db->query($sql, array($hash));
+ $query = $this->db->select('id')
+ ->from('files')
+ ->where('hash', $hash)
+ ->limit(1)
+ ->get();
if ($query->num_rows() == 0) {
return true;
@@ -222,13 +218,18 @@ class Mfile extends CI_Model {
// Note that this does not delete all relations in multipaste_file_map
// which is actually done by a SQL contraint.
// TODO: make it work properly without the constraint
- $this->db->query('
- DELETE m, mfm, f
- FROM files f
- LEFT JOIN multipaste_file_map mfm ON f.id = mfm.file_url_id
- LEFT JOIN multipaste m ON mfm.multipaste_id = m.multipaste_id
- WHERE f.id = ?
- ', array($id));
+ $map = $this->db->select('multipaste_id')
+ ->from('multipaste_file_map')
+ ->where('file_url_id', $id)
+ ->get()->row_array();
+
+ $this->db->where('id', $id)
+ ->delete('files');
+
+ if ( ! empty($map['multipaste_id'])) {
+ $this->db->where('multipaste_id', $map['multipaste_id'])
+ ->delete('multipaste');
+ }
if ($this->id_exists($id)) {
return false;
@@ -253,13 +254,27 @@ class Mfile extends CI_Model {
// Note that this does not delete all relations in multipaste_file_map
// which is actually done by a SQL contraint.
// TODO: make it work properly without the constraint
- $this->db->query('
- DELETE m, mfm, f
- FROM files f
- LEFT JOIN multipaste_file_map mfm ON f.id = mfm.file_url_id
- LEFT JOIN multipaste m ON mfm.multipaste_id = m.multipaste_id
- WHERE f.hash = ?
- ', array($hash));
+ $file = $this->db->select('id')
+ ->from('files')
+ ->where('hash', $hash)
+ ->get()->row_array();
+
+ if (empty($file['id'])) {
+ return false;
+ }
+
+ $map = $this->db->select('multipaste_id')
+ ->from('multipaste_file_map')
+ ->where('file_url_id', $file['id'])
+ ->get()->row_array();
+
+ $this->db->where('hash', $hash)
+ ->delete('files');
+
+ if ( ! empty($map['multipaste_id'])) {
+ $this->db->where('multipaste_id', $map['multipaste_id'])
+ ->delete('multipaste');
+ }
if (file_exists($this->file($hash))) {
unlink($this->file($hash));
@@ -273,11 +288,11 @@ class Mfile extends CI_Model {
public function get_owner($id)
{
- return $this->db->query("
- SELECT user
- FROM files
- WHERE id = ?
- ", array($id))->row_array()["user"];
+ return $this->db->select('user')
+ ->from('files')
+ ->where('id', $id)
+ ->get()->row_array()
+ ['user'];
}
public function get_lexers() {
diff --git a/application/models/mmultipaste.php b/application/models/mmultipaste.php
index 723132a50..367e74787 100644
--- a/application/models/mmultipaste.php
+++ b/application/models/mmultipaste.php
@@ -90,12 +90,8 @@ class Mmultipaste extends CI_Model {
public function delete_id($id)
{
- $this->db->query('
- DELETE m, mfm
- FROM multipaste m
- LEFT JOIN multipaste_file_map mfm ON mfm.multipaste_id = m.multipaste_id
- WHERE m.url_id = ?
- ', array($id));
+ $this->db->where('url_id', $id)
+ ->delete('multipaste');
if ($this->id_exists($id)) {
return false;
diff --git a/application/models/muser.php b/application/models/muser.php
index a1d8f18e5..ffcc5f6b3 100644
--- a/application/models/muser.php
+++ b/application/models/muser.php
@@ -97,17 +97,16 @@ class Muser extends CI_Model {
// get rid of spaces and newlines
$apikey = trim($apikey);
- $query = $this->db->query("
- SELECT a.user userid, a.access_level
- FROM apikeys a
- WHERE a.key = ?
- ", array($apikey))->row_array();
+ $query = $this->db->select('user, access_level')
+ ->from('apikeys')
+ ->where('key', $apikey)
+ ->get()->row_array();
- if (isset($query["userid"])) {
+ if (isset($query["user"])) {
$this->session->set_userdata(array(
'logged_in' => true,
'username' => '',
- 'userid' => $query["userid"],
+ 'userid' => $query["user"],
'access_level' => $query["access_level"],
));
return true;
@@ -205,12 +204,10 @@ class Muser extends CI_Model {
function get_action($action, $key)
{
- $query = $this->db->query("
- SELECT *
- FROM actions
- WHERE `key` = ?
- AND `action` = ?
- ", array($key, $action))->row_array();
+ $query = $this->db->from('actions')
+ ->where('key', $key)
+ ->where('action', $action)
+ ->get()->row_array();
if (!isset($query["key"]) || $key != $query["key"]) {
show_error("Invalid action key");
@@ -228,11 +225,10 @@ class Muser extends CI_Model {
"upload_id_limits" => $this->default_upload_id_limits,
);
- $query = $this->db->query("
- SELECT ".implode(", ", array_keys($fields))."
- FROM `profiles`
- WHERE user = ?
- ", array($userid))->row_array();
+ $query = $this->db->select(implode(', ', array_keys($fields)))
+ ->from('profiles')
+ ->where('user', $userid)
+ ->get()->row_array();
$extra_fields = array(
"username" => $this->get_username(),
@@ -262,11 +258,10 @@ class Muser extends CI_Model {
{
$userid = $this->get_userid();
- $query = $this->db->query("
- SELECT upload_id_limits
- FROM `profiles`
- WHERE user = ?
- ", array($userid))->row_array();
+ $query = $this->db->select('upload_id_limits')
+ ->from('profiles')
+ ->where('user', $userid)
+ ->get()->row_array();
if (empty($query)) {
return explode("-", $this->default_upload_id_limits);