![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/plugins/MauticSocialBundle/EventListener/ |
<?php namespace MauticPlugin\MauticSocialBundle\EventListener; use Mautic\CampaignBundle\CampaignEvents; use Mautic\CampaignBundle\Event\CampaignBuilderEvent; use Mautic\CampaignBundle\Event\CampaignExecutionEvent; use Mautic\PluginBundle\Helper\IntegrationHelper; use MauticPlugin\MauticSocialBundle\Form\Type\TweetSendType; use MauticPlugin\MauticSocialBundle\Helper\CampaignEventHelper; use MauticPlugin\MauticSocialBundle\SocialEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Contracts\Translation\TranslatorInterface; class CampaignSubscriber implements EventSubscriberInterface { public function __construct( private CampaignEventHelper $campaignEventHelper, private IntegrationHelper $integrationHelper, private TranslatorInterface $translator ) { } public static function getSubscribedEvents(): array { return [ CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0], SocialEvents::ON_CAMPAIGN_TRIGGER_ACTION => ['onCampaignAction', 0], ]; } public function onCampaignBuild(CampaignBuilderEvent $event): void { $integration = $this->integrationHelper->getIntegrationObject('Twitter'); if ($integration && $integration->getIntegrationSettings()->isPublished()) { $action = [ 'label' => 'mautic.social.twitter.tweet.event.open', 'description' => 'mautic.social.twitter.tweet.event.open_desc', 'eventName' => SocialEvents::ON_CAMPAIGN_TRIGGER_ACTION, 'formTypeOptions' => ['update_select' => 'campaignevent_properties_channelId'], 'formType' => TweetSendType::class, 'channel' => 'social.tweet', 'channelIdField' => 'channelId', ]; $event->addAction('twitter.tweet', $action); } } public function onCampaignAction(CampaignExecutionEvent $event) { $event->setChannel('social.twitter'); if ($response = $this->campaignEventHelper->sendTweetAction($event->getLead(), $event->getEvent())) { return $event->setResult($response); } return $event->setFailed( $this->translator->trans('mautic.social.twitter.error.handle_not_found') ); } }