Skip to content
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

Import issue with Feedme. Element is null #428

Closed
maximilian-schwarz opened this issue Oct 29, 2023 · 14 comments
Closed

Import issue with Feedme. Element is null #428

maximilian-schwarz opened this issue Oct 29, 2023 · 14 comments
Labels
bug Something isn't working

Comments

@maximilian-schwarz
Copy link

The issue still exist: issue-365

This only happens when 'runQueueAutomatically' => false, and the queue is offset to a separate worker.

Fix for _registerFeedMeElements function:

use craft\feedme\services\Elements as FeedMeElements;
use craft\feedme\events\RegisterFeedMeElementsEvent;

private function _registerFeedMeElements(): void
{
    if (class_exists(FeedMeElements::class)) {
        Event::on(FeedMeElements::class, FeedMeElements::EVENT_REGISTER_FEED_ME_ELEMENTS, function(RegisterFeedMeElementsEvent $event) {
            $event->elements[] = CampaignFeedMeElement::class;
            $event->elements[] = ContactFeedMeElement::class;
            $event->elements[] = MailingListFeedMeElement::class;
        });
    }
}

This solution is working perfectly.

Craft Version: 4.5.5
Feed me: 5.2.0
Campaign: 2.9.2

@maximilian-schwarz maximilian-schwarz added the bug Something isn't working label Oct 29, 2023
@bencroker
Copy link
Collaborator

bencroker commented Oct 29, 2023

Thanks for the attempt, however, that will break the plugin in other scenarios.

I realise this issue references another issue, but since it has been resolved and closed, can you please explain the exact issue you are having and under what specific circumstance?

@maximilian-schwarz
Copy link
Author

Okay.

  1. Create a new Feed with Feed Me and choose as Element type contacts.

  2. Set runQueueAutomatically => false

  3. Click run feed.

  4. And listen to the queue with ./craft queue/listen to start the job.

In the log you will see the issue element is properly null.

@bencroker
Copy link
Collaborator

In the log you will see the issue element is properly null.

Please show the relevant log.

@maximilian-schwarz
Copy link
Author

@bencroker:
Import newsletter contacts: Cannot assign null to property craft\feedme\services\Process::$_service of type craft\feedme\base\ElementInterface - Process.php: 87

@bencroker
Copy link
Collaborator

bencroker commented Oct 30, 2023

I cannot replicate this locally. Can you please double check that you’re running the latest version of Blitz Campaign? It might be worthwhile removing and requiring the plugin via composer again, to ensure the files are all updated.

@maximilian-schwarz
Copy link
Author

I don't use Blitz.

If i setup a test feed like this:
Bildschirmfoto 2023-10-30 um 21 44 02

URL: https://jsonplaceholder.typicode.com/users

And run Process feed and disable runQueueAutomatically => false and set the system environment to "staging" or "production". Execute ./craft queue/listen i still got the following error:

error | test: Cannot assign null to property craft\feedme\services\Process::$_service of type craft\feedme\base\ElementInterface - Process.php: 87

Also removed the vendor folder and re run "composer install".

@bencroker
Copy link
Collaborator

Sorry, I meant to write “Campaign”, of course.

I still cannot replicate the issue, following your instructions. Is this happening in a local development environment and in what kind of setup?

@maximilian-schwarz
Copy link
Author

This is happen in local and server, but only if i switch the environment to staging or production.

I use ddev for local environment.

config/general.php

<?php
/**
 * General Configuration
 *
 * All of your system's general configuration settings go in here. You can see a
 * list of the available settings in vendor/craftcms/cms/src/config/GeneralConfig.php.
 *
 * @see \craft\config\GeneralConfig
 */

return [
    '*' => [
        'aliases' => [
            '@web' => getenv('PRIMARY_SITE_URL'),
        ],
        'allowAdminChanges' => false,
        'allowedFileExtensions' => ['jpg', 'png', 'jpeg', 'gif', 'svg', 'mp4', 'pdf', 'zip', 'csv'],
        'allowUpdates' => false,
        'cacheDuration' => false,
        'defaultTokenDuration' => 'P2W',
        'defaultSearchTermOptions' => [
            'subLeft' => true,
            'subRight' => true,
        ],
        'devMode' => true,
        'disallowRobots' => true,
        'errorTemplatePrefix' => '_pages/errors/',
        'generateTransformsBeforePageLoad' => true,
        'limitAutoSlugsToAscii' => true,
        'maxRevisions' => 5,
        'omitScriptNameInUrls' => true,
        'runQueueAutomatically' => false,
        'securityKey' => getenv('SECURITY_KEY'),
    ],

    'production'  => [
        'devMode' => false,
        'disallowRobots' => false,
        'disabledPlugins' => [
            'blitz-recommendations',
            'cp-field-inspect',
            'dumper',
            'elements-panel',
            'templatecomments',
            'twig-profiler',
        ],
    ],

    'staging'  => [
        'testToEmailAddress' => getenv('TEST_EMAIL_ADDRESS') ?: null,
    ],

    'dev'  => [
        'allowAdminChanges' => true,
        'allowUpdates' => true,
        'enableTemplateCaching' => false,
        'testToEmailAddress' => getenv('TEST_EMAIL_ADDRESS') ?: null,
        'disabledPlugins' => [
        // 'seomatic', // for better performance measuring
        ],
        'runQueueAutomatically' => true,
    ],
];

@bencroker
Copy link
Collaborator

Can you please send me a ddev setup via a GitHub repo that I can use to replicate the issue?

@maximilian-schwarz
Copy link
Author

maximilian-schwarz commented Nov 6, 2023

Hi @bencroker,

sorry for the late response. I can't give you access to the repository because it's a customer project and we got problems with the GDPR.

Is it conceivable that the order of the plugins is not correct and this is causing the error? Unfortunately, I don't know exactly which craft determines the order of the plugins.

Here is the ddev config:

name: projectname
type: php
docroot: web
php_version: "8.1"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
database:
  type: mariadb
  version: "10.3"
nfs_mount_enabled: false
performance_mode: mutagen
use_dns_when_possible: true
composer_version: "2.2"
nodejs_version: "18"
web_extra_exposed_ports:
  - name: craft-vite
    container_port: 3000
    http_port: 3001
    https_port: 3000

@bencroker
Copy link
Collaborator

I can't give you access to the repository because it's a customer project and we got problems with the GDPR.

I’m not asking for access to your client’s project, just to a ddev site on which you can demonstrate the issue, so I can troubleshoot it, since I have not been able to replicate it.

Is it conceivable that the order of the plugins is not correct and this is causing the error?

Plugins are loaded in alphabetical order, so that shouldn’t be an issue.

@maximilian-schwarz
Copy link
Author

@bencroker okay thanks. I send you an email to support@putyourlightson.com with the ddev project setup. Here you can reproduce the issue.

@bencroker
Copy link
Collaborator

bencroker commented Nov 6, 2023

Thanks for the files. It turns out that your original proposed solution is really the only the way of fixing this issue, so I’ve implemented it in 3497dd9 for the next release, and hope that this doesn’t inadvertently break imports in other scenarios.

You can test this by running composer require "putyourlightson/craft-campaign:dev-develop as 2.9.4".

@bencroker
Copy link
Collaborator

Released in 2.9.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants