2
2
3
3
namespace OpenXdmod \Shared ;
4
4
5
+ use CCR \DB ;
5
6
use CCR \DB \MySQLHelper ;
6
7
use OpenXdmod \Setup \Console ;
7
8
@@ -24,6 +25,7 @@ class DatabaseHelper
24
25
* @param Console $console (Optional) The console to use to prompt the user.
25
26
* If not provided, one will be obtained.
26
27
*/
28
+
27
29
public static function createDatabases (
28
30
$ username ,
29
31
$ password ,
@@ -35,23 +37,50 @@ public static function createDatabases(
35
37
$ console = Console::factory ();
36
38
}
37
39
40
+ $ rows = MySQLHelper::userExists (
41
+ $ settings ['db_host ' ],
42
+ $ settings ['db_port ' ],
43
+ $ username ,
44
+ $ password ,
45
+ $ settings ['db_user ' ],
46
+ $ settings ['xdmod_host ' ]
47
+ );
38
48
$ console ->displayMessage (
39
- ' Creating User ' . $ settings [ ' db_user ' ]
49
+ ' rows retuned ' . $ rows
40
50
);
41
- // TODO: If db_host is not localhost, need to set $localHost to
42
- // the correct hostname or IP address.
43
- $ localHost = $ settings ['db_host ' ];
44
-
51
+ if ($ rows == false ) {
52
+ $ console ->displayMessage (
53
+ 'Creating User ' . $ settings ['db_user ' ]
54
+ );
55
+ $ console ->displayMessage (
56
+ 'Creating User with ' . $ settings ['db_user ' ] . ' on host ' . $ settings ['xdmod_host ' ] . ' with password ' . $ settings ['db_pass ' ]
57
+ );
58
+ MySQLHelper::staticExecuteStatement (
59
+ $ settings ['db_host ' ],
60
+ $ settings ['db_port ' ],
61
+ $ username ,
62
+ $ password ,
63
+ null ,
64
+ sprintf (
65
+ "CREATE USER '%s'@'%s' IDENTIFIED BY '%s'; " ,
66
+ $ settings ['db_user ' ],
67
+ $ settings ['xdmod_host ' ],
68
+ $ settings ['db_pass ' ],
69
+ )
70
+ );
71
+ $ console ->displayMessage (
72
+ 'Created User '
73
+ );
74
+ }
45
75
MySQLHelper::grantAllPrivileges (
46
76
$ settings ['db_host ' ],
47
77
$ settings ['db_port ' ],
48
78
$ username ,
49
79
$ password ,
50
- $ localHost ,
80
+ $ settings [ ' xdmod_host ' ] ,
51
81
$ settings ['db_user ' ],
52
82
$ settings ['db_pass ' ]
53
83
);
54
-
55
84
foreach ($ databases as $ database ) {
56
85
$ console ->displayBlankLine ();
57
86
@@ -97,10 +126,6 @@ public static function createDatabases(
97
126
$ database
98
127
);
99
128
100
- // TODO: If db_host is not localhost, need to set $localHost to
101
- // the correct hostname or IP address.
102
- $ localHost = $ settings ['db_host ' ];
103
-
104
129
$ console ->displayMessage (
105
130
"Granting privileges on database ` $ database`. "
106
131
);
@@ -110,7 +135,7 @@ public static function createDatabases(
110
135
$ username ,
111
136
$ password ,
112
137
$ database ,
113
- $ localHost ,
138
+ $ settings [ ' xdmod_host ' ] ,
114
139
$ settings ['db_user ' ],
115
140
$ settings ['db_pass ' ]
116
141
);
0 commit comments