Jump to content
DevFuse Forums
Sign in to follow this  
ShaneV

Custom edit mod tools

Recommended Posts

Hi,

 

I'm making an addon for my mods and everything working fine but i have one problem.

When a mod use it his postcount resets to 0 and also the reply count of the topic.

 

But i really cant see the problem or solution :p

 

Piece of the cake :p

 

		if($this->request['postREPLY'] == 'y')
	{
		$reply_author = "".$_COOKIE['member_id']."";
		$reply_author_name = $this->DB->buildAndFetch( array( 'select' => 'name', 'from' => 'members', 'where' => "member_id={$reply_author}") );

		$time_stamp = time();

		$mod_message = $this->request['reason'];

		$search  = array( "/%topic_title%/", "/%topic_link%/", "/%reason_note%/" );
		$replace = array( $this->topic['title'], "[url='{$this->settings['board_url']}/index.php?showtopic={$this->topic['tid']}']{$this->settings['board_url']}/index.php?showtopic={$this->topic['tid']}[/url]", $mod_message );			

		$tmessage = $this->settings['bs_advancedmodtools_disapprove_tm'];
		$tmessage = str_replace("\n", "<br />", $tmessage );

		$tmessage = preg_replace( $search, $replace, $tmessage );

		$this->DB->insert( 'posts', array(
											'author_id'			=> $reply_author,
											'author_name'		=> $reply_author_name,
											'ip_address'		=> '127.0.0.1',
											'post_date'			=> $time_stamp,
											'post'				=> $tmessage,
											'topic_id'			=> $this->topic['tid'] ,
						)				);			

		$this->DB->update( 'topics', array( 'posts' => 'posts+1',
											'last_poster_id' => $reply_author, 
											'last_post' => $time_stamp,
											'last_poster_name' => $reply_author_name['name']
										),
											'tid=' . $this->topic['tid'] 
							);

		$this->DB->update( 'members', array( 'posts' => 'posts+1' ),
											'member_id=' . $reply_author 
							);								

	}

Share this post


Link to post
Share on other sites

Both your 'posts+1' updates won't work. There are 2 ways to have the post count increase.

 

1. This is from IPB3 own update query for post count. (Ideal for the topic post count, as you can include your last poster info as well.)

 

				$ta = array (
						  'db_field1'		=> 'blahblah',
						  'db_field2'	=> 'test2'
						);

			$this->DB->buildAndFetch( array( 'update' => 'topics', 'set' => $this->DB->compileUpdateString( $ta ) . ", posts=posts+1", 'where' => 'tid='.$tid ) );

 

2. The set data doesn't have to be in array format, it's either true then false or false then true at the end.

 

$this->DB->update( 'members', 'posts=posts+1', 'member_id=' . $reply_author, true, false ); 

 

If there is no specific reason, I suggest you use IPB3's inbuilt topic function, will handle all this plus other topic related functions.

Share this post


Link to post
Share on other sites

Hi thanks Michael,

 

Query's looks like this now:

Wont reset to zero but also not increasing the count for topic count and user post count.

 

			$this->DB->insert( 'posts', array(
											'author_id'			=> $reply_author,
											'author_name'		=> $reply_author_name,
											'ip_address'		=> '127.0.0.1',
											'post_date'			=> $time_stamp,
											'post'				=> $tmessage,
											'topic_id'			=> $this->topic['tid'] ,
						)				);			

		$this->DB->update( 'topics', array( 'last_poster_id' => $reply_author, 
											'last_post' => $time_stamp,
											'last_poster_name' => $reply_author_name['name']
										),
											'tid=' . $this->topic['tid'] 
							);


		$this->DB->update( 'topics', 'posts=posts+1', 'tid=' . $this->topic['tid'], true, false ); 
		$this->DB->update( 'members', 'posts=posts+1', 'member_id=' . $reply_author, true, false ); 

 

I'm i still doing something wrong?

 

Grtz Shane

Share this post


Link to post
Share on other sites

Try the other way around.

 

                        $this->DB->update( 'topics', 'posts=posts+1', 'tid=' . $this->topic['tid'], false, true ); 
                       $this->DB->update( 'members', 'posts=posts+1', 'member_id=' . $reply_author, false, true ); 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×