Chance Posted Tuesday at 06:11 PM Report Posted Tuesday at 06:11 PM When editing a contact in admin, Blesta triggers the Contacts.get event for plugins to append custom properties to the contact object passed in params. The addt'l properties are present in the resultant Blesta view. But as soon as try to save the contact, a 500 error. Below is the error logged. This problem did not exist in v5.11.3. I believe it just surfaced after patching to v5.11.4. [2025-06-09T23:06:02.853593+00:00] general.ERROR: E_RECOVERABLE_ERROR: Object of class stdClass could not be converted to string {"code":4096,"message":"Object of class stdClass could not be converted to string","file":"/chroot/home/%username%/%userdomain%/html/app/models/contacts.php","line":401} The error is triggered within Blesta's Contacts Model on line 401 within the edit() method: // Calculate the changes made to the contact and log those results $diff = array_diff_assoc($old_contact, (array) $new_contact); At that point in code, the Contacts Model has first retrieved an old_contact record using $this->get(), and a new contact record also using $this->get(). The added properties are present in the $old_contact and $new_contact variables during the attempt to save the contact. PHP is throwing the 500 error because the contacts being compared have nested properties. If we just assign properties like: $contact->property1 = 'value #1'; $contact->property2 = 'value #2'; $contact->property3 = 100; Then there is no 500 error. But if we assign an object (or even an array) as a custom property to the contact, 500 error when save. Reporting this as a bug only because if we are permitted to append properties to a contact object in Blesta, then we need a way to encapsulate those appended properties such that another plugin that ALSO appends custom properties does not have potential to overwrite our plugin's custom properties. You can replicate this problem by having one or more plugins listen for the Contacts.get event. Here is a short excerpt of basically what we are doing. We could either define a custom array property, or object property. They both yield 500 when saving. // event handler for Blesta's Contacts.get event trigger public function getContact( $event ) { $params = $event->getParams(); $contact = $params['contact']; if( $contact ) { // append arbitrary data to contact using a nested property (this WILL trigger 500 error when Blesta saves the contact) $contact->meta = new \StdClass; $contact->meta->member_number = 93; $contact->meta->ancestor = 537; // append arbitrary data to contact using simple property (this will NOT trigger 500 error when Blesta saves the contact) $contact->member_number = 93; $contact->ancestor = 537; // set modified contact back into params $params['contact'] = $contact; } // set params back into event to pass back to trigger $event->setParams($params); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.