Issues (3627)

ReportBundle/Scheduler/Model/MessageSchedule.php (1 issue)

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\ReportBundle\Scheduler\Model;
13
14
use Mautic\CoreBundle\Helper\CoreParametersHelper;
15
use Mautic\CoreBundle\Helper\FileProperties;
16
use Mautic\ReportBundle\Entity\Report;
17
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
18
use Symfony\Component\Routing\Router;
19
use Symfony\Component\Translation\TranslatorInterface;
20
21
class MessageSchedule
22
{
23
    /**
24
     * @var TranslatorInterface
25
     */
26
    private $translator;
27
28
    /**
29
     * @var FileProperties
30
     */
31
    private $fileProperties;
32
33
    /**
34
     * @var CoreParametersHelper
35
     */
36
    private $coreParametersHelper;
37
38
    /**
39
     * @var Router
40
     */
41
    private $router;
42
43
    public function __construct(
44
        TranslatorInterface $translator,
45
        FileProperties $fileProperties,
46
        CoreParametersHelper $coreParametersHelper,
47
        Router $router
48
    ) {
49
        $this->translator           = $translator;
50
        $this->fileProperties       = $fileProperties;
51
        $this->coreParametersHelper = $coreParametersHelper;
52
        $this->router               = $router;
53
    }
54
55
    /**
56
     * @deprecated 2.15.2 to be removed in 3.0. Use getMessageForAttachedFile or getMessageForLinkedFile
57
     *
58
     * @param string $filePath
59
     *
60
     * @return string
61
     */
62
    public function getMessage(Report $report, $filePath)
63
    {
64
        $link = $this->router->generate('mautic_report_view', ['objectId' => $report->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
65
66
        if ($this->fileCouldBeSend($filePath)) {
0 ignored issues
show
Deprecated Code introduced by
The function Mautic\ReportBundle\Sche...dule::fileCouldBeSend() has been deprecated: 2.16.0 use \Mautic\ReportBundle\Scheduler\Model\FileHandler::fileCanBeAttached instead. To be removed in 3.0.0. ( Ignorable by Annotation )

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

66
        if (/** @scrutinizer ignore-deprecated */ $this->fileCouldBeSend($filePath)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
67
            $date = new \DateTime();
68
69
            return $this->translator->trans(
70
                'mautic.report.schedule.email.message',
71
                ['%report_name%' => $report->getName(), '%date%' => $date->format('Y-m-d'), '%link%' => $link]
72
            );
73
        }
74
75
        return $this->translator->trans(
76
            'mautic.report.schedule.email.message_file_not_attached',
77
            ['%report_name%' => $report->getName(), '%link%' => $link]
78
        );
79
    }
80
81
    public function getMessageForAttachedFile(Report $report): string
82
    {
83
        $link = $this->router->generate('mautic_report_view', ['objectId' => $report->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
84
        $date = new \DateTime();
85
86
        return $this->translator->trans(
87
            'mautic.report.schedule.email.message',
88
            ['%report_name%' => $report->getName(), '%date%' => $date->format('Y-m-d'), '%link%' => $link]
89
        );
90
    }
91
92
    public function getMessageForLinkedFile(Report $report): string
93
    {
94
        $link = $this->router->generate('mautic_report_download', ['reportId' => $report->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
95
96
        return $this->translator->trans(
97
            'mautic.report.schedule.email.message_file_linked',
98
            ['%report_name%' => $report->getName(), '%link%' => $link]
99
        );
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getSubject(Report $report)
106
    {
107
        $date = new \DateTime();
108
109
        return $this->translator->trans(
110
            'mautic.report.schedule.email.subject',
111
            ['%report_name%' => $report->getName(), '%date%' => $date->format('Y-m-d')]
112
        );
113
    }
114
115
    /**
116
     * @deprecated 2.16.0 use \Mautic\ReportBundle\Scheduler\Model\FileHandler::fileCanBeAttached instead. To be removed in 3.0.0.
117
     *
118
     * @param string $filePath
119
     *
120
     * @return bool
121
     *
122
     * @throws \Mautic\CoreBundle\Exception\FileInvalidException
123
     */
124
    public function fileCouldBeSend($filePath)
125
    {
126
        $filesize    = $this->fileProperties->getFileSize($filePath);
127
        $maxFileSize = $this->coreParametersHelper->get('report_export_max_filesize_in_bytes');
128
129
        return $filesize <= $maxFileSize;
130
    }
131
}
132