Error in submit_post function

Discussion forum for MOD Writers regarding MOD Development.
Locked
francois44
Registered User
Posts: 6
Joined: Sat Apr 18, 2015 9:34 am

Error in submit_post function

Post by francois44 » Mon Sep 14, 2015 3:55 pm

Hello,

I am using PhpBB3 API to update some post_text,
I want to correct somes posts to improve data quality by using some replace fonction.

To make those changes in the phpbb database,
I use :
generate_text_for_edit to prepare data
<do my replace in post_text>
generate_text_for_storage to prepare data for storage
submit_post("edit", to store modified post

Here an example of my code,

Code: Select all

<?php
	// Inclusion des librairies nécessaires
	define('IN_PHPBB', true);
	$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../../';
	$phpEx = substr(strrchr(__FILE__, '.'), 1);
	include($phpbb_root_path . 'common.' . $phpEx);
	include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
	include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

	// Start session management
	$user->session_begin();
	$auth->acl($user->data);

	$message= "Updating...";

	$sql = 'SELECT p.topic_id, p.post_id, p.post_subject, p.post_text, p.poster_id, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode,
				p.enable_smilies, p.enable_magic_url, p.post_subject, p.post_username, p.post_edit_reason, p.icon_id, p.post_approved,
				p.enable_sig, p.post_attachment, p.post_edit_locked, 
				t.topic_type, t.forum_id
			FROM phpbb_posts p, phpbb_topics t
			WHERE  p.topic_id=t.topic_id AND p.post_id=148218';
	$result = $db->sql_query($sql);
	while ($row = $db->sql_fetchrow($result))
	{
		$post_id = $row['post_id'];
		$poster_id = $row['poster_id']; 
		$post_subject = $row['post_subject'];
		$post_text = $row['post_text'];
		$bbcode_bitfield = $row['bbcode_bitfield'];
		$bbcode_uid = $row['bbcode_uid'];
		$post_subject = $row['post_subject'];
		$post_username = $row['post_username'];
		$topic_type = $row['topic_type'];
		$forum_id = $row['forum_id'];
		$post_edit_reason = $row['post_edit_reason'];
		$icon_id = 	$row['icon_id'];
		$post_approved = $row['post_approved'];
		$enable_bbcode = $row['enable_bbcode'];
		$enable_smilies = $row['enable_smilies'];
		$enable_magic_url = $row['enable_magic_url'];
		$enable_sig = $row['enable_sig'];
 		$post_attachment = $row['post_attachment'];
 		$post_edit_locked = $row['post_edit_locked'];
		$post_bbcode_options = $enable_bbcode + $enable_smilies + $enable_magic_url;

		$result_generate_text_for_edit = generate_text_for_edit($post_text, $bbcode_uid, $bbcode_bitfield, $post_bbcode_options);
		//var_dump($post_text_edit);
		$post_text_edit = $result_generate_text_for_edit['text'];

		//$post_text_new = str_replace($conditionFind, $conditionReplace, $post_text_edit);
		//For the test, to post my code on the forum I have simplify the program and for the moment i don't modify the post_text
		$post_text_new = $post_text_edit;
			
		$poll = $new_uid = $new_bitfield = '';
    	$allow_bbcode = $allow_urls = $allow_smilies = TRUE;
    	generate_text_for_storage($post_text_new, $new_uid, $new_bitfield, $post_bbcode_options, $allow_bbcode, $allow_urls, $allow_smilies);			
			
		$data = array(
				'post_id'				=> (int) $post_id,
				'topic_id'				=> (int) $topic_id,
				'forum_id'				=> (int) $forum_id,
				'poster_id'				=> (int) $poster_id,
				'message'				=> $post_text_new,
				'message_md5'			=> md5($post_text_new),
    			// Values from generate_text_for_storage()
    			'bbcode_bitfield'       => $new_bitfield,    // Value created from the generate_text_for_storage() function.
    			'bbcode_uid'            => $new_uid,         // Value created from the generate_text_for_storage() function.
    			'post_edit_reason'      => $post_edit_reason,
    			'icon_id'               => $icon_id,
    			'post_approved'         => $post_approved,
    			'enable_bbcode'         => $enable_bbcode,
    			'enable_smilies'        => $enable_smilies,
    			'enable_urlsss'      => $enable_magic_url,
    			'post_username'         => $post_username,
    			'enable_sig'            => $enable_sig, 
     			'post_attachment'       => $post_attachment, 
     			'post_edit_locked'      => $post_edit_locked     			
				);
				
		submit_post("edit", $post_subject, $post_username, $topic_type, $poll, $data, true, true);
	}
	$db->sql_freeresult($result);
	$message = "Result ok"

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
	<head>
 		<title>Formulaire de correction de masse des posts</title>
	</head>
	<body>

	<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); ?>" method="post">
		<?php if(!empty($message)) : ?>
		<p><?php echo $message; ?></p>
		<?php endif; ?>  
	</form>

	</body>
