[MODDB] Prime Trash Bin - Keep deleted topics & posts

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Anti-Spam Guide
Locked
User avatar
primehalo
Former Team Member
Posts: 2848
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA
Contact:

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by primehalo » Sat Jan 30, 2010 6:03 am

jackbl wrote:I found serious problem with this MOD on my forum.
I'll try to explain it as a simple:

Let, I have topic whith 16 messages. 15 - on the first page and 1 - on the second.
Then, I do fake-delete some message on first page. (Counter of messages on topic decreased by 1).
After reload topic, I have only 1 page whith 15 messages (one of them shows as deleted).
16-th message I don't see at all!
Try this as a quick fix:

Open: viewtopic.php
Find:

Code: Select all

$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies']; 
After, add:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
$sql = 'SELECT COUNT(post_id) AS deleted_posts FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id . ' AND post_deleted_time > 0';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$topic_replies = $topic_replies + $row['deleted_posts'];
//-- end: Prime Trash Bin (Posts) -------------------------------------------//   
Hercanic wrote:When trying to install Prime Trash Bin, I received a conflict error with two SQL entries.

What I'd like to know is if Soft Delete's additions match what Trash Bin needs, or if I must somehow remove Soft Delete's columns so Trash Bin can install correctly (I have asked this in Soft Delete's thread, but fear a response will not be forthcoming due to the author generally not giving complimentary support).

This is the code from Soft Delete's install.php:

Code: Select all

