本文整理汇总了PHP中KunenaForumCategoryHelper::recount方法的典型用法代码示例。如果您正苦于以下问题:PHP KunenaForumCategoryHelper::recount方法的具体用法?PHP KunenaForumCategoryHelper::recount怎么用?PHP KunenaForumCategoryHelper::recount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KunenaForumCategoryHelper
的用法示例。
在下文中一共展示了KunenaForumCategoryHelper::recount方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recount
function recount() {
$app = JFactory::getApplication ();
$state = $app->getUserState ( 'com_kunena.admin.recount', null );
if ($state === null) {
// First run
$query = "SELECT MAX(id) FROM #__kunena_messages";
$db = JFactory::getDBO();
$db->setQuery ( $query );
$state = new StdClass();
$state->step = 0;
$state->maxId = (int) $db->loadResult ();
$state->start = 0;
}
$this->checkTimeout();
while (1) {
$count = mt_rand(95000, 105000);
switch ($state->step) {
case 0:
// Update topic statistics
kimport('kunena.forum.topic.helper');
KunenaForumTopicHelper::recount(false, $state->start, $state->start+$count);
$state->start += $count;
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId) );
break;
case 1:
// Update usertopic statistics
kimport('kunena.forum.topic.user.helper');
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start+$count);
$state->start += $count;
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId) );
break;
case 2:
// Update user statistics
kimport('kunena.user.helper');
KunenaUserHelper::recount();
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USER') );
break;
case 3:
// Update category statistics
kimport('kunena.forum.category.helper');
KunenaForumCategoryHelper::recount();
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORY') );
break;
default:
$app->setUserState ( 'com_kunena.admin.recount', null );
$app->enqueueMessage (JText::_('COM_KUNENA_RECOUNTFORUMS_DONE'));
$this->setRedirect(KunenaRoute::_('index.php?option=com_kunena', false));
return;
}
if (!$state->start || $state->start > $state->maxId) {
$state->step++;
$state->start = 0;
}
if ($this->checkTimeout()) break;
}
$app->setUserState ( 'com_kunena.admin.recount', $state );
$this->setRedirect(KunenaRoute::_('index.php?option=com_kunena&view=recount&task=recount', false));
}
示例2: doprune
function doprune() {
$app = JFactory::getApplication ();
if (!JRequest::checkToken()) {
$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
$category = KunenaForumCategoryHelper::get(JRequest::getInt ( 'prune_forum', 0 ));
if (!$category->authorise('admin')) {
$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_CHOOSEFORUMTOPRUNE' ), 'error' );
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
// Convert days to seconds for timestamp functions...
$prune_days = JRequest::getInt ( 'prune_days', 36500 );
$prune_date = JFactory::getDate()->toUnix() - ($prune_days * 86400);
$trashdelete = JRequest::getInt( 'trashdelete', 0);
// Get up to 100 oldest topics to be deleted
$params = array(
'orderby'=>'tt.last_post_time ASC',
'where'=>"AND tt.last_post_time<{$prune_date} AND ordering=0",
);
list($count, $topics) = KunenaForumTopicHelper::getLatestTopics($category->id, 0, 100, $params);
$deleted = 0;
foreach ( $topics as $topic ) {
$deleted++;
if ( $trashdelete ) $topic->delete(false);
else $topic->trash();
}
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount();
KunenaForumMessageAttachmentHelper::cleanup();
if ( $trashdelete ) $app->enqueueMessage ( "" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNEDELETED') . " {$deleted}/{$count} " . JText::_('COM_KUNENA_PRUNETHREADS') );
else $app->enqueueMessage ( "" . JText::_('COM_KUNENA_FORUMPRUNEDFOR') . " " . $prune_days . " " . JText::_('COM_KUNENA_PRUNEDAYS') . "; " . JText::_('COM_KUNENA_PRUNETRASHED') . " {$deleted}/{$count} " . JText::_('COM_KUNENA_PRUNETHREADS') );
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}
示例3: recountCategories
function recountCategories()
{
$app = JFactory::getApplication();
$state = $app->getUserState('com_kunena.install.recount', null);
// Only perform this stage if database needs recounting (upgrade from older version)
$version = $this->getVersion();
if (version_compare($version->version, '2.0.0-DEV', ">")) {
return true;
}
if ($state === null) {
// First run
$query = "SELECT MAX(id) FROM #__kunena_messages";
$this->db->setQuery($query);
$state = new StdClass();
$state->step = 0;
$state->maxId = (int) $this->db->loadResult();
$state->start = 0;
}
while (1) {
$count = mt_rand(95000, 105000);
switch ($state->step) {
case 0:
// Update topic statistics
KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId), true, '', 'recount');
break;
case 1:
// Update usertopic statistics
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId), true, '', 'recount');
break;
case 2:
// Update user statistics
KunenaUserHelper::recount();
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_USER'), true, '', 'recount');
break;
case 3:
// Update category statistics
KunenaForumCategoryHelper::recount();
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_CATEGORY'), true, '', 'recount');
break;
default:
$app->setUserState('com_kunena.install.recount', null);
$this->addStatus(JText::_('COM_KUNENA_MIGRATE_RECOUNT_DONE'), true, '', 'recount');
return true;
}
if (!$state->start || $state->start > $state->maxId) {
$state->step++;
$state->start = 0;
}
if ($this->checkTimeout()) {
break;
}
}
$app->setUserState('com_kunena.install.recount', $state);
return false;
}
示例4: dorecount
/**
* Perform recount on statistics in smaller chunks.
*
* @return void
* @throws Exception
*/
public function dorecount()
{
$ajax = $this->input->getWord('format', 'html') == 'json';
if (!JSession::checkToken('request')) {
$this->setResponse(array('success' => false, 'header' => JText::_('COM_KUNENA_AJAX_ERROR'), 'message' => JText::_('COM_KUNENA_AJAX_DETAILS_BELOW'), 'error' => JText::_('COM_KUNENA_ERROR_TOKEN')), $ajax);
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
$state = $this->app->getUserState('com_kunena.admin.recount', null);
try {
$this->checkTimeout();
while (1) {
// Topic count per run.
// TODO: count isn't accurate as it can overflow total.
$count = mt_rand(4500, 5500);
switch ($state->step) {
case 0:
if ($state->topics) {
// Update topic statistics
KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
$msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS_X', round(min(100 * $state->start / $state->maxId + 1, 100)) . '%');
}
break;
case 1:
if ($state->usertopics) {
// Update user's topic statistics
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
$msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS_X', round(min(100 * $state->start / $state->maxId + 1, 100)) . '%');
}
break;
case 2:
if ($state->categories) {
// Update category statistics
KunenaForumCategoryHelper::recount();
KunenaForumCategoryHelper::fixAliases();
$msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORIES_X', '100%');
}
break;
case 3:
if ($state->users) {
// Update user statistics
KunenaUserHelper::recount();
$msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERS_X', '100%');
}
break;
case 4:
if ($state->polls) {
// Update user statistics
KunenaForumTopicPollHelper::recount();
$msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_POLLS_X', '100%');
}
break;
default:
$header = JText::_('COM_KUNENA_RECOUNTFORUMS_DONE');
$msg = JText::_('COM_KUNENA_AJAX_REQUESTED_RECOUNTED');
$this->app->setUserState('com_kunena.admin.recount', null);
$this->setResponse(array('success' => true, 'status' => '100%', 'header' => $header, 'message' => $msg), $ajax);
$this->setRedirect(KunenaRoute::_($this->baseurl, false), $header);
return;
}
$state->current = min($state->current + $count, $state->total);
if (!$state->start || $state->start > $state->maxId) {
$state->step++;
$state->start = 0;
}
if ($this->checkTimeout()) {
break;
}
}
$state->reload++;
$this->app->setUserState('com_kunena.admin.recount', $state);
} catch (Exception $e) {
if (!$ajax) {
throw $e;
}
$this->setResponse(array('success' => false, 'status' => sprintf("%2.1f%%", 99 * $state->current / ($state->total + 1)), 'header' => JText::_('COM_KUNENA_AJAX_ERROR'), 'message' => JText::_('COM_KUNENA_AJAX_DETAILS_BELOW'), 'error' => $e->getMessage()), $ajax);
}
$token = JSession::getFormToken() . '=1';
$redirect = KunenaRoute::_("{$this->baseurl}&task=dorecount&i={$state->reload}&{$token}", false);
$this->setResponse(array('success' => true, 'status' => sprintf("%2.1f%%", 99 * $state->current / ($state->total + 1)), 'header' => JText::_('COM_KUNENA_AJAX_RECOUNT_WAIT'), 'message' => $msg, 'href' => $redirect), $ajax);
}
示例5: delete
/**
* Method to delete the KunenaForumCategory object from the database
*
* @access public
* @return boolean True on success
* @since 1.6
*/
public function delete() {
if (!$this->exists()) {
return true;
}
// Create the user table object
$table = &$this->getTable ();
$result = $table->delete ( $this->id );
if (! $result) {
$this->setError ( $table->getError () );
}
$this->_exists = false;
$access = KunenaFactory::getAccessControl();
$access->clearCache();
$db = JFactory::getDBO ();
// Delete moderators
$queries[] = "DELETE FROM #__kunena_moderation WHERE catid={$db->quote($this->id)}";
// Delete user topics
$queries[] = "DELETE FROM #__kunena_user_topics WHERE category_id={$db->quote($this->id)}";
// Delete user categories
$queries[] = "DELETE FROM #__kunena_user_categories WHERE category_id={$db->quote($this->id)}";
// Delete user read
$queries[] = "DELETE FROM #__kunena_user_read WHERE category_id={$db->quote($this->id)}";
// Delete thank yous
$queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.catid={$db->quote($this->id)}";
// Delete poll users
$queries[] = "DELETE p FROM #__kunena_polls_users AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.pollid WHERE tt.category_id={$db->quote($this->id)} AND tt.moved_id=0";
// Delete poll options
$queries[] = "DELETE p FROM #__kunena_polls_options AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.pollid WHERE tt.category_id={$db->quote($this->id)} AND tt.moved_id=0";
// Delete polls
$queries[] = "DELETE p FROM #__kunena_polls AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.id WHERE tt.category_id={$db->quote($this->id)} AND tt.moved_id=0";
// Delete messages
$queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.catid={$db->quote($this->id)}";
// TODO: delete attachments
foreach ($queries as $query) {
$db->setQuery($query);
$db->query();
KunenaError::checkDatabaseError ();
}
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount();
return $result;
}
示例6: delete
/**
* Method to delete the KunenaForumTopic object from the database.
*
* @param bool $recount
*
* @return bool True on success.
*/
public function delete($recount = true)
{
if (!$this->exists()) {
return true;
}
if (!parent::delete()) {
return false;
}
// Clear authentication cache
$this->_authfcache = $this->_authccache = $this->_authcache = array();
// NOTE: shadow topic doesn't exist, DO NOT DELETE OR CHANGE ANY EXTERNAL INFORMATION
if ($this->moved_id == 0) {
$db = JFactory::getDBO();
// Delete user topics
$queries[] = "DELETE FROM #__kunena_user_topics WHERE topic_id={$db->quote($this->id)}";
// Delete user read
$queries[] = "DELETE FROM #__kunena_user_read WHERE topic_id={$db->quote($this->id)}";
// Delete poll (users)
$queries[] = "DELETE FROM #__kunena_polls_users WHERE pollid={$db->quote($this->poll_id)}";
// Delete poll (options)
$queries[] = "DELETE FROM #__kunena_polls_options WHERE pollid={$db->quote($this->poll_id)}";
// Delete poll
$queries[] = "DELETE FROM #__kunena_polls WHERE id={$db->quote($this->poll_id)}";
// Delete thank yous
$queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.thread={$db->quote($this->id)}";
// Delete all messages
$queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.thread={$db->quote($this->id)}";
foreach ($queries as $query) {
$db->setQuery($query);
$db->query();
KunenaError::checkDatabaseError();
}
// FIXME: add recount statistics
if ($recount) {
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount();
KunenaAttachmentHelper::cleanup();
KunenaForumMessageThankyouHelper::recount();
}
}
return true;
}
示例7: delete
/**
* Method to delete the KunenaForumTopic object from the database
*
* @access public
* @return boolean True on success
* @since 1.6
*/
public function delete($recount = true) {
if (!$this->exists()) {
return true;
}
// Create the table object
$table = $this->getTable ();
$result = $table->delete ( $this->id );
if (! $result) {
$this->setError ( $table->getError () );
}
$this->_exists = false;
// NOTE: shadow topic doesn't exist, DO NOT DELETE OR CHANGE ANY EXTERNAL INFORMATION
if ($this->moved_id == 0) {
$db = JFactory::getDBO ();
// Delete user topics
$queries[] = "DELETE FROM #__kunena_user_topics WHERE topic_id={$db->quote($this->id)}";
// Delete user read
$queries[] = "DELETE FROM #__kunena_user_read WHERE topic_id={$db->quote($this->id)}";
// Delete poll (users)
$queries[] = "DELETE FROM #__kunena_polls_users WHERE pollid={$db->quote($this->poll_id)}";
// Delete poll (options)
$queries[] = "DELETE FROM #__kunena_polls_options WHERE pollid={$db->quote($this->poll_id)}";
// Delete poll
$queries[] = "DELETE FROM #__kunena_polls WHERE id={$db->quote($this->poll_id)}";
// Delete thank yous
$queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.thread={$db->quote($this->id)}";
// Delete all messages
$queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.thread={$db->quote($this->id)}";
foreach ($queries as $query) {
$db->setQuery($query);
$db->query();
KunenaError::checkDatabaseError ();
}
if ($recount) {
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount();
KunenaForumMessageAttachmentHelper::cleanup();
}
}
return $result;
}
示例8: restore
function restore()
{
if (!JSession::checkToken('post')) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
$cid = JRequest::getVar('cid', array(), 'post', 'array');
// Array of integers
JArrayHelper::toInteger($cid);
$type = JRequest::getCmd('type', 'topics', 'post');
if (empty($cid)) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_A_NO_MESSAGES_SELECTED'), 'notice');
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
$nb_items = 0;
if ($type == 'messages') {
$messages = KunenaForumMessageHelper::getMessages($cid, 'none');
foreach ($messages as $target) {
if ($target->publish(KunenaForum::PUBLISHED)) {
$nb_items++;
} else {
$this->app->enqueueMessage($target->getError(), 'notice');
}
}
} elseif ($type == 'topics') {
$topics = KunenaForumTopicHelper::getTopics($cid, 'none');
foreach ($topics as $target) {
if ($target->publish(KunenaForum::PUBLISHED)) {
$nb_items++;
} else {
$this->app->enqueueMessage($target->getError(), 'notice');
}
}
} else {
// Error...
}
if ($nb_items > 0) {
$this->app->enqueueMessage(JText::sprintf('COM_KUNENA_TRASH_ITEMS_RESTORE_DONE', $nb_items));
}
KunenaUserHelper::recount();
KunenaForumTopicHelper::recount();
KunenaForumCategoryHelper::recount();
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
示例9: recount
function recount()
{
$state = $this->app->getUserState('com_kunena.admin.recount', null);
if ($state === null) {
// First run: get last message id (if topics were created with <K2.0)
$query = "SELECT MAX(id) FROM #__kunena_messages";
$db = JFactory::getDBO();
$db->setQuery($query);
$state = new StdClass();
$state->step = 0;
$state->maxId = (int) $db->loadResult();
$state->start = 0;
$state->reload = 0;
$state->topics = JRequest::getBool('topics', false);
$state->usertopics = JRequest::getBool('usertopics', false);
$state->categories = JRequest::getBool('categories', false);
$state->users = JRequest::getBool('users', false);
}
$this->checkTimeout();
while (1) {
$count = mt_rand(95000, 105000);
switch ($state->step) {
case 0:
if ($state->topics) {
// Update topic statistics
KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId) );
}
break;
case 1:
if ($state->usertopics) {
// Update usertopic statistics
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId) );
}
break;
case 2:
if ($state->categories) {
// Update category statistics
KunenaForumCategoryHelper::recount();
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORY') );
}
break;
case 3:
if ($state->users) {
// Update user statistics
KunenaUserHelper::recount();
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USER') );
}
break;
default:
$this->app->setUserState('com_kunena.admin.recount', null);
$this->app->enqueueMessage(JText::_('COM_KUNENA_RECOUNTFORUMS_DONE'));
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
if (!$state->start || $state->start > $state->maxId) {
$state->step++;
$state->start = 0;
}
if ($this->checkTimeout()) {
break;
}
}
$state->reload++;
$this->app->setUserState('com_kunena.admin.recount', $state);
$this->setRedirect(KunenaRoute::_("{$this->baseurl}&task=recount&i={$state->reload}", false));
}
示例10: restore
function restore() {
$app = JFactory::getApplication ();
if (! JRequest::checkToken ()) {
$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
$app->redirect ( KunenaRoute::_($this->baseurl, false) );
}
$kunena_db = JFactory::getDBO ();
$cid = JRequest::getVar ( 'cid', array (), 'post', 'array' );
$topics = JRequest::getInt ( 'topics', 0, 'post' );
$messages = JRequest::getInt ( 'messages', 0, 'post' );
if (empty ( $cid )) {
$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_A_NO_MESSAGES_SELECTED' ), 'notice' );
$app->redirect ( KunenaRoute::_($this->baseurl, false) );
}
$msg = JText::_('COM_KUNENA_TRASH_RESTORE_DONE');
if ( $messages ) {
$messages = KunenaForumMessageHelper::getMessages($cid);
foreach ( $messages as $target ) {
if ( $target->authorise('undelete') && $target->publish(KunenaForum::PUBLISHED) ) {
$app->enqueueMessage ( $msg );
} else {
$app->enqueueMessage ( $target->getError(), 'notice' );
}
}
} elseif ( $topics ) {
$topics = KunenaForumTopicHelper::getTopics($cid);
foreach ( $topics as $target ) {
if ( $target->authorise('undelete') && $target->publish(KunenaForum::PUBLISHED) ) {
$app->enqueueMessage ( $msg );
} else {
$app->enqueueMessage ( $target->getError(), 'notice' );
}
}
} else {
// error
}
KunenaUserHelper::recount();
KunenaForumTopicHelper::recount();
KunenaForumCategoryHelper::recount ();
$app->redirect(KunenaRoute::_($this->baseurl, false));
}
示例11: trash
/**
* Trash old topics in this category. Changes topic state to deleted.
*
* @param $time
* @param array $params
* @param int $limit
*
* @return int Number of trashed topics.
*/
public function trash($time, $params = array(), $limit = 1000)
{
// FIXME: why time isn't used?
if (!$this->exists()) {
return 0;
}
$where = isset($params['where']) ? (string) $params['where'] : '';
$db = JFactory::getDBO();
$query = "SELECT id FROM #__kunena_topics AS tt WHERE tt.category_id={$this->id} AND tt.hold!=2 {$where} ORDER BY tt.last_post_time ASC";
$db->setQuery($query, 0, $limit);
$ids = $db->loadColumn();
KunenaError::checkDatabaseError();
if (empty($ids)) {
return 0;
}
$count = KunenaForumTopicHelper::trash($ids);
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount($this->id);
return $count;
}
示例12: _Delete
//.........这里部分代码省略.........
if ( $currentMessage->userid > 0) {
$query = "UPDATE #__kunena_users SET posts=posts-1 WHERE `userid`={$this->_db->Quote($MessageID)}; ";
$this->_db->setQuery ($query);
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
}
break;
case KN_DEL_THREAD_PERMINANTLY : //Delete a complete thread from the databases
$query = "SELECT `id`,`userid` FROM #__kunena_messages WHERE `thread`={$this->_db->Quote($currentMessage->thread)};";
$this->_db->setQuery ($query);
$ThreadDatas = $this->_db->loadObjectList ();
if (KunenaError::checkDatabaseError()) return false;
$userid = array();
$messid = array();
if ( is_array( $ThreadDatas ) ) {
foreach ( $ThreadDatas as $mes ) {
$userid[] = $mes->userid;
$messid[] = $mes->id;
// Delete all attachments in this thread
if ($DeleteAttachments) {
$this->deleteAttachments($mes->id);
}
}
$sql2 = "DELETE FROM #__kunena_messages_text WHERE `mesid` IN ({$this->_db->Quote(implode(',',$messid))});";
$this->_db->setQuery ($sql2);
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
// Need to update number of posts of each users in this thread
if ( $mes->userid > 0) {
$query = "UPDATE #__kunena_users SET posts=posts-1 WHERE `userid` IN ({$this->_db->Quote(implode(',',$userid))}); ";
$this->_db->setQuery ($query);
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
}
}
$sql = "DELETE FROM #__kunena_messages WHERE `thread`={$this->_db->Quote($currentMessage->thread)};";
break;
case KN_UNDELETE_THREAD :
$sql1 = "UPDATE #__kunena_messages SET `hold`=0 WHERE `id`={$this->_db->Quote($MessageID)};";
$this->_db->setQuery ( $sql1 );
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
$sql = "UPDATE #__kunena_messages SET `hold`=0 WHERE hold=3 AND `thread`={$this->_db->Quote($currentMessage->thread)} AND `id`!={$this->_db->Quote($MessageID)} ;";
break;
case KN_DEL_THREAD : //Delete a complete thread
$sql1 = "UPDATE #__kunena_messages SET `hold`=2 WHERE `id`={$this->_db->Quote($MessageID)};";
$this->_db->setQuery ( $sql1 );
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
$sql = "UPDATE #__kunena_messages SET `hold`=3 WHERE hold IN (0,1) AND `thread`={$this->_db->Quote($currentMessage->thread)} AND `id`!={$this->_db->Quote($MessageID)} ;";
break;
case KN_DEL_ATTACH : //Delete only the attachments
// FIXME: removed class
//$attachments = CKunenaAttachments::getInstance();
//$attachments->deleteMessage($MessageID);
break;
default :
// Unsupported mode - Error!
$this->_errormsg = JText::_('COM_KUNENA_MODERATION_ERROR_UNSUPPORTED_MODE');
return false;
}
// Execute delete
if (isset($sql)) {
$this->_db->setQuery ( $sql );
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
}
// Remember to delete ghost post
// FIXME: replies may have ghosts, too. What to do with them?
$this->_db->setQuery ( "SELECT m.id FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.`id`=t.`mesid`
WHERE `moved`=1;" );
$ghostMessageID = $this->_db->loadResult ();
if (KunenaError::checkDatabaseError()) return false;
if ( !empty($ghostMessageID) ) {
$this->_db->setQuery ( "UPDATE #__kunena_messages SET `hold`=2 WHERE `id`={$this->_db->Quote($ghostMessageID)} AND `moved`=1;" );
$this->_db->query ();
if (KunenaError::checkDatabaseError()) return false;
}
// Check result to see if we need to abord and set error message
// When done log the action
$this->_Log ( 'Delete', $MessageID, 0, '', 0, $mode );
// Last but not least update forum stats
kimport('kunena.forum.category.helper');
KunenaForumCategoryHelper::recount ();
return true;
}
示例13: purge
/**
* Method to purge old topics from the category
*
* @access public
* @return boolean True on success
* @since 1.6
*/
public function purge($time, $limit = 1000) {
if (!$this->exists()) {
return true;
}
$db = JFactory::getDBO ();
$query ="SELECT id FROM #__kunena_topics WHERE last_post_time < {$time} ORDER BY last_post_time ASC";
$db->setQuery($query, 0, $limit);
$ids = $db->loadResultArray();
KunenaError::checkDatabaseError ();
if (empty($ids)) return true;
$idlist = implode(',', $ids);
// Delete user topics
$queries[] = "DELETE FROM #__kunena_user_topics WHERE topic_id IN ({$idlist})";
// Delete user read
$queries[] = "DELETE FROM #__kunena_user_read WHERE topic_id IN ({$idlist})";
// Delete thank yous
$queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.thread IN ({$idlist})";
// Delete poll users
$queries[] = "DELETE p FROM #__kunena_polls_users AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.pollid WHERE tt.topic_id IN ({$idlist}) AND tt.moved_id=0";
// Delete poll options
$queries[] = "DELETE p FROM #__kunena_polls_options AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.pollid WHERE tt.topic_id IN ({$idlist}) AND tt.moved_id=0";
// Delete polls
$queries[] = "DELETE p FROM #__kunena_polls AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.id WHERE tt.topic_id IN ({$idlist}) AND tt.moved_id=0";
// Delete messages
$queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.thread IN ({$idlist})";
// TODO: delete attachments
// TODO: delete keywords
// Delete topics
$queries[] = "DELETE FROM #__kunena_topics WHERE id IN ({$idlist})";
foreach ($queries as $query) {
$db->setQuery($query);
$db->query();
KunenaError::checkDatabaseError ();
}
KunenaUserHelper::recount();
KunenaForumCategoryHelper::recount($this->id);
return true;
}