Search
Other Snippets questions
Forum

How to migrate old syntax to new

Fabio Donna's Avatar Fabio Donna
Hi,
how can I batch migrate old syntax {snippet name|par1|par2} to {snippet alias="name" parameter1="par1" parameter2="par2"} in the whole site automatically?

Thank you very much
Kind regards
Peter van Westen's Avatar Peter van Westen ADMIN
You could use DB Replacer Pro and use Regular Expressions like this:
Search:
\{snippet ([^}]*)\|([^}]*)\|([^}]*)\}
Replace:
{snippet alias="\1" parameter1="\2" parameter2="\3"}
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
Another way would be to export your entire database (or only the tables that contain the content that include the {snippet} tags).
Then open that in a text editor, and do the Regular Expressions replacements in there.

Then import that back into your database.
Please post a rating at the Joomla! Extensions Directory
Fabio Donna's Avatar Fabio Donna
Thank you!
Regads
Fabio Donna's Avatar Fabio Donna
Hi again!
I have another problem.

If I have several lines like this
<a href="https://www.anysite.com/{snippet myPath}/other/path">LINK</a>

replacing it with
<a href="https://www.anysite.com/{snippet alias="myPath"}/other/path">LINK</a>
in SQL produces an error due to nested double quotes (").

Of course, the same problem happens if replacing with single quotes (') in single quoted texts:
<a href='https://www.anysite.com/{snippet myPath}/other/path'>LINK</a>
<a href='https://www.anysite.com/{snippet alias='myPath'}/other/path'>LINK</a>

Is there a way to find/replace old syntax without creating conflicts with existing quoted text?

Thank you very much!
Kind regards.

P.S.: changing the syntax without maintaining backwards compatibility was not a good idea, just like including quotes in syntax, I think. 🙂
Peter van Westen's Avatar Peter van Westen ADMIN
These are general SQL questions. That has nothing to do with Snippets.

You need to escape quotes in your SQL statement.
Please post a rating at the Joomla! Extensions Directory
Fabio Donna's Avatar Fabio Donna
Hi,
I'm sorry,I know how to escape chars but I'm talking about the RegEx search/replace method that you suggested, which cannot recognize nested quotes. It's not SQL.

Also, if Regular labs decided to switch syntax, I hoped that they offered a "scientific" procedure to migrate old syntax. Or do we developers have to go to all our customers' sites and replace all occurrences of Snippets by hand (there are thousands)?

Thank you again.
Peter van Westen's Avatar Peter van Westen ADMIN
So the error you are getting is in DB Replacer?
Please post a rating at the Joomla! Extensions Directory
Fabio Donna's Avatar Fabio Donna
No, I'm running substitution on exported database, as you kindly suggested here regularlabs.com/forum/snippets/49414-how...syntax-to-new#101348
Peter van Westen's Avatar Peter van Westen ADMIN
Yes, so that is down to the syntax in your custom SQL query.
And, like I mentioned, down to escaping quotes inside the statements.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
Tip: see the syntax of other quotes inside the content of that SQL dump.
Please post a rating at the Joomla! Extensions Directory
Fabio Donna's Avatar Fabio Donna
Yes, thank you.
The problem is that there is not only one syntax case, even in a single website.

Let's see some examples:

"bla bla bla bla {snippet name} bla bla bla bla"
"bla bla bla bla '{snippet name}' bla bla bla bla"
'bla bla bla bla "{snippet name}" bla bla bla bla'
'bla bla bla bla {snippet name} bla bla bla bla'
bla bla bla bla {snippet name} bla bla bla bla

Using {snippet alias=\"name\"} in a batch as a replacement for {snippet name} would result in:

"bla bla bla bla {snippet alias="name"} bla bla bla bla" -> WRONG
"bla bla bla bla '{snippet alias="name"}' bla bla bla bla" -> probably WRONG (not tested)
'bla bla bla bla "{snippet alias="name"}" bla bla bla bla' -> WRONG
'bla bla bla bla {snippet alias="name"} bla bla bla bla' -> OK
bla bla bla bla {snippet alias="name"} bla bla bla bla -> OK

Similar (inverted) results would be obtained with {snippet alias=\'name\'}.

In some cases {snippet alias=&quot;name&quot;} worked too, but not always.

Anyway, I'll work it out somehow.
I hoped RL made an "automatic conversion code" or a syntax backwards compatibility "switch".

Thank you.
Regards
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription