XF 2.2 Challenges with Changing Entity Property from SERIALIZED_ARRAY to JSON_ARRAY

robdog

Well-known member
I have a few legacy entities that I want to change from SERIALIZED_ARRAY to JSON_ARRAY. Is it as simple as just changing the entity property type or do you have to do something with the saved data in the database? Thanks.
 
You would need to convert the saved data during the upgrade process (have a look at \XF\Install\InstallHelperTrait::entityColumnsToJson).
 
Here is a usage example in an add-on;
PHP:
public function upgrade2040019Step3(array $stepParams)
{
   $position = $stepParams[0] ?? 0;
   $stepData = $stepParams[2] ?? [];

   return $this->entityColumnsToJson('SV\VoteTally:ThreadVoteCount', ['result','vote_maps','aliases'], $position, $stepData);
}

The return type is \XF\AddOn\StepResult|array|true|null. Returning false will error, and don't mark the return type as ?array for php 7.1 type hinting or it'll error.
 
Top Bottom