Jump to content

Problem saving comments (Page::statusCorrupted)


JoshoB
 Share

Recommended Posts

In an attempt to fend off comment spam, I apparently made a change that screwed ProcessWire up in a manner that I am unable to solve. Trying to post a comment now results in the following error: 

=== 

Error: Exception: Can't save field from page 1410: /blog/ancient-greeks-in-egypt/: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [Page::statusCorrupted] (in /sites/netjer.nl/www/wire/core/Pages.php line 654)

#0 [internal function]: Pages->___saveField(Object(Page), 'comments')
#1 /sites/netjer.nl/www/wire/core/Wire.php(271): call_user_func_array(Array, Array)
#2 /sites/netjer.nl/www/wire/core/Wire.php(229): Wire->runHooks('saveField', Array)
#3 /sites/netjer.nl/www/wire/core/Page.php(1004): Wire->__call('saveField', Array)
#4 /sites/netjer.nl/www/wire/core/Page.php(1004): Pages->saveField(Object(Page), 'comments')
#5 /sites/netjer.nl/www/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php(316): Page->save('comments')
#6 /sites/netjer.nl/www/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php(229): CommentForm->processInput()
#7 /sites/netjer.nl/www/wire/modules/Fieldtype/FieldtypeComments/CommentArray.php(63): CommentForm->render()
#8 /sites/netjer.

This error message was shown because you are logged in as a Superuser. Error has been logged.

===

I am using a modified version of the blog profile. 

The only thing I changed at one point was to add the security_field trick to $page->comments->renderForm that Ryan once posted on these boards as a simple way to try to block spammers (it works with hiding/showing the form using CSS and JavaScript). Removing it did not solve the problem. I looked at some other files, including the renderComments function that comes with the blog profile, but I didn't change anything there. 

Another possibility: I changed the status of spammed comments to "spam" before the error occurred. I don't think that's the problem, because I get these errors even on pages with zero comments. 

Where does one put $page->setOutputFormatting(false) in this case, and why was it not required earlier?

Thanks for your help!

Link to comment
Share on other sites

I can't really tell if you made any changes to the comments module itself, or if all your changes are in your template

The error suggest that you are missing line 315 of the commentForm.php file:

315/    $this->page->setOutputFormatting(false);
316/  $this->page->save($this->commentsField->name);

You can read more about the setting here: http://cheatsheet.processwire.com/?filter=setoutputformatting

If that line 315 is still intact, then we need to look further. Can you post the exact code you have for the security_field trick?

EDIT: Based on that post of Ryan's (http://processwire.com/talk/topic/960-comment-spam-filtering-alternatives/), I am guessing the only php change you made was to use: 

echo $page->comments->renderForm(array('requireSecurityField' => 'security_field'));

which should be fine.

Link to comment
Share on other sites

Thanks for the reply!

I never make any changes to core, so the module files are all as they were.

I have removed the security_field trick, so I'm not sure what's causing the problem now. The relevant part of the code, in markup/comments.php (blog profile), is this:

// If we are viewing a post page, then output a comments form
if($page->template == 'post') {
	// Add the category so we can change the colour of the submit button
	$id = trim($page->category); 
	$category = $pages->get($id);
	$short_category = str_replace(" ", "-", $category->title);
	$class = (isset($short_category) && trim($short_category) != "")? "-" . strtolower($short_category) : "";
	echo "<div id=\"comment-form" . $class . "\">";
	
	// Render the form
	echo $page->comments->renderForm(array(
		'headline' => '<h4>' . __('Post a comment') . '</h4>', // Post comment headline
		'successMessage' => "<p>" . __('Thank you, your submission has been saved.') . "</p>",
		'pendingMessage' => "<p>" . __('Thank you, your comment has been submitted and is pending approval.') . "</p>", 
		'errorMessage' => "<p>" . __('Your submission was not saved due to one or more errors. Try again.') . "</p>",
		'redirectAfterPost' => true
		));

	// Close the divs
	echo "</div>"; // Colour change div
	echo "</div>"; // Close #comments
}

I cannot figure out what is causing the problem now.

Edit: I originally stuck 'requireSecurityField' => 'security_field' above 'redirectAfterPost', which is when the problem started to occur. Removing it did not solve the issue. 

Link to comment
Share on other sites

As an update, downloading a fresh ZIP-archive of ProcessWire and dropping FieldtypeComments on the server did not solve the problem, so the issue is related somehow to the templates. But the only file that was modified, as far as I can tell, was markup/comments.php. Commenting out the array inside $page->comments->renderForm doesn't seem to do anything, either; I keep getting that error. 

Edit: I also deleted all of the spam comments, thinking that perhaps this was what caused the problem. No luck, either. 

Edit 2: reverting markup/comments.php to an earlier version also seems not to have changed anything. I'm starting the think the problem is located somewhere deeper, but I cannot remember changing any other files. Could it be a problem on the server somehow? My host changing some setting somewhere? Seems unlikely.

Link to comment
Share on other sites

Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [Page::statusCorrupted] 

I'm not really sure of the source of the issue here, but can answer some things about the original error you received here. Page::statusCorrupted means that some code modified the value of a page field when output formatting was ON. That means that the page is in a state where saving it could cause data corruption (like saving formatted data to the DB). The way to prevent this error is to ensure that output formatting is OFF before you retrieve and populate back any values to the $page that will be saved. You can turn off output formatting via $page->setOutputFormatting(false); or just: $page->of(false); 

If we look at the code where the error originated, it's a bit unusual because output formatting is being turned off before the save(); 

I would look in code unrelated to and above your comments code to see if you are setting any field values to the page. Given that the page has statusCorrupted and we can clearly see $page->setOutputFormatting(false); that means that the page had already been corrupted before your comments were even rendered. Meaning, I think there is a good chance this is not related to comments at all. Check what's in your own code (any $page->set(key,value) or $page->field = "value" anywhere?) and if you don't see anything there let us know what 3rd party modules are installed. 

  • Like 2
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...