• Resolved threadi

    (@threadi)


    Hello,

    I already use the plugin in some projects, but now I encountered a strange problem with the WP CLI.

    It concerns an online store with thousands of products. In the browser, the delivery time is super optimized by the plugin.

    The product data is regularly synchronized via WP CLI. The WordPress Importer plugin from WordPress is used for this, but slightly adapted for additional product data.

    The problem:
    As soon as APCu Manager is activated, the import via WP CLI does not go through. An error message is then displayed for each product.

    Failed to import “XY42”: Invalid post type

    This text is generated by the WordPress Importer plugin. Here is the location: https://github.com/WordPress/wordpress-importer/blob/master/src/class-wp-import.php#L635 – apparently it no longer finds the post type as soon as APCu Manager is activated.

    As soon as APCu Manager is deactivated, the message no longer appears and the import runs as it should.

    Is there a solution for this? Many thanks in advance ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Pierre Lannoy

    (@pierrelannoy)

    Hello @threadi

    I must admit that’s strange error. Before going farther, can you confirm your cli versions (wp --info) and the status of APCu Manager (wp apcu status)?

    Thanks a lot

    Thread Starter threadi

    (@threadi)

    Hi,

    I have since investigated the problem further and have been able to narrow down the cause.

    Back to the background:
    I am importing an XML file using the WordPress Importer plugin controlled by a WP CLI command. Since the XML file would otherwise be gigantic, when we create it in an external CRM we omit many of the otherwise uniform details about the products that are being imported. We then add this uniform information before and during the import. My individual plugin provides the WP CLI command for this purpose, integrates the files of the WordPress Importer plugin for the import when it is called and sets a marker that the import is now running. This marker is saved as a transient:

    set_transient( 'product_import_running', true );

    The import then starts:

    $import_obj = new WP_Import();
    $import_obj->import( $xml_file );

    We then use the “wp_import_posts” hook to add the missing information to the posts from the XML. This also checks whether it is our import by loading and checking the transient marker:

    // bail if our product import is not running.
    if ( false === get_transient( 'product_import_running' ) ) {
    return $posts;
    }

    This also works without any problems without APCu Manager and its object cache. As soon as APCu Manager AND its object cache are activated:

    get_transient( 'product_import_running' )

    always returns false. This means that the filter then returns the original post array, which means that the information about the post types is missing, which explains the error message in the first post.

    In summary: the problem is that APCu Manager apparently cannot handle transients on the WP CLI when the object cache is activated.

    So that you can understand this, I have designed a small plugin that clearly recreates the problem on a small scale. You can find it here: https://github.com/threadi/apcu-test – the testing procedure is described there.

    The solution for my project will now be to switch from transient to a file flag to mark the ongoing import. However, an evaluation of my findings would still be interesting so that this does not happen to me or others in similar situations.

    Then the requested information:

    OS:     Linux 5.10.0-33-amd64 #1 SMP Debian 5.10.226-1 (2024-10-03) x86_64
    Shell: /bin/false
    PHP binary: /usr/bin/php8.2
    PHP version: 8.2.27
    php.ini used: /etc/php/8.2/cli/php.ini
    MySQL binary: /usr/bin/mysql
    MySQL version: mysql Ver 15.1 Distrib 10.5.26-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
    SQL modes:
    WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir: phar://wp-cli.phar/vendor
    WP_CLI phar path: /var/www/clients/client0/web54/web/wp-content/plugins/apcu-test
    WP-CLI packages dir:
    WP-CLI cache dir: /var/www/clients/client0/web54/.wp-cli/cache
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 2.11.0
    APCu Manager 4.1.0 is running.
    APCu is not activated for command-line.
    WordPress object caching: enabled.
    Garbage collector: disabled.
    Analytics: enabled.
    Metrics collation: disabled.
    Logging support: no.
    Plugin Author Pierre Lannoy

    (@pierrelannoy)

    Wow, what a bug report <3

    Just to be sure it’s a bug, could you try to activate APCu for command line?

    Thread Starter threadi

    (@threadi)

    Fascinating. Then it works. The transients are then saved and also used.

    Plugin Author Pierre Lannoy

    (@pierrelannoy)

    ??

    Glad to know it works now… Have a nice (object) caching journey!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.