It was necessary to change the location of already downloaded files. Before that, all files were located in folders by dates, now I have transferred everything to the uploads folder. Further in the database I changed all the paths to the files. uploads / 2017/01 / file.doc to uploads / file.doc Everything worked out in the media library of files everything was displayed as it should be. But later I noticed that all my files were missing from the products (woocommerce). I have downloadable products with attached files. In the database, I see that by ID they remained attached, but for some reason they are no longer connected. For example:

(18370, 1358, '_downloadable_files', 'a:1:{s:32:\"cf099301da794922b99eb1ef2cb9c0d7\";a:2:{s:4:\"name\";s:0:\"\";s:4:\"file\";s:99:\"https://site.com/wp-content/uploads/file.doc\";}}'), 

What could be the problem? How to decrypt this code? Is it possible to somehow link files with products without hooking everything from zero manually?

    2 answers 2

    What could be the problem? How to decrypt this code?

    This is a serialized array .

     s:32:"cf099301da794922b99eb1ef2cb9c0d7" 

    Here 32 is the length of the string, and cf099301da794922b99eb1ef2cb9c0d7 is the string itself. If the specified length does not match the actual length, the entire array is considered damaged, and unserialize() returns false . When replacing uploads/2017/01/ to uploads/ this is exactly what happened - the length of the lines was reduced by 8 characters.

    You can perform such a replacement only with the help of tools that work correctly with serialized data - for example, WP-CLI or Search Replace DB .

    Is it possible to somehow link files with products without hooking everything from zero manually?

    As an option - roll back the changes and make a replacement correctly.

      What could be the problem?

      That got into the base with his hands. Never do that again. If possible - roll back the base. I can not imagine what could prevent the logical location of files, but to change such things there are plugins. They use API.

      How to decrypt this code?

      This is not a “code”, but an entry in the database (and something I’m suggesting is that the curve - there should be no escaping quotes). Changing the path to the files here you broke the serialized data.

      Is it possible to somehow link files with products without hooking everything from zero manually?

      More likely no than yes. Is that to carry out the reverse operation and not to invent problems for themselves out of the blue. Well, or deal with serialized data and manually change their value in the database :)