|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Saito - The Threaded Web Forum |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright (c) the Saito Project Developers |
|
9
|
|
|
* @link https://github.com/Schlaefer/Saito |
|
10
|
|
|
* @license http://opensource.org/licenses/MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Installer\Form; |
|
14
|
|
|
|
|
15
|
|
|
use Cake\Datasource\ConnectionManager; |
|
16
|
|
|
use Cake\Form\Form; |
|
17
|
|
|
use Cake\Form\Schema; |
|
18
|
|
|
use Cake\Validation\Validator; |
|
19
|
|
|
|
|
20
|
|
|
class UpdaterStartForm extends Form |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritDoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function _buildSchema(Schema $schema) |
|
26
|
|
|
{ |
|
27
|
|
|
return $schema |
|
28
|
|
|
->addField('dbname', ['type' => 'string']) |
|
29
|
|
|
->addField('dbpassword', ['type' => 'password']); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function _buildValidator(Validator $validator) |
|
36
|
|
|
{ |
|
37
|
|
|
$validator |
|
|
|
|
|
|
38
|
|
|
->requirePresence('dbname') |
|
39
|
|
|
->notEmpty('dbname') |
|
40
|
|
|
->add('dbname', 'custom', [ |
|
41
|
|
|
'rule' => [$this, 'validateDbName'], |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
$validator |
|
|
|
|
|
|
45
|
|
|
->requirePresence('dbpassword') |
|
46
|
|
|
->allowEmpty('dbpassword') |
|
47
|
|
|
->add('dbpassword', 'custom', [ |
|
48
|
|
|
'rule' => [$this, 'validateDbPassword'], |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
|
|
return $validator; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* validate database-name |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $data database-name |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
public function validateDbName($data): bool |
|
61
|
|
|
{ |
|
62
|
|
|
$connection = ConnectionManager::get('default'); |
|
63
|
|
|
$dbConfig = $connection->config(); |
|
64
|
|
|
|
|
65
|
|
|
return $data === $dbConfig['database']; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* validate database-password |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $data database-password |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
public function validateDbPassword($data): bool |
|
75
|
|
|
{ |
|
76
|
|
|
$connection = ConnectionManager::get('default'); |
|
77
|
|
|
$dbConfig = $connection->config(); |
|
78
|
|
|
|
|
79
|
|
|
return $data === $dbConfig['password']; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
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.