summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-02-19 22:36:29 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-02-19 22:36:29 +0100
commit0443d0829ab7e2d30825fded2f172b74d26b5b3c (patch)
tree0d6823082f2803ac732d448e9f1c0ca29dcab44f
parent00c600799d074ee9f52cf8e788cf6ff588b89e39 (diff)
Add claiming of multipastes
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/file.php11
-rw-r--r--application/models/mfile.php2
-rw-r--r--application/models/mmultipaste.php11
3 files changed, 19 insertions, 5 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index fd7eb9962..6a14fceee 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -813,6 +813,7 @@ class File extends MY_Controller {
}
if ($multipaste !== false) {
+ $userid = $this->muser->get_userid();
$ids[] = \service\files::create_multipaste($ids, $userid, $limits)["url_id"];
}
@@ -835,17 +836,17 @@ class File extends MY_Controller {
assert(is_array($ids));
foreach ($ids as $key => $id) {
- $filedata = $this->mfile->get_filedata($id);
+ $affected = 0;
+ $affected += $this->mfile->adopt($id);
+ $affected += $this->mmultipaste->adopt($id);
- if ($filedata["user"] != 0) {
+ if ($affected == 0) {
$errors[] = $id;
}
-
- $this->mfile->adopt($id);
}
if (!empty($errors)) {
- throw new \exceptions\PublicApiException("file/claim_id/already-owned", "Someone already owns '".implode(", ", $errors)."', can't reassign.");
+ throw new \exceptions\PublicApiException("file/claim_id/failed", "Failed to claim ".implode(", ", $errors)."");
}
$this->session->unset_userdata("last_upload");
diff --git a/application/models/mfile.php b/application/models/mfile.php
index 0ec27a817..51c865900 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -126,7 +126,9 @@ class Mfile extends CI_Model {
$this->db->set(array('user' => $userid ))
->where('id', $id)
+ ->where('user', 0)
->update('files');
+ return $this->db->affected_rows();
}
// remove old/invalid/broken IDs
diff --git a/application/models/mmultipaste.php b/application/models/mmultipaste.php
index ed3b8e3a7..f80105ec9 100644
--- a/application/models/mmultipaste.php
+++ b/application/models/mmultipaste.php
@@ -88,6 +88,17 @@ class Mmultipaste extends CI_Model {
return true;
}
+ function adopt($id)
+ {
+ $userid = $this->muser->get_userid();
+
+ $this->db->set(array('user_id' => $userid ))
+ ->where('url_id', $id)
+ ->where('user_id', 0)
+ ->update('multipaste');
+ return $this->db->affected_rows();
+ }
+
public function get_tarball_path($id)
{
return $this->config->item("upload_path")."/special/multipaste-tarballs/".substr(md5($id), 0, 3)."/$id.tar.gz";