Skip to content

Commit

Permalink
Fix Feed Me imports when running queue via console
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Nov 6, 2023
1 parent cabd214 commit 3497dd9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Campaign

## 2.9.4 - Unreleased

### Fixed

- Fixed a bug in which importing Campaign elements using the Feed Me plugin could throw errors when the queue job was run via the console ([#428](https://github.com/putyourlightson/craft-campaign/issues/428)).

## 2.9.3 - 2023-10-31

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "putyourlightson/craft-campaign",
"description": "Send and manage email campaigns, contacts and mailing lists.",
"version": "2.9.3",
"version": "2.9.4",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/campaign",
"license": "proprietary",
Expand Down
27 changes: 11 additions & 16 deletions src/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use craft\services\Sites;
use craft\services\UserPermissions;
use craft\services\Utilities;
use craft\web\Application;
use craft\web\Response;
use craft\web\twig\variables\CraftVariable;
use craft\web\UrlManager;
Expand Down Expand Up @@ -702,21 +701,17 @@ private function _registerTwigExtensions(): void
*/
private function _registerFeedMeElements(): void
{
// Ensure that the plugin is enabled and exists on application initialisation.
// https://github.com/putyourlightson/craft-campaign/issues/400
// https://github.com/putyourlightson/craft-campaign/issues/412
// TODO: replace with `Application::onInit()` in 5.0.0
Event::on(Application::class, Application::EVENT_INIT, function() {
if (Craft::$app->getPlugins()->getPlugin('feed-me') !== null) {
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;
}
);
}
});
// Only check that the class exists, disregarding application initialisation.
// https://github.com/putyourlightson/craft-campaign/issues/428
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;
}
);
}
}

/**
Expand Down

0 comments on commit 3497dd9

Please sign in to comment.