|
1
|
|
|
<?php |
|
2
|
|
|
/*************************************************************************************/ |
|
3
|
|
|
/* This file is part of the Thelia package. */ |
|
4
|
|
|
/* */ |
|
5
|
|
|
/* Copyright (c) OpenStudio */ |
|
6
|
|
|
/* email : [email protected] */ |
|
7
|
|
|
/* web : http://www.thelia.net */ |
|
8
|
|
|
/* */ |
|
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
|
10
|
|
|
/* file that was distributed with this source code. */ |
|
11
|
|
|
/*************************************************************************************/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Dealer\Controller; |
|
14
|
|
|
|
|
15
|
|
|
use Dealer\Dealer; |
|
16
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
use Thelia\Controller\Admin\BaseAdminController; |
|
19
|
|
|
use Thelia\Core\Security\AccessManager; |
|
20
|
|
|
use Thelia\Core\Security\Resource\AdminResources; |
|
21
|
|
|
use Thelia\Core\Thelia; |
|
22
|
|
|
use Thelia\Form\Exception\FormValidationException; |
|
23
|
|
|
use Thelia\Tools\URL; |
|
24
|
|
|
use Thelia\Tools\Version\Version; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class ConfigureController |
|
28
|
|
|
* @package DealerGoogleTimeZone\Controller |
|
29
|
|
|
*/ |
|
30
|
|
|
class ConfigureController extends BaseAdminController |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
public function configureAction() |
|
34
|
|
|
{ |
|
35
|
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'dealer', AccessManager::UPDATE)) { |
|
36
|
|
|
return $response; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$configurationForm = $this->createForm('dealer.configuration.form'); |
|
40
|
|
|
$message = null; |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
$form = $this->validateForm($configurationForm); |
|
44
|
|
|
|
|
45
|
|
|
// Get the form field values |
|
46
|
|
|
$data = $form->getData(); |
|
47
|
|
|
|
|
48
|
|
|
Dealer::setConfigValue('googlemapsapi_key',$data['googlemapsapi_key']); |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
// Redirect to the success URL, |
|
52
|
|
|
if ($this->getRequest()->get('save_mode') == 'stay') { |
|
53
|
|
|
// If we have to stay on the same page, redisplay the configuration page/ |
|
54
|
|
|
$url = '/admin/module/Dealer'; |
|
55
|
|
|
} else { |
|
56
|
|
|
// If we have to close the page, go back to the module back-office page. |
|
57
|
|
|
$url = '/admin/modules'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->generateRedirect(URL::getInstance()->absoluteUrl($url)); |
|
61
|
|
|
} catch (FormValidationException $ex) { |
|
|
|
|
|
|
62
|
|
|
$message = $this->createStandardFormValidationErrorMessage($ex); |
|
63
|
|
|
} catch (\Exception $ex) { |
|
64
|
|
|
$message = $ex->getMessage(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$this->setupFormErrorContext( |
|
68
|
|
|
$this->getTranslator()->trans("Dealer configuration", [], Dealer::MESSAGE_DOMAIN), |
|
69
|
|
|
$message, |
|
70
|
|
|
$configurationForm, |
|
71
|
|
|
$ex |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
// Before 2.2, the errored form is not stored in session |
|
75
|
|
|
if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { |
|
76
|
|
|
return $this->render('module-configure', [ 'module_code' => 'Dealer' ]); |
|
77
|
|
|
} else { |
|
78
|
|
|
return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Dealer')); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.