45
38
public $existing_db_pass;
46
39
public $existing_db_name;
48
/** @var SanitizerServiceInterface */
52
* Install constructor.
53
* @param SanitizeService $sanitizer
55
public function __construct($sanitizer)
57
$this->sanitizer = $sanitizer;
63
41
public function Step1()
66
'config' => new ConfigService()
44
'config' => new Config()
73
48
public function Step2()
79
* @param StorageServiceInterface $store
80
* @throws InstallationError
82
public function Step3($store)
53
public function Step3()
84
55
// Have we been told to create a new database
85
$this->db_create = $this->sanitizer->getInt('db_create');
56
$this->db_create = Sanitize::getInt('db_create');
87
58
// Check all parameters have been specified
88
$this->db_admin_user = $this->sanitizer->getString('admin_username');
89
$this->db_admin_pass = $this->sanitizer->getString('admin_password');
91
$this->new_db_host = $this->sanitizer->getString('host');
92
$this->new_db_user = $this->sanitizer->getString('db_username');
93
$this->new_db_pass = $this->sanitizer->getString('db_password');
94
$this->new_db_name = $this->sanitizer->getString('db_name');
96
$this->existing_db_host = $this->sanitizer->getString('existing_host');
97
$this->existing_db_user = $this->sanitizer->getString('existing_db_username');
98
$this->existing_db_pass = $this->sanitizer->getString('existing_db_password');
99
$this->existing_db_name = $this->sanitizer->getString('existing_db_name');
59
$this->db_admin_user = Sanitize::getString('admin_username');
60
$this->db_admin_pass = Sanitize::getString('admin_password');
62
$this->new_db_host = Sanitize::getString('host');
63
$this->new_db_user = Sanitize::getString('db_username');
64
$this->new_db_pass = Sanitize::getString('db_password');
65
$this->new_db_name = Sanitize::getString('db_name');
67
$this->existing_db_host = Sanitize::getString('existing_host');
68
$this->existing_db_user = Sanitize::getString('existing_db_username');
69
$this->existing_db_pass = Sanitize::getString('existing_db_password');
70
$this->existing_db_name = Sanitize::getString('existing_db_name');
101
72
// If an administrator user name / password has been specified then we should create a new DB
102
73
if ($this->db_create == 1) {
119
90
// Try to create the new database
120
91
// Try and connect using these details and create the new database
122
$store->connect($this->new_db_host, $this->db_admin_user, $this->db_admin_pass);
93
PDOConnect::connect($this->new_db_host, $this->db_admin_user, $this->db_admin_pass);
123
94
} catch (\PDOException $e) {
124
95
throw new InstallationError(sprintf(__('Could not connect to MySQL with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
127
98
// Try to create the new database
129
$dbh = $store->getConnection();
130
$dbh->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8 COLLATE utf8_general_ci', $this->new_db_name));
100
$dbh = PDOConnect::init();
101
$dbh->exec(sprintf('CREATE DATABASE `%s`', $this->new_db_name));
131
102
} catch (\PDOException $e) {
132
103
throw new InstallationError(sprintf(__('Could not create a new database with the administrator details [%s]. Please check and try again. Error Message = [%s]'), $this->db_admin_user, $e->getMessage()));
135
106
// Try to create the new user
137
$dbh = $store->getConnection();
108
$dbh = PDOConnect::init();
139
110
// Create the user and grant privileges
140
111
if ($this->new_db_host == 'localhost') {
141
$sql = sprintf('GRANT ALL PRIVILEGES ON `%s`.* to %s@%s IDENTIFIED BY %s',
143
$dbh->quote($this->new_db_user),
144
$dbh->quote($this->new_db_host),
145
$dbh->quote($this->new_db_pass)
112
$dbh->exec(sprintf('GRANT ALL PRIVILEGES ON `%s`.* to %s@%s IDENTIFIED BY %s',
114
$dbh->quote($this->new_db_user),
115
$dbh->quote($this->new_db_host),
116
$dbh->quote($this->new_db_pass))
150
$sql = sprintf('GRANT ALL PRIVILEGES ON `%s`.* to %s@\'%%\' IDENTIFIED BY %s',
152
$dbh->quote($this->new_db_user),
153
$dbh->quote($this->new_db_pass)
119
$dbh->exec(sprintf("GRANT ALL PRIVILEGES ON `%s`.* to %s@%% IDENTIFIED BY %s",
121
$dbh->quote($this->new_db_user),
122
$dbh->quote($this->new_db_pass))
160
127
$dbh->exec('FLUSH PRIVILEGES');
161
128
} catch (\PDOException $e) {
162
throw new InstallationError(sprintf(__('Could not create a new user with the administrator details. Please check and try again. Error Message = [%s]. SQL = [%s].'), $e->getMessage(), $sql));
129
throw new InstallationError(sprintf(__('Could not create a new user with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
165
132
// Set our DB details
189
155
// Try and make a connection with this database
191
$store->connect($this->existing_db_host, $this->existing_db_user, $this->existing_db_pass, $this->existing_db_name);
157
PDOConnect::connect($this->existing_db_host, $this->existing_db_user, $this->existing_db_pass, $this->existing_db_name);
192
158
} catch (\PDOException $e) {
193
159
throw new InstallationError(sprintf(__('Could not connect to MySQL with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
196
162
// We should have a database that we can access and populate with our tables.
197
$sql_files = array('structure.sql', 'data.sql', 'constraints.sql');
163
$sql_files = array('structure.sql', 'data.sql');
198
164
$sqlStatementCount = 0;
203
$dbh = $store->getConnection();
169
$dbh = PDOConnect::init();
205
171
foreach ($sql_files as $filename) {
206
172
$delimiter = ';';
275
233
// This is handled by the calling function (i.e. there is no output from this call, we just reload and move on)
281
236
public function Step4()
287
* @param StorageServiceInterface $store
288
* @throws InstallationError
290
public function Step5($store)
241
public function Step5()
292
243
// Configure the user account
293
$username = $this->sanitizer->getString('admin_username');
294
$password = $this->sanitizer->getString('admin_password');
244
$username = Sanitize::getString('admin_username');
245
$password = Sanitize::getString('admin_password');
296
247
if ($username == '')
297
248
throw new InstallationError(__('Missing the admin username.'));
334
* @param StorageServiceInterface $store
335
* @throws InstallationError
337
public function Step7($store)
281
public function Step7()
339
$server_key = $this->sanitizer->getString('server_key');
340
$library_location = $this->sanitizer->getString('library_location');
341
$stats = $this->sanitizer->getCheckbox('stats');
283
$server_key = Sanitize::getString('server_key');
284
$library_location = Sanitize::getString('library_location');
285
$stats = Sanitize::getCheckbox('stats');
343
287
if ($server_key == '')
344
288
throw new InstallationError(__('Missing the server key.'));