Beispiel #1
0
    /**
     * Hard delete a post
     */
    public function hard_delete()
    {
        if (!$this->topic->topic_posts) {
            if (!$this->topic->load($this->topic_id)) {
                return false;
            }
        }
        // Update the postcount for the topic
        $this->update_topic_postcount(true);
        // Set the visibility appropriately if no posts are visibile to the public/authors
        $flags = titania_count::get_flags(TITANIA_ACCESS_PUBLIC);
        if (titania_count::from_db($this->topic->topic_posts, $flags) <= 0) {
            // There are no posts visible to the public, change it to authors level access
            $this->topic->topic_access = TITANIA_ACCESS_AUTHORS;
            $flags = titania_count::get_flags(TITANIA_ACCESS_AUTHORS);
            if (titania_count::from_db($this->topic->topic_posts, $flags) <= 0) {
                // There are no posts visible to authors, change it to teams level access
                $this->topic->topic_access = TITANIA_ACCESS_TEAMS;
            }
        }
        // Sync the first topic post if required
        if ($this->post_id == $this->topic->topic_first_post_id) {
            $this->topic->sync_first_post($this->post_id);
        }
        // Sync the last topic post if required
        if ($this->post_id == $this->topic->topic_last_post_id) {
            $this->topic->sync_last_post($this->post_id);
        }
        // Submit the topic to store the updated information
        $this->topic->submit();
        // Remove from the search index
        titania_search::delete($this->post_type, $this->post_id);
        // @todo remove attachments and other things
        // Remove any attention items
        $sql = 'DELETE FROM ' . TITANIA_ATTENTION_TABLE . '
			WHERE attention_object_type = ' . TITANIA_POST . '
				AND attention_object_id = ' . $this->post_id;
        phpbb::$db->sql_query($sql);
        // Decrement the user's postcount if we must
        if (!$this->post_deleted && $this->post_approved && in_array($this->post_type, titania::$config->increment_postcount)) {
            phpbb::update_user_postcount($this->post_user_id, '-');
        }
        // Hooks
        titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $this);
        // Initiate self-destruct mode
        parent::delete();
        // Check if the topic is empty
        $flags = titania_count::get_flags(TITANIA_ACCESS_TEAMS, true, true);
        if (titania_count::from_db($this->topic->topic_posts, $flags) <= 0) {
            // Remove any subscriptions to this topic
            $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . '
				WHERE watch_object_type = ' . TITANIA_TOPIC . '
					AND watch_object_id = ' . $this->topic->topic_id;
            phpbb::$db->sql_query($sql);
            // Remove any tracking for this topic
            titania_tracking::clear_item(TITANIA_TOPIC, $this->topic->topic_id);
            // Delete the now empty topic
            $sql = 'DELETE FROM ' . TITANIA_TOPICS_TABLE . '
				WHERE topic_id = ' . $this->topic->topic_id;
            phpbb::$db->sql_query($sql);
        }
    }