0

This works -

$serialized = 'a:23:{s:6:"fields";a:5:{s:21:"display_name_creditor";s:1:"1";s:24:"display_name_constituent";s:1:"1";s:14:"email_creditor";s:1:"1";s:14:"phone_creditor";s:1:"1";s:12:"total_amount";s:1:"1";}s:5:"id_op";s:2:"in";s:8:"id_value";a:0:{}s:21:"receive_date_relative";s:1:"0";s:17:"receive_date_from";s:0:"";s:15:"receive_date_to";s:0:"";s:25:"contribution_status_id_op";s:2:"in";s:28:"contribution_status_id_value";a:1:{i:0;s:1:"1";}s:16:"total_amount_min";s:0:"";s:16:"total_amount_max";s:0:"";s:15:"total_amount_op";s:3:"lte";s:18:"total_amount_value";s:0:"";s:6:"gid_op";s:2:"in";s:9:"gid_value";a:0:{}s:8:"tagid_op";s:2:"in";s:11:"tagid_value";a:0:{}s:11:"description";s:20:"Soft Credit details.";s:13:"email_subject";s:0:"";s:8:"email_to";s:0:"";s:8:"email_cc";s:0:"";s:10:"permission";s:21:"access CiviContribute";s:6:"groups";s:0:"";s:9:"domain_id";i:1;}';

$result = unserialize($serialized);

This does not -

$serialized = 'a:23:{s:6:"fields";a:5:{s:21:"display_name_creditor";s:1:"1";s:24:"display_name_constituent";s:1:"1";s:14:"email_creditor";s:1:"1";s:14:"phone_creditor";s:1:"1";s:12:"amount";s:1:"1";}s:5:"id_op";s:2:"in";s:8:"id_value";a:0:{}s:21:"receive_date_relative";s:1:"0";s:17:"receive_date_from";s:0:"";s:15:"receive_date_to";s:0:"";s:25:"contribution_status_id_op";s:2:"in";s:28:"contribution_status_id_value";a:1:{i:0;s:1:"1";}s:16:"total_amount_min";s:0:"";s:16:"total_amount_max";s:0:"";s:15:"total_amount_op";s:3:"lte";s:18:"total_amount_value";s:0:"";s:6:"gid_op";s:2:"in";s:9:"gid_value";a:0:{}s:8:"tagid_op";s:2:"in";s:11:"tagid_value";a:0:{}s:11:"description";s:20:"Soft Credit details.";s:13:"email_subject";s:0:"";s:8:"email_to";s:0:"";s:8:"email_cc";s:0:"";s:10:"permission";s:21:"access CiviContribute";s:6:"groups";s:0:"";s:9:"domain_id";i:1;}'

I have just changed the total_amount field to amount and I receive this error --

unserialize(): Error at offset 181 of 849 bytes

I've checked the solution provided at unserialize() [function.unserialize]: Error at offset & http://davidwalsh.name/php-serialize-unserialize-issues, but nothing worked.

Also tried using base64_encode/decode before serialize/unserialize

Any hints ?

Community
  • 1
  • 1
jitendrapurohit
  • 9,435
  • 2
  • 28
  • 39
  • 2
    Unserialize the working string, rename the index in the array and serialize it. If you don't know what you are doing, don't change the serialized string yourself. – Charlotte Dunois Sep 07 '15 at 10:45
  • 1
    We have a set of serialized value defined in the db before installation of our software for some known reason, which has a change of field_name. Hence, it is required to pre-edit those values, which I try to do here. – jitendrapurohit Sep 07 '15 at 10:52

1 Answers1

6

The second one is invalid the reason being that field s:12:"amount" states that this value is a string of length 12. However amount only has 6 bytes. so you want to use s:6:"amount"

That being said its probably easier to unserialize then make a change then serialize the new value.

Victory
  • 5,811
  • 2
  • 26
  • 45