Subtitles::delete PHP Method

delete() public method

public delete ( $id, $reason = '' )
    public function delete($id, $reason = '')
    {
        $subtitle = $this->get($id);
        if ($this->user->getClass() < User::CLASS_ADMIN && $this->user->getId() != $subtitle["userid"]) {
            throw new Exception(L::get("PERMISSION_DENIED"), 404);
        }
        $this->db->query('DELETE FROM subs WHERE id = ' . $subtitle["id"]);
        $sth = $this->db->query("SELECT COUNT(*) FROM subs WHERE torrentid = " . $subtitle["torrentid"]);
        $res = $sth->fetch();
        if ($res[0] == 0) {
            $this->db->query('UPDATE torrents SET swesub = 0 WHERE id = ' . $subtitle["torrentid"]);
        }
        @unlink($this->subsDir . $subtitle["filnamn"]);
        $anonymous = 1;
        if ($subtitle["userid"] != $this->user->getId()) {
            $user = $this->user->get($subtitle["userid"]);
            if ($user) {
                $torrent = $this->torrent->get($subtitle["torrentid"]);
                $subject = L::get("SUBTITLE_DELETED_PM_SUBJECT", null, $user["language"]);
                $message = L::get("SUBTITLE_DELETED_PM_BODY", [$subtitle["filnamn"], $torrent["id"], $torrent["name"], $torrent["name"], $reason], $user["language"]);
                $this->mailbox->sendSystemMessage($user["id"], $subject, $message);
                $anonymous = 0;
            }
        }
        $this->log->log(3, L::get("SUBTITLE_DELETED_SITE_LOG", [$subtitle["filnamn"], $reason ?: "-"], Config::DEFAULT_LANGUAGE), $this->user->getId(), $anonymous);
    }

Usage Example

コード例 #1
0
ファイル: api-v1.php プロジェクト: lordgabber/rartracker
     $subtitles = new Subtitles($db, $user);
     httpResponse($subtitles->fetch($_GET["torrentid"]));
     break;
 case validateRoute('POST', 'subtitles'):
     $torrent = new Torrent($db, $user);
     $log = new Logs($db);
     $mailbox = new Mailbox($db, $user);
     $subtitles = new Subtitles($db, $user, $log, $torrent, $mailbox);
     httpResponse($subtitles->upload($_FILES["file"], $_POST));
     break;
 case validateRoute('DELETE', 'subtitles/\\d+'):
     $log = new Logs($db);
     $torrent = new Torrent($db, $user);
     $mailbox = new Mailbox($db, $user);
     $subtitles = new Subtitles($db, $user, $log, $torrent, $mailbox);
     httpResponse($subtitles->delete((int) $params[1], $_GET["reason"]));
     break;
 case validateRoute('GET', 'donations'):
     $donations = new Donations($db, $user);
     list($result, $totalCount) = $donations->query(array("limit" => $_GET["limit"], "index" => $_GET["index"]));
     httpResponse($result, $totalCount);
     break;
 case validateRoute('POST', 'donations'):
     $donate = new Donations($db, $user);
     httpResponse($donate->create($postdata));
     break;
 case validateRoute('PATCH', 'donations/\\d+'):
     $donate = new Donations($db, $user);
     httpResponse($donate->update((int) $params[1], $postdata));
     break;
 case validateRoute('DELETE', 'donations/\\d+'):