1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Saito - The Threaded Web Forum |
6
|
|
|
* |
7
|
|
|
* @copyright Copyright (c) the Saito Project Developers |
8
|
|
|
* @link https://github.com/Schlaefer/Saito |
9
|
|
|
* @license http://opensource.org/licenses/MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Installer\Controller; |
13
|
|
|
|
14
|
|
|
use Cake\Cache\Cache; |
15
|
|
|
use Cake\Controller\Controller; |
16
|
|
|
use Cake\Core\Configure; |
17
|
|
|
use Cake\Datasource\ConnectionManager; |
18
|
|
|
use Cake\I18n\I18n; |
19
|
|
|
use Cake\Log\LogTrait; |
20
|
|
|
use Cake\ORM\Table; |
21
|
|
|
use Migrations\Migrations; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Installer App Controller |
25
|
|
|
* |
26
|
|
|
* @property \App\Model\Table\SettingsTable $Settings |
27
|
|
|
*/ |
28
|
|
|
class AppController extends Controller |
29
|
|
|
{ |
30
|
|
|
use LogTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \Migrations\Migrations |
34
|
|
|
*/ |
35
|
|
|
protected $migrations; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritDoc} |
39
|
|
|
*/ |
40
|
|
|
public function initialize(): void |
41
|
|
|
{ |
42
|
|
|
Cache::clear(); |
43
|
|
|
Cache::disable(); |
44
|
|
|
|
45
|
|
|
parent::initialize(); |
46
|
|
|
|
47
|
|
|
$this->loadModel('Settings'); |
48
|
|
|
$this->migrations = $this->initializeMigrations($this->Settings); |
49
|
|
|
|
50
|
|
|
$this->viewBuilder()->setHelpers( |
51
|
|
|
[ |
52
|
|
|
'Breadcrumbs' => ['className' => 'BootstrapUI.Breadcrumbs'], |
53
|
|
|
'Flash' => ['className' => 'BootstrapUI.Flash'], |
54
|
|
|
'Form' => ['className' => 'BootstrapUI.Form'], |
55
|
|
|
'Html' => ['className' => 'BootstrapUI.Html'], |
56
|
|
|
'Paginator' => ['className' => 'BootstrapUI.Paginator'], |
57
|
|
|
] + $this->viewBuilder()->getHelpers() |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$locale = Configure::read('Saito.language'); |
61
|
|
|
I18n::setLocale($locale); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Initialize migration property |
66
|
|
|
* |
67
|
|
|
* @param \Cake\ORM\Table $table a table to read the config from |
68
|
|
|
* @return \Migrations\Migrations |
69
|
|
|
*/ |
70
|
|
|
private function initializeMigrations(Table $table) |
71
|
|
|
{ |
72
|
|
|
$installerConfigName = 'installer'; |
73
|
|
|
// if: static configuration only allowed once, but done multiple times in test-cases |
74
|
|
|
if (ConnectionManager::getConfig($installerConfigName) === null) { |
75
|
|
|
$defaultConfigName = $table->getConnection()->configName(); |
76
|
|
|
$connectionConfig = ConnectionManager::getConfig($defaultConfigName); |
77
|
|
|
$connectionConfig['quoteIdentifiers'] = true; |
78
|
|
|
ConnectionManager::setConfig($installerConfigName, $connectionConfig); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return new Migrations(['connection' => $installerConfigName]); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|