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

Make package ready for multiple sites and multiple Mautic instances #47

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
.vscode
3 changes: 2 additions & 1 deletion Classes/Api/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Emails extends MauticEmails
*/
public function sendExample(int $id, array $recipients)
{
return $this->makeRequest($this->endpoint . '/' . $id . '/example', ['recipients' => $recipients], 'POST');
$uri = sprintf('%s/%s/example', $this->endpoint, $id);
return $this->makeRequest($uri, ['recipients' => $recipients], 'POST');
}
}
21 changes: 6 additions & 15 deletions Classes/Command/MauticCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@
use Neos\Flow\Cli\CommandController;
use function \Neos\Flow\var_dump;

/**
*
* @Flow\Scope("singleton")
*/
// TODO Remove var_dump and replace with proper logging
#[Flow\Scope('singleton')]
class MauticCommandController extends CommandController
{
#[Flow\Inject]
protected ApiService $apiService;

/**
* @Flow\Inject
* @var ApiService
*/
protected $apiService;

/**
* @Flow\Inject
* @var MauticService
*/
protected $mauticService;
#[Flow\Inject]
protected MauticService $mauticService;

public function getCommand(string $emailIdentifier)
{
Expand Down
122 changes: 45 additions & 77 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
use Neos\Neos\Service\UserService;
use Neos\Neos\TypeConverter\NodeConverter;

/**
* @Flow\Scope("singleton")
*/
#[Flow\Scope('singleton')]
class BackendController extends AbstractModuleController
{
/**
Expand All @@ -40,76 +38,40 @@ class BackendController extends AbstractModuleController
*/
protected $defaultViewObjectName = FusionView::class;

/**
* @Flow\Inject
* @var Context
*/
protected $securityContext;
#[Flow\Inject]
protected Context $securityContext;

/**
* @Flow\Inject
* @var NodeService
*/
protected $nodeService;
#[Flow\Inject]
protected NodeService $nodeService;

/**
* @Flow\Inject
* @var LinkingService
*/
protected $linkingService;
#[Flow\Inject]
protected LinkingService $linkingService;

/**
* @Flow\Inject
* @var MauticService
*/
protected $mauticService;
#[Flow\Inject]
protected MauticService $mauticService;

/**
* @Flow\Inject
* @var TaskService
*/
protected $taskService;
#[Flow\Inject]
protected TaskService $taskService;

/**
* @Flow\Inject
* @var TestEmailService
*/
protected $testEmailService;
#[Flow\Inject]
protected TestEmailService $testEmailService;

/**
* @Flow\Inject
* @var ApiService
*/
protected $apiService;
#[Flow\Inject]
protected ApiService $apiService;

/**
* @Flow\Inject
* @var FlashMessageService
*/
protected $flashMessageService;
#[Flow\Inject]
protected FlashMessageService $flashMessageService;

/**
* @Flow\Inject
* @var TranslationHelper
*/
protected $translationHelper;
#[Flow\Inject]
protected TranslationHelper $translationHelper;

/**
* @Flow\Inject
* @var UserService
*/
protected $userService;
#[Flow\Inject]
protected UserService $userService;

/**
* @var array
* @Flow\InjectConfiguration(path="routeArgument", package="Garagist.Mautic")
*/
#[Flow\InjectConfiguration('routeArgument', 'Garagist.Mautic')]
protected $routeArgument;

/**
* @var string
* @Flow\InjectConfiguration(path="mail.trackingPixel", package="Garagist.Mautic")
*/
#[Flow\InjectConfiguration('mail.trackingPixel', 'Garagist.Mautic')]
protected $trackingPixel;

/**
Expand All @@ -127,25 +89,10 @@ class BackendController extends AbstractModuleController
*/
protected function initialize(): void
{
// use this constant only if available (became available with patch level releases in Neos 4.0 and up)
if (defined(NodeConverter::class . '::INVISIBLE_CONTENT_SHOWN')) {
$this->arguments->getArgument('node')->getPropertyMappingConfiguration()->setTypeConverterOption(NodeConverter::class, NodeConverter::INVISIBLE_CONTENT_SHOWN, true);
}
$this->arguments->getArgument('node')->getPropertyMappingConfiguration()->setTypeConverterOption(NodeConverter::class, NodeConverter::INVISIBLE_CONTENT_SHOWN, true);
}

protected function localSort(array $array, ?string $key = null): array
{
$collator = new Collator($this->userService->getInterfaceLanguage());

uasort($array, function ($a, $b) use ($collator, $key) {
if (isset($key)) {
return $collator->compare($a[$key], $b[$key]);
}
return $collator->compare($a, $b);
});

return $array;
}

/**
* Render the overview of emails
Expand Down Expand Up @@ -729,4 +676,25 @@ private function getCategories(NodeInterface $node): ?array
'nodes' => $parents,
];
}

/**
* Sort an array by the current language
*
* @param array $array
* @param string|null $key
* @return array
*/
private function localSort(array $array, ?string $key = null): array
{
$collator = new Collator($this->userService->getInterfaceLanguage());

uasort($array, function ($a, $b) use ($collator, $key) {
if (isset($key)) {
return $collator->compare($a[$key], $b[$key]);
}
return $collator->compare($a, $b);
});

return $array;
}
}
7 changes: 2 additions & 5 deletions Classes/DataSource/FormsDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ class FormsDataSource extends AbstractDataSource
*/
protected static $identifier = 'garagist-mautic-forms';

/**
* @Flow\Inject
* @var ApiService
*/
protected $apiService;
#[Flow\Inject]
protected ApiService $apiService;

/**
* Get data
Expand Down
5 changes: 1 addition & 4 deletions Classes/Domain/Model/MauticEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use Doctrine\ORM\Mapping as ORM;
use DateTime;

/**
*
* @Flow\Entity
*/
#[Flow\Entity]
class MauticEmail
{

Expand Down
4 changes: 1 addition & 3 deletions Classes/Domain/Repository/MauticEmailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\Doctrine\Repository;

/**
* @Flow\Scope("singleton")
*/
#[Flow\Scope('singleton')]
class MauticEmailRepository extends Repository
{
}
30 changes: 30 additions & 0 deletions Classes/EelHelper/MauticHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Garagist\Mautic\EelHelper;

use Garagist\Mautic\Service\SettingsService;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Flow\Annotations as Flow;

class MauticHelper implements ProtectedContextAwareInterface
{

#[Flow\Inject]
protected SettingsService $settingsService;

public function settings(string $settingPath, ?string $siteName = null, $rootPackage = 'Garagist.Mautic'): string
{
return $this->settingsService->path($settingPath, $siteName, $rootPackage);
}

/**
* All methods are considered safe
*
* @param string $methodName The name of the method
* @return bool
*/
public function allowsCallOfMethod($methodName)
{
return true;
}
}
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use Doctrine\ORM\Mapping as ORM;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
class MauticEmailCreate implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailDelete implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailPublish.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailPublish implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailSend implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailSent implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailSync implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailTaskFinished.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailTaskFinished implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailUnpublish.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Neos\EventSourcing\Event\DomainEventInterface;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
final class MauticEmailUnpublish implements DomainEventInterface
{
/**
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/MauticEmailUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use Doctrine\ORM\Mapping as ORM;
use Neos\Flow\Annotations as Flow;

/**
* @Flow\Proxy(false)
*/
#[Flow\Proxy(false)]
class MauticEmailUpdate implements DomainEventInterface
{
/**
Expand Down
Loading