Issues (3627)

CampaignBundle/Controller/AjaxController.php (1 issue)

Severity
1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CampaignBundle\Controller;
13
14
use Mautic\CampaignBundle\Entity\LeadEventLog;
15
use Mautic\CampaignBundle\Model\EventLogModel;
16
use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController;
17
use Mautic\CoreBundle\Helper\InputHelper;
18
use Symfony\Component\HttpFoundation\Request;
19
20
/**
21
 * Class AjaxController.
22
 */
23
class AjaxController extends CommonAjaxController
24
{
25
    /**
26
     * @return \Symfony\Component\HttpFoundation\JsonResponse
27
     */
28
    protected function updateConnectionsAction(Request $request)
29
    {
30
        $session        = $this->get('session');
31
        $campaignId     = InputHelper::clean($request->query->get('campaignId'));
32
        $canvasSettings = $request->request->get('canvasSettings', [], true);
0 ignored issues
show
The call to Symfony\Component\HttpFo...ion\ParameterBag::get() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        /** @scrutinizer ignore-call */ 
33
        $canvasSettings = $request->request->get('canvasSettings', [], true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
33
        if (empty($campaignId)) {
34
            $dataArray = ['success' => 0];
35
        } else {
36
            $session->set('mautic.campaign.'.$campaignId.'.events.canvassettings', $canvasSettings);
37
38
            $dataArray = ['success' => 1];
39
        }
40
41
        return $this->sendJsonResponse($dataArray);
42
    }
43
44
    protected function updateScheduledCampaignEventAction(Request $request)
45
    {
46
        $eventId      = (int) $request->request->get('eventId');
47
        $contactId    = (int) $request->request->get('contactId');
48
        $newDate      = InputHelper::clean($request->request->get('date'));
49
        $originalDate = InputHelper::clean($request->request->get('originalDate'));
50
51
        $dataArray = ['success' => 0, 'date' => $originalDate];
52
53
        if (!empty($eventId) && !empty($contactId) && !empty($newDate)) {
54
            if ($log = $this->getContactEventLog($eventId, $contactId)) {
55
                $newDate = new \DateTime($newDate);
56
57
                if ($newDate >= new \DateTime()) {
58
                    $log->setTriggerDate($newDate);
59
60
                    /** @var EventLogModel $logModel */
61
                    $logModel = $this->getModel('campaign.event_log');
62
                    $logModel->saveEntity($log);
63
64
                    $dataArray = [
65
                        'success' => 1,
66
                        'date'    => $newDate->format('Y-m-d H:i:s'),
67
                    ];
68
                }
69
            }
70
        }
71
72
        // Format the date to match the view
73
        $dataArray['formattedDate'] = $this->get('mautic.helper.template.date')->toFull($dataArray['date']);
74
75
        return $this->sendJsonResponse($dataArray);
76
    }
77
78
    /**
79
     * @return \Symfony\Component\HttpFoundation\JsonResponse
80
     */
81
    protected function cancelScheduledCampaignEventAction(Request $request)
82
    {
83
        $dataArray = ['success' => 0];
84
85
        $eventId   = (int) $request->request->get('eventId');
86
        $contactId = (int) $request->request->get('contactId');
87
        if (!empty($eventId) && !empty($contactId)) {
88
            if ($log = $this->getContactEventLog($eventId, $contactId)) {
89
                $log->setIsScheduled(false);
90
91
                /** @var EventLogModel $logModel */
92
                $logModel = $this->getModel('campaign.event_log');
93
                $logModel->saveEntity($log);
94
95
                $dataArray = ['success' => 1];
96
            }
97
        }
98
99
        return $this->sendJsonResponse($dataArray);
100
    }
101
102
    /**
103
     * @param $eventId
104
     * @param $contactId
105
     *
106
     * @return LeadEventLog|null
107
     */
108
    protected function getContactEventLog($eventId, $contactId)
109
    {
110
        $contact = $this->getModel('lead')->getEntity($contactId);
111
        if ($contact) {
112
            if ($this->get('mautic.security')->hasEntityAccess('lead:leads:editown', 'lead:leads:editother', $contact->getPermissionUser())) {
113
                /** @var EventLogModel $logModel */
114
                $logModel = $this->getModel('campaign.event_log');
115
116
                /** @var LeadEventLog $log */
117
                $log = $logModel->getRepository()
118
                                ->findOneBy(
119
                                    [
120
                                        'lead'  => $contactId,
121
                                        'event' => $eventId,
122
                                    ]
123
                                );
124
125
                if ($log && ($log->getTriggerDate() > new \DateTime())) {
126
                    return $log;
127
                }
128
            }
129
        }
130
131
        return null;
132
    }
133
}
134