Skip to content

wp db size doesn't like if-statements in wp-config.php #76

Closed

Description

@Ipstenu

I have the following in my wp-config.php file:

if ( WP_DEBUG ) {
        @error_reporting( E_ALL );
        @ini_set( 'log_errors', true );
        @ini_set( 'log_errors_max_len', '0' );
        if ( !defined('WP_DEBUG_LOG' ) ) define( 'WP_DEBUG_LOG', true );
        if ( !defined('WP_DEBUG_DISPLAY' ) ) define( 'WP_DEBUG_DISPLAY', false);
        if ( !defined('CONCATENATE_SCRIPTS' ) ) define( 'CONCATENATE_SCRIPTS', false );
        if ( !defined('SAVEQUERIES' ) ) define( 'SAVEQUERIES', true );
}

If I have any defines after that section, any time I run wp db size I'll get this:

$ wp db size
PHP Notice:  Constant Mika_Test already defined in /usr/local/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 99

Notice: Constant Mika_Test already defined in /usr/local/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 99
+------------------+-------+
| Name             | Size  |
+------------------+-------+
| my_test_domain  | 40 MB |
+------------------+-------+

However all other commands I've tested work.

If WP_DEBUG is false, there's no error.

Activity

  1. schlessera commented on Jan 6, 2018

    @schlessera
    Member

    I cannot reproduce this behavior.

    Is it possible to post the entire wp-config.php file (without any sensitive information) ?

    Also what version are you running ( wp cli info ) ?

  2. Ipstenu commented on Jan 7, 2018

    @Ipstenu
    Author
    PHP version:	5.6.31
    php.ini used:	/etc/php56/php.ini
    WP-CLI root dir:	/usr/local/wp
    WP-CLI vendor dir:	/usr/local/wp/vendor
    WP_CLI phar path:
    WP-CLI packages dir:
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version:	1.4.1

    The rest of the wp-config.php that's abnormal are defines like this:

    // Akismet - Mika's Key
    define( 'WPCOM_API_KEY', 'SECRETKEY' );
    
    // DreamObjects Keys - Mika's Keys
    define( 'DHO_ACCESS_KEY_ID', 'SECRETKEY' );
    define( 'DHO_SECRET_ACCESS_KEY', 'SECRET-KEY' );
    
    // Amazon affiliate keys - Mika's Keys
    define( 'AMAZON_PRODUCT_API_KEY', 'SECRETKEY' );
    define( 'AMAZON_PRODUCT_API_SECRET', 'SECRETKEY' );
    
    // Limit revisions
    define( 'WP_POST_REVISIONS', 3 );
    
    define('JETPACK_IP_ADDRESS_OK', '12.34.56.78');
    
  3. schlessera commented on Jan 8, 2018

    @schlessera
    Member

    My suspicion is that you're loading your wp-config.php twice, but you're only getting redefinition errors because of this after enabling the error reporting in your above conditional. So, I don't think the conditional is the cause, but rather the thing that enables you to see the symptoms after that point.

    Now, why would your wp-config.php be loaded twice?

    I have to assume this is a problem of your environment, not of WP-CLI source code, so I'm closing this for now. But please ping me on the Slack #cli team to discuss and debug further. If we should indeed locate a bug, I'll reopen of course.

  4. Ipstenu commented on Jan 8, 2018

    @Ipstenu
    Author

    That was my thought, however...

    It literally only happens when I run wp db size

    If I was loading it twice, it stands to reason that it would error every time, right?

  5. schlessera commented on Jan 8, 2018

    @schlessera
    Member

    Can you run the command --debug to see where exactly the error message is thrown?

  6. gitlost commented on Jan 8, 2018

    @gitlost
    Contributor

    Note there was a hack used to call Runner::load_wordpress() in the db commands db size, db prefix and db search with error suppression in WP-CLI 1.4.1 to make sure $wpdb was available, even though Runner::get_wp_config_code() had already been called, so that's why wp-config.php is getting loaded twice.

    However you should get the same error running db prefix or db search.

  7. schlessera commented on Jan 8, 2018

    @schlessera
    Member

    Ah, yes, @gitlost is right.

    @Ipstenu Can you try the same command with the nightly to check whether the error is gone for you? It should already be fixed with the current master code...

  8. Ipstenu commented on Jan 8, 2018

    @Ipstenu
    Author

    Confirmed it happens using db prefix - I'll spin up a box and update to nightly to test that as soon as I can.

  9. Ipstenu commented on Jan 11, 2018

    @Ipstenu
    Author

    The first two tests I did make me think this will work. I'm rebuilding one of the exact sites from the field to be double sure :)

  10. danielbachhuber commented on Jan 16, 2018

    @danielbachhuber
    Member

    Can you try the same command with the nightly to check whether the error is gone for you? It should already be fixed with the current master code...

    Specifically, this was #57

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions