function _deleteTopic($topic_id = null) { $this->id = $topic_id; $result = $this->read(null); $time_now = date("Y-m-d H:i:s", time()); //Delete topic $this->saveField('deleted', $time_now); $this->saveField('is_deleted', 1); //Count posts of a topic $posts = $this->query("\n\t\t\t\t\t\t\tSELECT \tcount(id) AS posts\n\t\t\t\t\t\t\tFROM \tforumposts\n\t\t\t\t\t\t\tWHERE\tforumtopic_id = " . $this->id . "\n\t\t\t\t\t\t\t\t\tAND forumposts.is_deleted <> 1\n\t\t\t\t\t\t"); $posts_count = $posts[0][0]['posts']; //Delete posts $posts = $this->query("\n\t\t\t\t\t\t\tUPDATE \tforumposts\n\t\t\t\t\t\t\tSET\t\tdeleted = '{$time_now}', is_deleted = 1\n\t\t\t\t\t\t\tWHERE\tforumtopic_id = " . $this->id . "\n\t\t\t\t\t\t\t\t\tAND forumposts.is_deleted <> 1\n\t\t\t\t\t\t"); if (!class_exists('Forumbranch')) { App::import('Model', 'Forumbranch'); } $forumbranch = new Forumbranch(); $forumbranch->update_branch_parents($result['Forumtopic']['forumbranch_id'], 1, $posts_count); $forumbranch->update_lastpostID($result['Forumtopic']['forumbranch_id'], $result['Forumtopic']['lastpost_id']); return true; }
function _deletePost($post_id = null) { $post_id = (int) $post_id; if (!$post_id) { return false; } $time_now = date("Y-m-d H:i:s", time()); $this->id = $post_id; $forumtopic_id = $this->field('forumtopic_id'); $this->Forumtopic->recursive = 0; $result = $this->Forumtopic->read(null, $forumtopic_id); if (!$result['Forumtopic']['repliescounter']) { $this->Forumtopic->_deleteTopic($forumtopic_id); return false; } $this->query("\n\t\t\t\t\t\t\tUPDATE `forumposts`\n\t\t\t\t\t\t\tSET `deleted` = '{$time_now}', is_deleted = 1\n\t\t\t\t\t\t\tWHERE `forumposts`.`id` = {$post_id}"); $this->query("\n\t\t\t\t\t\t\tUPDATE `forumtopics`\n\t\t\t\t\t\t\tSET `repliescounter` = `repliescounter` - 1\n\t\t\t\t\t\t\tWHERE `forumtopics`.`id` = " . $result['Forumtopic']['id']); //Change only if topic have this lastpost id if ($result['Forumtopic']['lastpost_id'] == $post_id) { $lastpost_id = $this->query("\tSELECT max(id) AS lastpost_id\n\t\t\t\t\t\t\t\t\t\t\tFROM forumposts\n\t\t\t\t\t\t\t\t\t\t\tWHERE \tforumtopic_id = " . $forumtopic_id . "\n\t\t\t\t\t\t\t\t\t\t\t\tAND\tis_deleted <> 1 "); $lastpost_id = $lastpost_id[0][0]['lastpost_id']; $this->query("\n\t\t\t\t\t\t\t\tUPDATE `forumtopics`\n\t\t\t\t\t\t\t\tSET `lastpost_id` = " . $lastpost_id . "\n\t\t\t\t\t\t\t\tWHERE `forumtopics`.`id` = " . $result['Forumtopic']['id']); } if (!class_exists('Forumbranch')) { App::import('Model', 'Forumbranch'); } $forumbranch = new Forumbranch(); $forumbranch->update_branch_parents($result['Forumtopic']['forumbranch_id'], null, 1); $forumbranch->update_lastpostID($result['Forumtopic']['forumbranch_id'], $post_id); return true; }