Invisionize.eu - IP.Board (IPB) News

Drukowana wersja artykułu

Kliknij tutaj aby zobaczyć artykuł w oryginalnym formacie

Invisionize.eu - IP.Board (IPB) News _ IP.Content Tracker _ Callbacks cannot edit non-user editable fields

Dodane przez: Invisionize.eu czw, 29 lipiec 2010

Cross posting from the forum....

I made a test database with two fields, one user editable (field_51), one not (field_52). They're both text fields with no filtering, no formatting.

# more hooks/database_callback_7.php 
<?php

class database_callback_7
{
	protected $registry;
	protected $DB;
	protected $settings;
	protected $request;
	protected $lang;
	protected $member;
	protected $memberData;
	protected $caches;
	protected $cache;

	public function __construct( $registry )
	{
		$this->registry		= $registry;
		$this->DB		= $this->registry->DB();
		$this->settings		=& $this->registry->fetchSettings();
		$this->request		=& $this->registry->fetchRequest();
		$this->lang		= $this->registry->getClass('class_localization');
		$this->member		= $this->registry->member();
		$this->memberData	=& $this->registry->member()->fetchMemberData();
		$this->cache		= $this->registry->cache();
		$this->caches		=& $this->registry->cache()->fetchCaches();
	}
	
	public function startUp()
	{
	}

	public function preSave()
	{
		echo "This is in preSave() before any changes have been made!<BR>";
		print_r($this->request);
		$this->request['field_51'] = "I like traffic lights";
		$this->request['field_52'] = "But only when they're green";

		echo "<BR><BR>This is in preSave() after changes have been made!<BR>";
		print_r($this->request);
	}

	public function postSave()
	{
		echo "<BR><BR>This is in postSave()!<BR>";
		print_r($this->request);

		$record = $this->DB->buildAndFetch(
							 array( 'select' => 'field_51, field_52', 
								'from'   => 'ccs_custom_database_7',
						 		'order'  => 'primary_id_field desc',
								'limit'  =>  1 )
			  			  );

		echo "<BR><BR>But this is what's in the database!<BR>";
		print_r($record);
		die();
	}
}

?>



Yet, the results of an insert show that field_52 did not update:
This is in preSave() before any changes have been made!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 7 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => oh bother [dosubmit] => Save [request_method] => post ) 

This is in preSave() after changes have been made!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 7 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => I like traffic lights [dosubmit] => Save [request_method] => post [field_52] => But only when they're green ) 

This is in postSave()!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 7 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => I like traffic lights [dosubmit] => Save [request_method] => post [field_52] => But only when they're green ) 

But this is what's in the database!
Array ( [field_51] => I like traffic lights [field_52] => )



And when I switch the order, field_52 still does not update. I would not expect a change in the stack ordering to change the processing, but hey, you never know when you come up with weird errors
This is in preSave() before any changes have been made!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 8 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => oh bother [dosubmit] => Save [request_method] => post ) 

This is in preSave() after changes have been made!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 8 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => I like traffic lights [dosubmit] => Save [request_method] => post [field_52] => But only when they're green ) 

This is in postSave()!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 8 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => I like traffic lights [dosubmit] => Save [request_method] => post [field_52] => But only when they're green ) 

But this is what's in the database!
Array ( [field_51] => I like traffic lights [field_52] => )



HOWEVER if I make field_52 user editable, it then saves field_52:
This is in preSave() before any changes have been made!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 8 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => oh bother [dosubmit] => Save [request_method] => post ) 

This is in preSave() after changes have been made!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 8 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => I like traffic lights [dosubmit] => Save [request_method] => post [field_52] => But only when they're green ) 

This is in postSave()!
Array ( [app] => ccs [module] => pages [section] => pages [id] => 8 [do] => save [record] => [post_key] => e29fc01e3e3dfa873c54f24144794a9f [field_51] => I like traffic lights [dosubmit] => Save [request_method] => post [field_52] => But only when they're green ) 

But this is what's in the database!
Array ( [field_51] => I like traffic lights [field_52] => But only when they're green )


Źródło: http://community.invisionpower.com/tracker/issue-24517-callbacks-cannot-edit-non-user-editable-fields/

Powered by SD.Agregator (http://www.invisionize.eu)
© SpannerDEV (http://www.spannerdev.pl)