New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internalize `like_escape()` and `esc_sql()` functions to avoid `$wpdb` dependency #65

Closed
andrewalcantara opened this Issue Dec 3, 2017 · 4 comments

Comments

5 participants
@andrewalcantara

andrewalcantara commented Dec 3, 2017

Received a Fatal Error when running the following command:

$ wp db search "hello" --path=/Users/andrew/wp/

Fatal error: Call to undefined function like_escape() in /Users/andrew/wp-cli/db-command/src/DB_Command.php on line 1081

Scenarios:

  1. When running the command inside the db-command directory, that is when the error appear.
  2. When running the command in my home directory, the error does not appear.

My environment:

$ wp --info
PHP binary:	/usr/bin/php
PHP version:	5.6.30
php.ini used:	
WP-CLI root dir:	phar://wp-cli.phar
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/andrew/wp-cli/db-command
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	/Users/andrew/wp-cli/db-command/wp-cli.yml
WP-CLI version:	1.4.1
@miya0001

This comment has been minimized.

Show comment
Hide comment
@miya0001

miya0001 Dec 3, 2017

Member

Thanks @andrewalcantara 😊

I saw the same problem with the behat like following.

$ vendor/bin/behat features/db-search.feature 

  Scenario: Search with custom colors                                                                                                                                # features/db-search.feature:897
    Given a WP install                                                                                                                                               # features/steps/given.php:73
    When I run `SHELL_PIPE=0 wp db search example.com`                                                                                                               # features/steps/when.php:29
      $ SHELL_PIPE=0 wp db search example.com
      
      Fatal error: Uncaught Error: Call to undefined function like_escape() in src/DB_Command.php:1081
      Stack trace:
      #0 src/DB_Command.php(864): DB_Command::esc_like('example.com')
      #1 [internal function]: DB_Command->search(Array, Array)
      #2 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(81): call_user_func(Array, Array, Array)
      #3 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
      #4 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(401): call_user_func(Object(Closure), Array, Array)
      #5 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(323): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
      #6 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(330): WP_CLI\Runner->run_command(Array, Array)
      #7 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php( in src/DB_Command.php on line 1081
      
      PHP Fatal error:  Uncaught Error: Call to undefined function like_escape() in src/DB_Command.php:1081
      Stack trace:
      #0 src/DB_Command.php(864): DB_Command::esc_like('example.com')
      #1 [internal function]: DB_Command->search(Array, Array)
      #2 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(81): call_user_func(Array, Array, Array)
      #3 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
      #4 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(401): call_user_func(Object(Closure), Array, Array)
      #5 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(323): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
      #6 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(330): WP_CLI\Runner->run_command(Array, Array)
      #7 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php( in src/DB_Command.php on line 1081
      cwd: /var/folders/r8/93smf9ld3lgdsn7ly3s5hj940000gr/T/wp-cli-test-run-db-search.feature.897-5a245cf9a89898.01545215/
      run time: 0.33373379707336
      exit status: 255
Member

miya0001 commented Dec 3, 2017

Thanks @andrewalcantara 😊

I saw the same problem with the behat like following.

$ vendor/bin/behat features/db-search.feature 

  Scenario: Search with custom colors                                                                                                                                # features/db-search.feature:897
    Given a WP install                                                                                                                                               # features/steps/given.php:73
    When I run `SHELL_PIPE=0 wp db search example.com`                                                                                                               # features/steps/when.php:29
      $ SHELL_PIPE=0 wp db search example.com
      
      Fatal error: Uncaught Error: Call to undefined function like_escape() in src/DB_Command.php:1081
      Stack trace:
      #0 src/DB_Command.php(864): DB_Command::esc_like('example.com')
      #1 [internal function]: DB_Command->search(Array, Array)
      #2 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(81): call_user_func(Array, Array, Array)
      #3 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
      #4 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(401): call_user_func(Object(Closure), Array, Array)
      #5 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(323): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
      #6 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(330): WP_CLI\Runner->run_command(Array, Array)
      #7 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php( in src/DB_Command.php on line 1081
      
      PHP Fatal error:  Uncaught Error: Call to undefined function like_escape() in src/DB_Command.php:1081
      Stack trace:
      #0 src/DB_Command.php(864): DB_Command::esc_like('example.com')
      #1 [internal function]: DB_Command->search(Array, Array)
      #2 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(81): call_user_func(Array, Array, Array)
      #3 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
      #4 vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(401): call_user_func(Object(Closure), Array, Array)
      #5 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(323): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
      #6 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(330): WP_CLI\Runner->run_command(Array, Array)
      #7 vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php( in src/DB_Command.php on line 1081
      cwd: /var/folders/r8/93smf9ld3lgdsn7ly3s5hj940000gr/T/wp-cli-test-run-db-search.feature.897-5a245cf9a89898.01545215/
      run time: 0.33373379707336
      exit status: 255
@miya0001

This comment has been minimized.

Show comment
Hide comment
@miya0001

miya0001 Dec 3, 2017

Member

@schlessera

It looks same problem with you said at contributor day in WCUS.

Member

miya0001 commented Dec 3, 2017

@schlessera

It looks same problem with you said at contributor day in WCUS.

@gitlost

This comment has been minimized.

Show comment
Hide comment
@gitlost

gitlost Dec 3, 2017

Contributor

Somewhat related wp-cli/wp-cli#4527 (comment)

If you do

composer require wp-cli/wp-cli:dev-master # Make sure have latest wp-cli master
git checkout composer.json # Undo the composer.json change

then the problem should hopefully disappear.

(However I think it would make sense to shim these 2 WP functions like_escape() and esc_sql() both here in db-command and in search-replace as they're trivial and would avoid any dependency except on wpdb.)

Edit: core-command -> wp-cli.

Contributor

gitlost commented Dec 3, 2017

Somewhat related wp-cli/wp-cli#4527 (comment)

If you do

composer require wp-cli/wp-cli:dev-master # Make sure have latest wp-cli master
git checkout composer.json # Undo the composer.json change

then the problem should hopefully disappear.

(However I think it would make sense to shim these 2 WP functions like_escape() and esc_sql() both here in db-command and in search-replace as they're trivial and would avoid any dependency except on wpdb.)

Edit: core-command -> wp-cli.

@danielbachhuber danielbachhuber changed the title from Fatal error: Call to undefined function `like_escape()` to Internalize `like_escape()` and `esc_sql()` functions to avoid `$wpdb` dependency Dec 4, 2017

@schlessera

This comment has been minimized.

Show comment
Hide comment
@schlessera

schlessera Dec 5, 2017

Member

Related: #66

Member

schlessera commented Dec 5, 2017

Related: #66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment