Skip to content

Commit

Permalink
CS fixer and rector
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Mar 28, 2021
1 parent f4544ca commit a34a948
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 77 deletions.
27 changes: 9 additions & 18 deletions Command/CustomDeduplicateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,17 @@ class CustomDeduplicateCommand extends DeduplicateCommand

/**
* DeduplicateCommand constructor.
*
* @param ContactDeduper $contactDeduper
* @param TranslatorInterface $translator
* @param NotificationModel $notificationModel
* @param UserModel $userModel
* @param IntegrationHelper $integrationHelper
* @param Logger $logger
*/
public function __construct(ContactDeduper $contactDeduper, TranslatorInterface $translator, NotificationModel $notificationModel, UserModel $userModel, IntegrationHelper $integrationHelper, Logger $logger)
{
parent::__construct($contactDeduper, $translator);

$this->notificationModel = $notificationModel;
$this->translator = $translator;
$this->contactDeduper = $contactDeduper;
$this->userModel = $userModel;
$this->translator = $translator;
$this->contactDeduper = $contactDeduper;
$this->userModel = $userModel;
$this->integrationHelper = $integrationHelper;
$this->logger = $logger;
$this->logger = $logger;
}

public function configure()
Expand Down Expand Up @@ -103,10 +96,6 @@ public function configure()
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$integration = $this->integrationHelper->getIntegrationObject('CustomDeduplicate');
Expand All @@ -117,19 +106,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
$this->sendDisabledNotification();
$this->logger->debug($message);

return 0;
}

$notify = (bool) $input->getOption('notify');
$key = __CLASS__;
$key = __CLASS__;
if (!$this->checkRunStatus($input, $output, $key)) {
if ($notify) {
$this->sendProgressNotification();
}

return 0;
}


if ($notify) {
$this->sendStartNotification();
}
Expand All @@ -151,6 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($notify) {
$this->sendEndNotification($count);
}

return 0;
}

Expand Down Expand Up @@ -188,7 +179,7 @@ private function sendProgressNotification()
private function sendEndNotification($count)
{
$this->notificationModel->addNotification(
$this->translator->trans('plugin.custom.deduplication.notification.result.count',[
$this->translator->trans('plugin.custom.deduplication.notification.result.count', [
'%count%' => $count,
]),

Expand Down
12 changes: 6 additions & 6 deletions Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'arguments' => [
'mautic.helper.integration',
'router',
'translator'
'translator',
],
],
'mautic.plugin.custom.deduplicate.contacts.subscriber' => [
Expand All @@ -37,23 +37,23 @@
'doctrine.orm.entity_manager',
'mautic.point.model.trigger',
'mautic.lead.repository.lead',
'mautic.plugin.custom.duplicate.fields'
'mautic.plugin.custom.duplicate.fields',
],
],
'mautic.plugin.custom.duplicate.fields' => [
'class' => \MauticPlugin\MauticCustomDeduplicateBundle\Deduplicate\Fields::class,
'arguments' => [
'mautic.helper.integration'
'mautic.helper.integration',
],
],
'mautic.plugin.custom.duplicate.command.execute' => [
'class' => \MauticPlugin\MauticCustomDeduplicateBundle\Deduplicate\CommandExecution::class,
'arguments' => [
'mautic.helper.core_parameters'
'mautic.helper.core_parameters',
],
],
],
'command'=>[
'command'=> [
'mautic.plugin.custom.deduplicate.command' => [
'class' => \MauticPlugin\MauticCustomDeduplicateBundle\Command\CustomDeduplicateCommand::class,
'arguments' => [
Expand All @@ -62,7 +62,7 @@
'mautic.core.model.notification',
'mautic.user.model.user',
'mautic.helper.integration',
'monolog.logger.mautic'
'monolog.logger.mautic',
],
'tag' => 'console.command',
],
Expand Down
6 changes: 2 additions & 4 deletions Controller/CustomDeduplicateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@

class CustomDeduplicateController extends CommonController
{

public function runAction()
{

$flashes = [];
$routeContext = 'contact';
$routeContext = 'contact';
$contentTemplate = 'MauticLeadBundle:Lead:index';
$activeLink = '#mautic_contact_index';
$mauticContent = 'lead';
$returnUrl = $this->generateUrl(
'mautic_'.$routeContext.'_index'
);
$this->get('mautic.plugin.custom.duplicate.command.execute')->execute();
$flashes[] = [
$flashes[] = [
'type' => 'notice',
'msg' => $this->translator->trans('plugin.custom.deduplication.command'),
];
Expand Down
8 changes: 4 additions & 4 deletions Deduplicate/CommandExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function getDefaultConsolePath()
}

/**
* Execute command line in background
* Execute command line in background.
*/
public function execute()
{
$cmd = 'php '.$this->getDefaultConsolePath().' mautic:contacts:deduplicate:custom --notify --env='.MAUTIC_ENV;

if (substr(php_uname(), 0, 7) == "Windows") {
pclose(popen("start /B ".$cmd, "r"));
if ('Windows' == substr(php_uname(), 0, 7)) {
pclose(popen('start /B '.$cmd, 'r'));
} else {
exec($cmd." > /dev/null &");
exec($cmd.' > /dev/null &');
}
}
}
31 changes: 5 additions & 26 deletions Deduplicate/CustomDuplications.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,22 @@ class CustomDuplications
*/
private $entityManager;

/**
* @var TriggerModel
*/
private $triggerModel;

/**
* @var LeadRepository
*/
private $leadRepository;

/**
* @var Fields
*/
private $fields;

/**
* CustomDuplications constructor.
*
* @param EntityManager $entityManager
* @param TriggerModel $triggerModel
* @param LeadRepository $leadRepository
* @param Fields $fields
*/
public function __construct(
EntityManager $entityManager,
TriggerModel $triggerModel,
LeadRepository $leadRepository,
Fields $fields
) {

$this->entityManager = $entityManager;
$this->triggerModel = $triggerModel;
$this->leadRepository = $leadRepository;
$this->fields = $fields;
$this->fields = $fields;
}

/**
Expand All @@ -72,7 +54,6 @@ public function customCheckForDuplicateContacts($fields)
return $this->getContactsByUniqueFields($uniqueData);
}
}

}

/**
Expand Down Expand Up @@ -134,26 +115,24 @@ private function getContactsByUniqueFields($uniqueFieldsWithData, $leadId = null
->setParameter('ids', array_keys($leads))
->orderBy('l.dateAdded', 'DESC')
->addOrderBy('l.id', 'DESC');
$entities = $q->getQuery()
->getResult();

return $entities;
return $q->getQuery()
->getResult();
}

/**
* @param array $queryFields
*
* @return array
*/
private function getCustomUniqueData(array $queryFields)
{
$uniqueLeadFields = $this->fields->getCustomUniqueFields();
$uniqueLeadFields = $this->fields->getCustomUniqueFields();
$uniqueLeadFieldData = [];
foreach ($queryFields as $k => $v) {
if (in_array($k, $uniqueLeadFields)) {
$uniqueLeadFieldData[$k] = $v;
}
}

return $uniqueLeadFieldData;
}
}
15 changes: 7 additions & 8 deletions Deduplicate/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class Fields
private $settings;

public function __construct(IntegrationHelper $integrationHelper)
{
$this->integrationHelper = $integrationHelper;
$integration = $this->integrationHelper->getIntegrationObject('CustomDeduplicate');
if ($integration && $integration->getIntegrationSettings()->getIsPublished()) {
$this->settings = $integration->mergeConfigToFeatureSettings();
}
}
{
$this->integrationHelper = $integrationHelper;
$integration = $this->integrationHelper->getIntegrationObject('CustomDeduplicate');
if ($integration && $integration->getIntegrationSettings()->getIsPublished()) {
$this->settings = $integration->mergeConfigToFeatureSettings();
}
}

/**
* @return array
Expand All @@ -46,7 +46,6 @@ public function getFieldsToSkip()
return isset($this->settings['skipFields']) ? $this->settings['skipFields'] : [];
}


/**
* @return array
*/
Expand Down
4 changes: 0 additions & 4 deletions EventListener/ButtonSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class ButtonSubscriber implements EventSubscriberInterface
*/
protected $integrationHelper;

private $event;

private $objectId;

/**
* @var RouterInterface
*/
Expand Down
5 changes: 0 additions & 5 deletions EventListener/CheckDeduplicateContactsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@

class CheckDeduplicateContactsListener implements EventSubscriberInterface
{

/**
* @var CustomDuplications
*/
private $customDuplications;

/**
* CheckDeduplicateContactsListener constructor.
*
* @param CustomDuplications $customDuplications
*/
public function __construct(CustomDuplications $customDuplications)
{

$this->customDuplications = $customDuplications;
}

Expand All @@ -52,5 +48,4 @@ public function checkForDuplicateContacts(DuplicateContactsEvent $event)
$duplications = $this->customDuplications->customCheckForDuplicateContacts($event->getFields());
$event->setDuplicates($duplications);
}

}
3 changes: 1 addition & 2 deletions Integration/CustomDeduplicateIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getIcon()
*/
public function appendToForm(&$builder, $data, $formArea)
{
if ($formArea == 'features') {
if ('features' == $formArea) {
$builder->add(
'uniqueFields',
LeadFieldsType::class,
Expand Down Expand Up @@ -72,5 +72,4 @@ public function appendToForm(&$builder, $data, $formArea)
);
}
}

}

0 comments on commit a34a948

Please sign in to comment.