</html>
I volontary made a volontary erreur "enable_urlsss" instead "enable_urls" to have an error and look to the UPDATE SQL QUERY on my screen :

Code: Select all

UPDATE phpbb_posts SET post_edit_reason = '', forum_id = 3, poster_id = 544, icon_id = '0', post_approved = '1', enable_bbcode = '1', enable_smilies = '1', enable_magic_url = NULL, enable_sig = '1', post_username = '', post_subject = 'Re: (E36 318IS M44B19 AN96) Présentation VDB', post_checksum = '02d800f1c9cdafb3ee7b7da118d423e1', post_attachment = 0, bbcode_bitfield = 'EA==', bbcode_uid = '11nrouk0', post_edit_locked = '0', post_text = '<!-- s:bien: --><img src=\"{SMILIES_PATH}/bien1.gif\" alt=\":bien:\" title=\"bienvenue\" /><!-- s:bien: --> \n\nsur ce forum ,\n\nVoici quelques liens que je te demanderai de bien vouloir lire ,afin que tu comprennes au mieux le principes de fonctionnement de ce forum\n\n[url:11nrouk0]http&#58;//www&#46;darkgyver&#46;fr/reparation-BMW/affiche-fiche-technique-5-5-comment-identifier-sa-bmw&#46;html[/url:11nrouk0]\n\nA l\'issue tu pourras nous transmettre ton N° VIN ,afin que nous puissions répondre au mieux à tes questions .\nCe sont les 7 dernier chiffres de ton N° de série.\n\n[url:11nrouk0]http&#58;//www&#46;darkgyver&#46;fr/forum/presentation-des-membres-charte-et-fonctionnement-du-forum-f1/charte-du-forum-t21&#46;htm[/url:11nrouk0]\n\n[url:11nrouk0]http&#58;//www&#46;darkgyver&#46;fr/forum/t5682-limites-et-conditions-d-utilisation-du-forum&#46;[/url:11nrouk0]\n\nTitre des posts de la section résolution de problèmes techniques doivent avoir le format :\n\n[E.. M.. an..] description succincte du problème\n\nOù\n\nE.. est le type carrosserie\nM.. est le type Moteur\nan.. est l\'année de production\n\nExemple : [E36 M51 an94] Ne démarre plus\n\nMerci , de ta compréhension ,\nA bientôt sur le fofo .\nCordialement' WHERE post_id = 148218
In this query, post_username = '', this is the error.
I think the problem is in functions_posting.php, line 1808

Code: Select all

'post_username'		=> ($username && $data['poster_id'] == ANONYMOUS) ? $username : '',
I don't understand this test.
It should be : if username is not empty and poster_id is NOT anonymous
I think the error is on the forgotten NOT

Code: Select all

'post_username'		=> ($username && $data['poster_id'] != ANONYMOUS) ? $username : '',
I have remove the test to affect directly post_username : 'post_username' => $username,
and the username is correctly UPDATE

Why is this 1808 line is like that ?
Am i wrong ?

François

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51785
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Error in submit_post function

Post by Brf » Mon Sep 14, 2015 4:01 pm

The post_username should be blank, unless the post has been made by an unregistered user, in which case they are prompted to type in a username for the post.

francois44
Registered User
Posts: 6
Joined: Sat Apr 18, 2015 9:34 am

Re: Error in submit_post function

Post by francois44 » Tue Sep 15, 2015 3:07 pm

Thank you for your answer Brf, the post is correctly submit and correctly display with an empty post_username in database.
I was thinking wrong because post_username was not empty (because of forum migration)
:D

Locked

Return to “[3.0.x] MOD Writers Discussion”