welaika / wordmove

Multi-stage command line deploy/mirroring and task runner for Wordpress
https://wptools.it/wordmove
MIT License
1.87k stars 165 forks source link

How to escape quotes in a hook #585

Closed herbie4 closed 4 years ago

herbie4 commented 4 years ago

Hi all, Trying to run a mysql query in a hook but need to escape quotes in the where clause on the option_name to make it work. Any ideas...?

- 'mysql --host=localhost --user=wp --password=wp --database=myDB --execute="DELETE FROM wp_options WHERE wp_options.option_name='_transient_fusion_fontawesome_en'"'

alessandro-fazzi commented 4 years ago

Do you have an error output to start with? Have you already tried some solutions?

herbie4 commented 4 years ago

Do you have an error output to start with? Have you already tried some solutions?

Yes tried the query directly in the commandline and then it works. The problem is that I need to use '_transient_fusion_fontawesome_en' with quotes for the query to work, but in the hook I cannot use ' ' these quotes again. If they are in the hook as shown before I get this error: local | Output: ERROR 1054 (42S22) at line 1: Unknown column '_transient_fusion_fontawesome_en' in 'where clause'

alessandro-fazzi commented 4 years ago

Isn't simply

'mysql --host=localhost --user=wp --password=wp --database=myDB --execute="DELETE FROM wp_options WHERE wp_options.option_name=\'_transient_fusion_fontawesome_en\'"'

a solution someway?

herbie4 commented 4 years ago

Isn't simply

'mysql --host=localhost --user=wp --password=wp --database=myDB --execute="DELETE FROM wp_options WHERE wp_options.option_name=\'_transient_fusion_fontawesome_en\'"'

a solution someway?

Nope. Tried that as first option. Error: (<unknown>): did not find expected '-' indicator while parsing a block collection at line 57 column 11 (Psych::SyntaxError)

herbie4 commented 4 years ago

@pioneerskies SOLVED! Thank you for putting me on the right path. The sollution is actualy simple. I just needed to use 2 single quotes in front and in the back and it works. So -> ''_transient_fusion_fontawesome_en''

alessandro-fazzi commented 4 years ago

Inception escaping black magic (as in the majority of software that uses such configurations!). Good catch. But when the scenario get worst than this i think it's necessary to add a bash script in the project and invoke it through the hook. That's really the most solid solution.

Cheers