|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* The MIT License (MIT) |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (c) 2015 Daniel Popiniuc |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
11
|
|
|
* in the Software without restriction, including without limitation the rights |
|
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
14
|
|
|
* furnished to do so, subject to the following conditions: |
|
15
|
|
|
* |
|
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
17
|
|
|
* copies or substantial portions of the Software. |
|
18
|
|
|
* |
|
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
25
|
|
|
* SOFTWARE. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace danielgp\fk_scale_mysql; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Description of FKchange |
|
33
|
|
|
* |
|
34
|
|
|
* @author Daniel Popiniuc <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
trait FKinterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
use \danielgp\common_lib\CommonCode; |
|
40
|
|
|
|
|
41
|
|
|
private function buildInputFormForFKscaling($mysqlConfig, $sGb) |
|
42
|
|
|
{ |
|
43
|
|
|
$sReturn = []; |
|
44
|
|
|
$sReturn[] = $this->buildInputs(['field' => 'db', 'label' => 'Database name to analyze'], $sGb); |
|
45
|
|
|
$sReturn[] = $this->buildInputs(['field' => 'tbl', 'label' => 'Table name to analyze'], $sGb); |
|
46
|
|
|
$sReturn[] = $this->buildInputs(['field' => 'fld', 'label' => 'Field name to analyze'], $sGb); |
|
47
|
|
|
$sReturn[] = $this->buildInputs(['field' => 'dt', 'label' => 'Data type to change to'], $sGb); |
|
48
|
|
|
$sReturn[] = '<input type="submit" value="Generate SQL queries for scaling" />'; |
|
49
|
|
|
$sReturn[] = $this->displayMySqlConfiguration($mysqlConfig); |
|
50
|
|
|
return '<form method="get" action="' . filter_var($sGb->server->get('PHP_SELF'), FILTER_SANITIZE_URL) . '">' |
|
51
|
|
|
. implode('<br/>', $sReturn) |
|
52
|
|
|
. '</form>'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function buildInputFormTab($mysqlConfig, $transmitedParameters, $sGb) |
|
56
|
|
|
{ |
|
57
|
|
|
return '<div class="tabber" id="tabberFKscaleMySQL">' |
|
58
|
|
|
. '<div class="tabbertab' . ($transmitedParameters ? '' : ' tabbertabdefault') |
|
59
|
|
|
. '" id="FKscaleMySQLparameters" title="Parameters for scaling">' |
|
60
|
|
|
. $this->buildInputFormForFKscaling($mysqlConfig, $sGb) |
|
61
|
|
|
. '</div><!-- end of Parameters tab -->'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private function buildInputs($inArray, $sGb) |
|
65
|
|
|
{ |
|
66
|
|
|
return '<label for="' . $inArray['field'] . 'Name">' . $inArray['label'] . ':</label>' |
|
67
|
|
|
. '<input type="text" id="' . $inArray['field'] . 'Name" name="' . $inArray['field'] |
|
68
|
|
|
. '" placeholder="' . explode(' ', $inArray['label'])[0] . ' name" ' |
|
69
|
|
|
. $this->returnInputsCleaned($inArray['field'], $sGb) |
|
70
|
|
|
. 'size="30" maxlength="64" class="labell" />'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function displayMySqlConfiguration($mysqlConfig) |
|
74
|
|
|
{ |
|
75
|
|
|
$styleForMySQLparams = 'color:green;font-weight:bold;font-style:italic;'; |
|
76
|
|
|
return '<p>For security reasons the MySQL connection details are not available ' |
|
77
|
|
|
. 'to be set/modified through the interface and must be set directly ' |
|
78
|
|
|
. 'into the "configurationMySQL.php" file. Currently these settings are:<ul>' |
|
79
|
|
|
. '<li>Host name where MySQL server resides: <span style="' . $styleForMySQLparams . '">' |
|
80
|
|
|
. $mysqlConfig['host'] . '</span></li>' |
|
81
|
|
|
. '<li>MySQL port used: <span style="' . $styleForMySQLparams . '">' |
|
82
|
|
|
. $mysqlConfig['port'] . '</span></li>' |
|
83
|
|
|
. '<li>MySQL database to connect to: <span style="' . $styleForMySQLparams . '">' |
|
84
|
|
|
. $mysqlConfig['database'] . '</span></li>' |
|
85
|
|
|
. '<li>MySQL username used: <span style="' . $styleForMySQLparams . '">' |
|
86
|
|
|
. $mysqlConfig['username'] . '</span></li>' |
|
87
|
|
|
. '<li>MySQL password used: <span style="' . $styleForMySQLparams . '">' |
|
88
|
|
|
. 'cannot be disclosed due to security reasons</span></li>' |
|
89
|
|
|
. '</ul></p>'; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
private function returnInputsCleaned($inputFieldName, $sGb) |
|
93
|
|
|
{ |
|
94
|
|
|
$sReturn = ''; |
|
95
|
|
|
if (!is_null($sGb->get($inputFieldName))) { |
|
96
|
|
|
$sReturn = 'value="' . filter_var($sGb->get($inputFieldName), FILTER_SANITIZE_STRING) . '" '; |
|
97
|
|
|
} |
|
98
|
|
|
return $sReturn; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function returnMessagesInCaseOfNoResults($mConnection) |
|
102
|
|
|
{ |
|
103
|
|
|
if (strlen($mConnection) === 0) { |
|
104
|
|
|
return '<p style="color:red;">Check if provided parameters are correct ' |
|
105
|
|
|
. 'as the combination of Database. Table and Column name were not found as a Foreign Key!</p>'; |
|
106
|
|
|
} else { |
|
107
|
|
|
return '<p style="color:red;">Check your "configurationMySQL.php" file ' |
|
108
|
|
|
. 'for correct MySQL connection parameters ' |
|
109
|
|
|
. 'as the current ones were not able to be used to establish a connection!</p>'; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function setApplicationFooter() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->setFooterCommon(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
protected function setApplicationHeader() |
|
119
|
|
|
{ |
|
120
|
|
|
$pageTitle = 'Foreign Keys Scale in MySQL'; |
|
121
|
|
|
$headerArray = [ |
|
122
|
|
|
'css' => [ |
|
123
|
|
|
'css/fk_scale_mysql.css', |
|
124
|
|
|
], |
|
125
|
|
|
'javascript' => [ |
|
126
|
|
|
'vendor/danielgp/common-lib/js/tabber/tabber-management.min.js', |
|
127
|
|
|
'vendor/danielgp/common-lib/js/tabber/tabber.min.js', |
|
128
|
|
|
], |
|
129
|
|
|
'lang' => 'en-US', |
|
130
|
|
|
'title' => $pageTitle, |
|
131
|
|
|
]; |
|
132
|
|
|
return $this->setHeaderCommon($headerArray) |
|
133
|
|
|
. '<h1>' . $pageTitle . '</h1>'; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|