0

I have some records in a CMS that include HTML fragments with custom tags for a widget tool. The maker of the CMS has apparently updated their CMS without providing proper data conversion. Their widgets use keys for layout based on screen width such as block_lg, block_md, block_sm. The problem kicks in with the fact they used to have a block_xs and they have now shifted them all -- dropping the block_xs and instead placing a block_xl on the other end. We don't really use these things, but their widget configurations do. What this means for us is the values for each key are identical. The problem occurs when the updated CMS code is looking for the 'block_xl' in any widget definition tags, it can't find it and errors out.

What I'm thinking then is that the new code will appear to 'ignore' the block_xs due to how it reads the tags. (and similarly, the old code will ignore block_xl) Since the values for each are identical, I need to basically read any widget definition and add a block_xl value to it matching the value of [any one of] the other width parameters.

Since the best place order-wise would be 'before' the block_lg value, it's probably easiest to do it as follows:

Replace any thing matching posix style regex matching /block_lg(="\d+,\d+")/ with: block_xl="$1" block_lg="$1"

Or whatever the equivalent of that would be.

Example of an existing CMS block with multiple widget definitions:

<div>{{widget type="CleverSoft\CleverBlock\Block\Widget"
      widget_title="The Album" classes="highlight-bottom modish greenfont font52 fontlight"
      enable_fullwidth="0" block_ids="127" lazyload="0"
      block_lg="127,12," block_md="127,12," block_sm="127,12," block_xs="127,12,"
      template="widget/block.phtml" scroll="0" background_overlay_o="0"}}</div>
<!-- Image Block -->
<div>{{widget type="CleverSoft\CleverBlock\Block\Widget"
       widget_title="What’s Your Favorite Cover Style?"
       classes="zoo-widget-style2 modish grey font26 fontlight"
       enable_fullwidth="0" block_ids="126" lazyload="0"
       block_lg="126,12," block_md="126,12," block_sm="126,12," block_xs="126,12,"
       template="widget/block.phtml" scroll="0" background_overlay_o="0"}}</div>

What I would prefer to end up with from the above (adding block_xl):

<div>{{widget type="CleverSoft\CleverBlock\Block\Widget"
      widget_title="The Album" classes="highlight-bottom modish greenfont font52 fontlight"
      enable_fullwidth="0" block_ids="127" lazyload="0"
      block_xl="127,12," block_lg="127,12," block_md="127,12," block_sm="127,12," block_xs="127,12,"
      template="widget/block.phtml" scroll="0" background_overlay_o="0"}}</div>
<!-- Image Block -->
<div>{{widget type="CleverSoft\CleverBlock\Block\Widget"
       widget_title="What’s Your Favorite Cover Style?"
       classes="zoo-widget-style2 modish grey font26 fontlight"
       enable_fullwidth="0" block_ids="126" lazyload="0"
       block_xl="126,12," block_lg="126,12," block_md="126,12," block_sm="126,12," block_xs="126,12,"
       template="widget/block.phtml" scroll="0" background_overlay_o="0"}}</div>

I know how to do it in php and if necessary, I will just replace it on my local DB and write an sql script to update the modified records, but the html blocks can be kind of big in some cases. It would be preferable, if it is possible, to make the substitutions right in the SQL but I'm not sure how to do it or if it's even possible to do. And yes, there can be more than one instance of a widget in any given cms page or block. (i.e. there may be a need for more than one such substitutions with different local 'values' assigned to the block_lg)

If anyone can help me do it in SQL, it would be greatly appreciated.

for reference, the tables effected are called cms_page and cms_block, the name of the row in both cases is content SW

Scott
  • 7,983
  • 2
  • 26
  • 41
  • What version of SQL are you using? T-SQL has the REPLACE function that can be used in a query to accomplish what you want. – PKatona Sep 12 '18 at 16:03
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Edward Sep 12 '18 at 16:40
  • If you absolutely have to, you may be able to use some of the XML functionalities of SQL, but SQL isn't really the best tool for text manipulation or parsing. Regardless, this is definitely a huge backwards compatibility bug on the CMS' part, and unless they specifically said they won't handle back compat, they should be taken to task. It would be polite to ask them first to address it, but if they won't, their name should be shared as openly as possible so that when the next person runs into this issue, they'll be able to find the correct help. – Shawn Sep 12 '18 at 16:50
  • cool, thanks for the suggestions. It's kinda what I thought so I did it using PHP in the meantime once I got assurance that they could run it on the deploy. – Scott Sep 21 '18 at 18:58

0 Answers0