Issues (3627)

CoreBundle/Update/Step/FinalizeUpdateStep.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2020 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        https://www.mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CoreBundle\Update\Step;
13
14
use Mautic\CoreBundle\Helper\AppVersion;
15
use Mautic\CoreBundle\Helper\PathsHelper;
16
use Symfony\Component\Console\Helper\ProgressBar;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\HttpFoundation\Session\Session;
20
use Symfony\Component\Translation\TranslatorInterface;
21
22
final class FinalizeUpdateStep implements StepInterface
23
{
24
    /**
25
     * @var TranslatorInterface
26
     */
27
    private $translator;
28
29
    /**
30
     * @var PathsHelper
31
     */
32
    private $pathsHelper;
33
34
    /**
35
     * @var Session
36
     */
37
    private $session;
38
39
    /**
40
     * @var AppVersion
41
     */
42
    private $appVersion;
43
44
    public function __construct(TranslatorInterface $translator, PathsHelper $pathsHelper, Session $session, AppVersion $appVersion)
45
    {
46
        $this->translator  = $translator;
47
        $this->pathsHelper = $pathsHelper;
48
        $this->session     = $session;
49
        $this->appVersion  = $appVersion;
50
    }
51
52
    public function getOrder(): int
53
    {
54
        return 50;
55
    }
56
57
    public function shouldExecuteInFinalStage(): bool
58
    {
59
        return true;
60
    }
61
62
    public function execute(ProgressBar $progressBar, InputInterface $input, OutputInterface $output): void
63
    {
64
        $progressBar->setMessage($this->translator->trans('mautic.core.update.step.wrapping_up'));
65
        $progressBar->advance();
66
67
        // Clear the cached update data and the download package now that we've updated
68
        @unlink($this->pathsHelper->getRootPath().'/upgrade.php');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

68
        /** @scrutinizer ignore-unhandled */ @unlink($this->pathsHelper->getRootPath().'/upgrade.php');

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
69
        @unlink($this->pathsHelper->getCachePath().'/lastUpdateCheck.txt');
70
71
        // Update successful
72
        $progressBar->setMessage(
73
            $this->translator->trans('mautic.core.update.update_successful', ['%version%' => $this->appVersion->getVersion()])."\n\n"
74
        );
75
        $progressBar->finish();
76
77
        // Check for a post install message from migrations
78
        if ($postMessage = $this->session->get('post_upgrade_message')) {
79
            $postMessage = strip_tags($postMessage);
80
            $this->session->remove('post_upgrade_message');
81
            $output->writeln("\n\n<info>$postMessage</info>");
82
        }
83
    }
84
}
85