5

The new field type subform does not retrieve old data repeatable, even fields have the same names. I created many posts with repeatable. The data are stored in extra fields of com_conent. attribs exactly the column.

This is the structure of all my data obsolete repeatable field

"image_gallery":"{\"image\":[\"images\/portfolio\/default\/web\/web_01.jpg\",\"images\/portfolio\/default\/web\/web_02.jpg\"],\"image_alt\":[\"\",\"\"]}"

This is the structure of the new subform field with the same data.

"image_gallery":{"image_gallery0":{"image":"images\/portfolio\/default\/web\/web_01.jpg","image_alt":""},"image_gallery1":{"image":"images\/portfolio\/default\/web\/web_02.jpg","image_alt":""}}

Question: How can I make a SQL query to alter the old data to upgrade to the new structure.

Please I need a query a script or whatever to update such data. Thanks in advance.

  • Good question. Personally I'm probably going to fork the old repeatable form fields for my extension when J4.x is released, as I absolutely hate the new subform fields – Lodder Aug 6 '16 at 18:46
  • 1
    @Lodder may I ask why? IMO the new subform is better and easier to use – webchun Nov 10 '16 at 13:28
  • @webchun - Subforms have more functionality, but I like the fact repeatable fields appear in a modal and generally more simplistic. – Lodder Nov 10 '16 at 14:00
1

I don't recommend you to process this data with an SQL query. Its not bulletproof and you don't have a tools to validate the data. Why? You would have to work strictly on strings that can lead to broken data. Not to mention that creating and testing a proper query would take ages.

Solution

What I would recommend is to do it through CLI Joomla! application. You gonna have access to the Joomla! framework and you can use all sort of Joomla! tables and models to validate/process data. You would also be able to check if data is not broken. Of course you should do it on website copy or at least have a backup of your database. You can easily force the CLI application to work from browser too if you prefer that way.

Example CLI application

For examples you can look into /cli directory inside your Joomla! installation or here: https://github.com/joomla/joomla-cms/blob/staging/cli/garbagecron.php

  • @Leoalv is this an "acceptable" answer? Please always progress your questions toward a resolution so that future researchers can be confidently educated by the posted solution. If you are needing a bit more support please edit your question to express what is left to solve. – mickmackusa May 27 '18 at 5:25
  • @mickmackusa That is the best solution. Re-arranging JSON in a query is a terrible idea, a lot can go wrong, not to mention that the query would be really complicated and hard to debug. Building a CLI application for that is the easiest and most testable solution. I will not write a code for someone. If any one has the skills for that the answer was enough, if not, then its better to delegate the task for some one more experienced cause mistakes here can damage database data. – Artur Stępień May 27 '18 at 18:46
  • I only meant to urge the OP to award the green tick; I merely hedged my request to make my comment less demanding. I like to see open questions resolved -- for several reasons. – mickmackusa May 27 '18 at 23:09
  • @mickmackusa The user seems inactive. So wouldn't count on Answer Accept. – Artur Stępień May 28 '18 at 9:46
  • Color me optimistic. If nothing comes, at least I tried. – mickmackusa May 28 '18 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.