lsst-epo / canto-dam-assets

Canto/Craft DAM Integration Plugin
MIT License
0 stars 0 forks source link

Re-save entries after updating to Craft >= `4.6.0` & Canto DAM Assets >= `4.1.0` #8

Open khalwat opened 4 months ago

khalwat commented 4 months ago

After you update to Craft >= 4.6.0, and Canto DAM Assets >= 4.1.0, due to a bug in Craft that I fixed via PR in Craft 4.6, the existing data in the JSON columns will be double-encoded as JSON. So for the full webhook updating to work with updating or deleting individual assets inside of a multi-selection or album selection of assets, the entries will need to be re-saved via:

php craft resave/entries

https://craftcms.com/docs/4.x/console-commands.html#resave-entries

This will cause the data in the fields to be re-saved, and then should be in valid single-encoded JSON format.

Once you've done this and are satisfied everything has been resaved properly, you can remove the double-decoding here if you want:

https://github.com/lsst-epo/canto-dam-assets/blob/develop-v4/src/fields/CantoDamAsset.php#L106

This:

            // We are doing this twice to work around a Craft bug for now:
            // https://github.com/craftcms/cms/issues/13916
            $config['cantoAssetData'] = Json::decodeIfJson($config['cantoAssetData'] ?? []);
            $config['cantoAssetData'] = Json::decodeIfJson($config['cantoAssetData'] ?? []);
            $config['cantoAlbumData'] = Json::decodeIfJson($config['cantoAlbumData'] ?? []);
            $config['cantoAlbumData'] = Json::decodeIfJson($config['cantoAlbumData'] ?? []);

...should become this:

            $config['cantoAssetData'] = Json::decodeIfJson($config['cantoAssetData'] ?? []);
            $config['cantoAlbumData'] = Json::decodeIfJson($config['cantoAlbumData'] ?? []);

It shouldn't harm anything if it is left in, however, because it just won't decode the JSON twice if it is properly single-encoded. It was just a hack I added until the PR ended up fixing the issue properly in Craft >= 4.6.0