Example #1
0
    /**
     * Delete those comments from the database which corresponds to the given condition or to the given ids array
     * Note: the delete cascade arrays are handled!
     *
     * @param string the name of this class
     *   Note: This is required until min phpversion will be 5.3. Since PHP 5.3 we can use static::function_name to achieve late static bindings
     * @param string where condition
     * @param array object ids
     * @return mixed # of rows affected or false if error
     */
    static function db_delete_where($class_name, $sql_where, $object_ids = NULL, $params = NULL)
    {
        global $DB;
        $use_transaction = isset($params['use_transaction']) ? $params['use_transaction'] : true;
        if ($use_transaction) {
            $DB->begin();
            $params['use_transaction'] = false;
        }
        if (!empty($sql_where)) {
            $object_ids = $DB->get_col('SELECT comment_ID FROM T_comments WHERE ' . $sql_where);
        }
        if (!$object_ids) {
            // There is no comment to delete
            if ($use_transaction) {
                // Commit transaction if it was started
                $DB->commit();
            }
            return;
        }
        $query_get_attached_file_ids = 'SELECT link_file_ID FROM T_links
			WHERE link_cmt_ID IN ( ' . implode(', ', $object_ids) . ' )';
        $attached_file_ids = $DB->get_col($query_get_attached_file_ids);
        $result = parent::db_delete_where($class_name, $sql_where, $object_ids);
        if ($result !== false && !empty($attached_file_ids)) {
            // Delete orphan attachments and empty comment attachment folders
            load_funcs('files/model/_file.funcs.php');
            remove_orphan_files($attached_file_ids, NULL, true);
        }
        if ($use_transaction) {
            // Commit or rollback the transaction
            $result !== false ? $DB->commit() : $DB->rollback();
        }
        return $result;
    }
Example #2
0
    /**
     * Trigger event AfterCommentDelete after calling parent method.
     *
     * @param boolean set true to force permanent delete, leave false otherwise
     * @return boolean true on success
     */
    function dbdelete($force_permanent_delete = false)
    {
        global $Plugins, $DB;
        $DB->begin();
        $was_published = $this->is_published();
        if ($this->status != 'trash') {
            // The comment was not recycled yet
            if ($this->has_replies()) {
                // Move the replies to the one level up
                $new_parent_ID = !empty($this->in_reply_to_cmt_ID) ? $DB->quote($this->in_reply_to_cmt_ID) : 'NULL';
                $DB->query('UPDATE T_comments
				    SET comment_in_reply_to_cmt_ID = ' . $new_parent_ID . '
				  WHERE comment_in_reply_to_cmt_ID = ' . $this->ID);
            }
        }
        if ($force_permanent_delete || $this->status == 'trash') {
            // remember ID, because parent method resets it to 0
            $old_ID = $this->ID;
            // Select comment attachment ids
            $result = $DB->get_col('
				SELECT link_file_ID
					FROM T_links
				 WHERE link_cmt_ID = ' . $this->ID);
            if ($r = parent::dbdelete()) {
                if (!empty($result)) {
                    // remove deleted comment not linked attachments
                    remove_orphan_files($result);
                }
                // re-set the ID for the Plugin event
                $this->ID = $old_ID;
                $this->delete_prerendered_content();
                $Plugins->trigger_event('AfterCommentDelete', $params = array('Comment' => &$this));
                $this->ID = 0;
            }
        } else {
            // don't delete, just move to the trash:
            $this->set('status', 'trash');
            $r = $this->dbupdate();
        }
        if ($r) {
            if ($was_published) {
                // Update last touched date of item if a published comment was deleted
                $comment_Item =& $this->get_Item();
                $comment_Item->update_last_touched_date();
            }
            $DB->commit();
        } else {
            $DB->rollback();
        }
        return $r;
    }
/**
 * Find and delete orphan comment uploads
 */
function dbm_delete_orphan_comment_uploads()
{
    global $Messages;
    $count = remove_orphan_files(NULL, 24);
    $Messages->add(sprintf(T_('%d files have been deleted'), $count), 'success');
}