<?php
/**
*
* @package phpBB3 Soft Delete Install
* @copyright (c) 2007 EXreaction, Lithium Studios
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

// Stuff required to work with phpBB3
define('IN_PHPBB', true);
$phpbb_root_path = ((isset($phpbb_root_path)) ? $phpbb_root_path : './');
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('common');
$user->add_lang('mods/soft_delete');

if ($user->data['user_type'] != USER_FOUNDER)
{
   trigger_error('FOUNDER_ONLY');
}

include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);

$auth_admin = new auth_admin();
$db_tool = new phpbb_db_tools($db);

$db_tool->sql_column_add(POSTS_TABLE, 'post_deleted', array('UINT', 0));
$db_tool->sql_column_add(POSTS_TABLE, 'post_deleted_time', array('TIMESTAMP', 0));

$db_tool->sql_column_add(TOPICS_TABLE, 'topic_deleted', array('UINT', 0));
$db_tool->sql_column_add(TOPICS_TABLE, 'topic_deleted_time', array('TIMESTAMP', 0));
$db_tool->sql_column_add(TOPICS_TABLE, 'topic_deleted_reply_count', array('UINT', 0));

$db_tool->sql_column_add(FORUMS_TABLE, 'forum_deleted_topic_count', array('UINT', 0));
$db_tool->sql_column_add(FORUMS_TABLE, 'forum_deleted_reply_count', array('UINT', 0));

$permissions = array(
   'local'      => array(
      'm_harddelete',
   ),
   'global'   => array(
      'm_harddelete',
   )
);
$auth_admin->acl_add_option($permissions);

$cache->purge();

trigger_error('SOFT_DELETE_INSTALL_COMPLETE');
?>
Great, now I have another problem. Apparently AutoMod fully executed the SQL changes the first time I tried to install Trash Bin, and did not undo them like the file edits when I retreated back. I was going to fetch which tables were in conflict, only to find them all now claiming duplicates. Joy! Maybe this doesn't matter, though? :?
The topic_deleted_time and post_deleted_time look like the same columns I use. I don't think my MOD contains the other columns.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!

Hercanic
Registered User
Posts: 40
Joined: Wed Jun 26, 2002 7:15 pm

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by Hercanic » Sun Jan 31, 2010 4:12 am

Alright, after a few more hoops, I managed to get it successfully installed. However, there seems to be a bug when using AutoMod.
  • root/styles/prosilver/template/prime_delete_confirm.html,
    root/styles/prosilver/template/prime_deleted_msg.html,
These files were, for some inexplicable reason, renamed by AutoMod.
  • prime_delete_topic_confirm.html
    prime_delete_topic_message.html
Which then results in this error:

Code: Select all

General Error

template->_tpl_load_file(): File ./styles/prosilver/template/prime_delete_confirm.html does not exist or is empty

Hercanic
Registered User
Posts: 40
Joined: Wed Jun 26, 2002 7:15 pm

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by Hercanic » Sun Jan 31, 2010 4:50 am

After testing this mod out, I just have to say: Wow. It is by far superior in functionality to Soft Delete. Good show!

I have noticed a small bug: When you soft delete a thread, post counts are reduced appropriately, but when you permanently delete it afterward, post counts are reduced again.

User avatar
knmt
Registered User
Posts: 110
Joined: Fri Aug 29, 2008 10:13 am
Contact:

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by knmt » Sun Jan 31, 2010 10:44 am

Hercanic wrote:After testing this mod out, I just have to say: Wow. It is by far superior in functionality to Soft Delete. Good show!

I have noticed a small bug: When you soft delete a thread, post counts are reduced appropriately, but when you permanently delete it afterward, post counts are reduced again.
Which version are you using? I thought this has already been fixed o.O

Hercanic
Registered User
Posts: 40
Joined: Wed Jun 26, 2002 7:15 pm

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by Hercanic » Sun Jan 31, 2010 1:35 pm

1.0.9 on phpBB 3.0.6

jackbl
Registered User
Posts: 6
Joined: Thu Jan 28, 2010 8:32 am

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by jackbl » Tue Feb 02, 2010 8:13 am

primehalo wrote: Try this as a quick fix:
Tanks, the problem solved.
But, sumetimes now, when send new message on topic witch has fake-deleted messages and when new message post will be on new page, after post compleete, forum can't find new page whith this message and show the first page of topic.
It's better then not visible messages, but is not very good. ;)

P.S.
Found another bug:
When select in mcp.php topic: not deleted message and fake-deleted message same time and then select "Delete messages", I get this error:
[phpBB Debug] PHP Notice: in file /includes/prime_trash_bin_2.php on line 912: Use of undefined constant PRIME_DELETE_POST_MIX_NOTICE - assumed 'PRIME_DELETE_POST_MIX_NOTICE'
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4184: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4186: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4187: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4188: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3493)
It's very strange, because in /language/ru/mods/prime_trash_bin_2.php the string whith PRIME_DELETE_POST_MIX_NOTICE presents.
'PRIME_DELETE_POST_MIX_NOTICE' => 'Информация: Все сообщения, помеченные как удаленные, не будут изменены.',
Then I look in /includes/prime_trash_bin_2.php on line 912

Code: Select all

			{
				$template->assign_var('ADDITIONAL_MSG', $user->lang[PRIME_DELETE_POST_MIX_NOTICE]);
May be PRIME_DELETE_POST_MIX_NOTICE in this string need to quote'?

Spotify
Registered User
Posts: 15
Joined: Thu Jul 09, 2009 12:04 am

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by Spotify » Sun Feb 14, 2010 3:29 pm

Hercanic wrote:I have noticed a small bug: When you soft delete a thread, post counts are reduced appropriately, but when you permanently delete it afterward, post counts are reduced again.
I can confirm this. It can be a serious problem if the topic have 1 reply and we soft delete and then permanently delete the reply, the topic will be deleted completely from the database.

jackbl
Registered User
Posts: 6
Joined: Thu Jan 28, 2010 8:32 am

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by jackbl » Tue Feb 16, 2010 1:25 pm

I fixed problem with last topic message (I wrote about it higher).

It's need to comment some code in viewtopic.php :

Code: Select all

//	if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
//	{
//		$check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
//
//		if ($sort_dir == $check_sort)
//		{
//			$topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
//		}
//		else
//		{
//			$topic_data['prev_posts'] = 0;
//		}
//	}
//	else
//	{
		$sql = 'SELECT COUNT(p1.post_id) AS prev_posts
			FROM ' . POSTS_TABLE . ' p1, ' . POSTS_TABLE . " p2
			WHERE p1.topic_id = {$topic_data['topic_id']}
				AND p2.post_id = {$post_id}
				" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p1.post_approved = 1' : '') . '
				AND ' . (($sort_dir == 'd') ? 'p1.post_time >= p2.post_time' : 'p1.post_time <= p2.post_time');

		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		$topic_data['prev_posts'] = $row['prev_posts'] - 1;
//	}
Now, I have no problem whith show topic and pagination in it.
But, still have a problem in viewforum: Sometimes in showforum mode I see less pages of topic (which have fake-deleted messages) than it has. And when I go to the last page of such topic, I see, for example, real last-1 page.

I can modify viewforum.php analogically as "quick fix" whith select count... but may be better - add column whith deleted posts count in topics table in new version of this mod?

User avatar
primehalo
Former Team Member
Posts: 2848
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA
Contact:

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by primehalo » Wed Feb 17, 2010 12:28 am

jackbl wrote:/includes/prime_trash_bin_2.php on line 912

Code: Select all

			{
				$template->assign_var('ADDITIONAL_MSG', $user->lang[PRIME_DELETE_POST_MIX_NOTICE]);
May be PRIME_DELETE_POST_MIX_NOTICE in this string need to quote'?
Yes, it is supposed to have quotes. Sorry about that. I actually found two lines that need the quotes, so add quotes to both of these:

Code: Select all

$user->lang[PRIME_DELETE_TOPIC_MIX_NOTICE]
$user->lang[PRIME_DELETE_POST_MIX_NOTICE]
 
As for your other problem on the viewtopic page, I think I have a fix for it. First, undo the quick fix that I mentioned earlier (and also undo your fix). Now:
Open: includes/functions_admin.php
Find:

Code: Select all

            // Use "t" as table alias because of the $where_sql clause
            // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.
 
Before, add:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
            global $phpbb_root_path, $phpEx;
            include ($phpbb_root_path . 'includes/prime_trash_bin.' . $phpEx);
            if (stifle_posts_enabled())
            {
                // Get the last topic that isn't deleted, except for when doing the Trash forum.
                $where_sql2 = str_replace('WHERE ', 'WHERE (t.post_deleted_time = 0' . (get_trash_forum() ? ' OR t.forum_id = ' . get_trash_forum() : '') . ') AND ', $where_sql);
                $sql2 = 'SELECT MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id FROM ' . POSTS_TABLE . " t $where_sql2";
                $result2 = $db->sql_query($sql2);
                $row2 = $db->sql_fetchrow($result2);
                $db->sql_freeresult($result2);
            }
//-- end: Prime Trash Bin (Posts) -------------------------------------------//    
Find & Delete:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
            global $phpbb_root_path, $phpEx;
            include ($phpbb_root_path . 'includes/prime_trash_bin.' . $phpEx);
            if (stifle_posts_enabled())
            {
                // Get the last topic that isn't deleted, except for when doing the Trash forum.
                $sql = str_replace('WHERE ', 'WHERE (t.post_deleted_time = 0' . (get_trash_forum() ? ' OR t.forum_id = ' . get_trash_forum() : '') . ') AND ', $sql);
            }
//-- end: Prime Trash Bin (Posts) -------------------------------------------//    
Find:

Code: Select all

                $row['first_post_id'] = (int) $row['first_post_id'];
                $row['last_post_id'] = (int) $row['last_post_id'];
 
After, add:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
                $row['first_post_id'] = (int) $row2['first_post_id'];
                $row['last_post_id'] = (int) $row2['last_post_id'];
//-- end: Prime Trash Bin (Posts) -------------------------------------------//
 
Open: viewforum.php
Find:

Code: Select all

        // Replies
        $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
 
After, add:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
        $sql = 'SELECT COUNT(post_id) AS deleted_replies FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . $topic_id . ' AND post_deleted_time > 0 AND post_id <> ' . $row['topic_first_post_id'];
        $result = $db->sql_query($sql);
        $tmp_result = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        $replies = $replies - $tmp_result['deleted_replies'];
//-- end: Prime Trash Bin (Posts) -------------------------------------------//   
This should also fix the problem in viewforum. You will want to go into the admin control panel and resync your forums, because the database probably currently has the wrong number of replies stored in the topic table.

Let me know if this works and I'll incorporate it into the instructions.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!

Peter77sx
Registered User
Posts: 3257
Joined: Wed Nov 09, 2005 2:51 pm

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by Peter77sx » Wed Feb 17, 2010 2:14 am

So what's going on.. are you updating the MOD, or are those just fixes for the people having issues with it?

User avatar
primehalo
Former Team Member
Posts: 2848
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA
Contact:

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by primehalo » Wed Feb 17, 2010 2:49 am

I will update the instructions once other people test the fixes to make sure they work correctly.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!

User avatar
IPB_Refugee
Registered User
Posts: 1290
Joined: Fri Jul 07, 2006 2:25 pm
Location: Austria
Name: Wolfgang Weber

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by IPB_Refugee » Wed Feb 17, 2010 9:10 am

Hi Ken,

I might be wrong because I have a heavily modified board, but I think your fixes don't work. :(

What I did:

On my board, 15 posts per page are displayed.
In a topic with 16 posts I soft deleted two posts and then hard deleted one of the soft deleted posts.
Then I posted a new message in this topic which is the first message on page 2 now.

- On viewtopic page, it tells "16 posts", but on viewforum page, it tells only "15 posts", and the pagination is missing. Furthermore, on viewforum page, when I click on the link to the latest post of the topic, I get to page one instead of page two.

- When I first soft delete and then hard delete a post, the number of total posts on index page is wrong (1 to high).

- When I first soft delete and then hard delete the first post of a topic with a few posts, it works without a phpBB debug notice. But when I choose to immediately hard delete the first post (without soft deleting it before), I get:
[phpBB Debug] PHP Notice: in file /includes/functions_posting.php on line 1555: Undefined index: post_approved
In this case your MOD seems to conflict with nickvergessen's user topics MOD, because the lines around 1555 in my functions_posting.php are:
// nv user topics mod
if ($row['post_approved'] && $row['post_postcount'])
{
$sub_sql = 'UPDATE ' . USERS_TABLE . ' SET user_topics = user_topics + 1 WHERE user_id = ' . (int) $row['poster_id'];
$db->sql_query($sub_sql);
}
// nv user topics mod end
These lines are within function delete_post / case 'delete_first_post'. Strange, that the problem only occurs when first soft deleting the first post.

Wish I had better news, but thanks a lot for working on this great MOD!

Regards
Wolfgang

jackbl
Registered User
Posts: 6
Joined: Thu Jan 28, 2010 8:32 am

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by jackbl » Wed Feb 17, 2010 10:18 am

It was very-very bad idea...

I syncronize my forums and got something... strange...
//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
global $phpbb_root_path, $phpEx;
include ($phpbb_root_path . 'includes/prime_trash_bin.' . $phpEx);
if (stifle_posts_enabled())
{
// Get the last topic that isn't deleted, except for when doing the Trash forum.
$where_sql2 = str_replace('WHERE ', 'WHERE (t.post_deleted_time = 0' . (get_trash_forum() ? ' OR t.forum_id = ' . get_trash_forum() : '') . ') AND ', $where_sql);
$sql2 = 'SELECT MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id FROM ' . POSTS_TABLE . " t $where_sql2";
$result2 = $db->sql_query($sql2);
$row2 = $db->sql_fetchrow($result2);
$db->sql_freeresult($result2);
}
//-- end: Prime Trash Bin (Posts) -------------------------------------------//

// Use "t" as table alias because of the $where_sql clause
// NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.
$sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id
FROM ' . POSTS_TABLE . " t
$where_sql
GROUP BY t.topic_id, t.post_approved";

$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
$topic_id = (int) $row['topic_id'];

$row['first_post_id'] = (int) $row['first_post_id'];

$row['last_post_id'] = (int) $row['last_post_id'];

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
// $row['first_post_id'] = (int) $row2['first_post_id'];
// $row['last_post_id'] = (int) $row2['last_post_id'];
//-- end: Prime Trash Bin (Posts) -------------------------------------------//
It changes first & last post id for different topics...

jackbl
Registered User
Posts: 6
Joined: Thu Jan 28, 2010 8:32 am

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by jackbl » Wed Feb 17, 2010 10:36 am

primehalo, tell me please the idea whith topic_replies/topic_replies_real counters in topics table consists in:

1. this is a counter of total replies in topic (both real messages & fake-deleted)

or

2. this is a counter of only real replies (and when fake-delete, it's decreesed)

In first case, is need not touch this counter when doing fake-delete, and only do

Code: Select all

 $replies = $replies - $tmp_result['deleted_replies'];
in viewforum.php, but pagination calculate with clear $replies count.

In 2-nd case, we must calculate pagination and total messages and prev_posts whith add fake-deleted messages

Or may be better - to add some additional column in topic table for keep deleted message count or total-message-count/real-message-count and it will be better because low resurses of MySQL for operations whith (big - 1Gb in my case) posts table?

User avatar
primehalo
Former Team Member
Posts: 2848
Joined: Fri May 06, 2005 5:58 pm
Location: Redding, CA
Contact:

Re: [BETA] Prime Trash Bin - Keep deleted topics & posts

Post by primehalo » Thu Feb 18, 2010 12:28 am

Yep, that fix wasn't quite right either. Okay, undo those last changes and lets try it again.

Open: includes/functions_admin.php
Find:

Code: Select all

            // Use "t" as table alias because of the $where_sql clause
            // NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.   
Before, add:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
            global $phpbb_root_path, $phpEx;
            include ($phpbb_root_path . 'includes/prime_trash_bin.' . $phpEx);
            if (stifle_posts_enabled())
            {
                // Get the last topic that isn't deleted, except for when doing the Trash forum.
                $where_sql2 = str_replace('WHERE ', 'WHERE (t.post_deleted_time = 0' . (get_trash_forum() ? ' OR t.forum_id = ' . get_trash_forum() : '') . ') AND ', $where_sql);
                $sql = 'SELECT t.topic_id, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id
                    FROM ' . POSTS_TABLE . " t
                    $where_sql2
                    GROUP BY t.topic_id";
                $result = $db->sql_query($sql);
                while ($row2 = $db->sql_fetchrow($result))
                {
                    $topic_id = (int) $row2['topic_id'];
                    $first_post_ids[$topic_id] = $row2['first_post_id'];
                    $last_post_ids[$topic_id] = $row2['last_post_id'];
                }
                $db->sql_freeresult($result);
            }
//-- end: Prime Trash Bin (Posts) -------------------------------------------//   
Find:

Code: Select all

                $row['first_post_id'] = (int) $row['first_post_id'];
                $row['last_post_id'] = (int) $row['last_post_id'];
 
After, add:

Code: Select all

//-- mod: Prime Trash Bin (Posts) -------------------------------------------//
// Here we update the last post information for the topics.
                if (stifle_posts_enabled())
                {
                    if (!empty($first_post_ids[$topic_id]))
                    {
                        $row['first_post_id'] = (int) $first_post_ids[$topic_id];
                    }
                    if (!empty($last_post_ids[$topic_id]))
                    {
                        $row['last_post_id'] = (int) $last_post_ids[$topic_id];
                    }
                }
//-- end: Prime Trash Bin (Posts) -------------------------------------------//   
The number of replies shown on the viewforum page is now the total replies, including any that were fake-deleted.
Ken F. Innes IV
My Extensions | My MODs | My Topics | My Site: Absolute Anime
Experience the wonder of Japanese Animation!

Locked

Return to “[3.0.x] MODs in Development”