21
21
namespace Xibo\Helper;
24
23
use Xibo\Exception\InstallationError;
25
24
use Xibo\Service\ConfigService;
25
use Xibo\Service\SanitizerServiceInterface;
26
use Xibo\Service\SanitizeService;
27
use Xibo\Storage\StorageServiceInterface;
31
* @package Xibo\Helper
36
37
public $db_admin_user;
44
45
public $existing_db_pass;
45
46
public $existing_db_name;
47
public function __construct($app)
57
public function getApp()
48
/** @var SanitizerServiceInterface */
52
* Install constructor.
53
* @param SanitizeService $sanitizer
55
public function __construct($sanitizer)
57
$this->sanitizer = $sanitizer;
62
63
public function Step1()
69
73
public function Step2()
74
public function Step3()
79
* @param StorageServiceInterface $store
80
* @throws InstallationError
82
public function Step3($store)
76
84
// Have we been told to create a new database
77
$this->db_create = $this->getSanitizer()->getInt('db_create');
85
$this->db_create = $this->sanitizer->getInt('db_create');
79
87
// Check all parameters have been specified
80
$this->db_admin_user = $this->getSanitizer()->getString('admin_username');
81
$this->db_admin_pass = $this->getSanitizer()->getString('admin_password');
83
$this->new_db_host = $this->getSanitizer()->getString('host');
84
$this->new_db_user = $this->getSanitizer()->getString('db_username');
85
$this->new_db_pass = $this->getSanitizer()->getString('db_password');
86
$this->new_db_name = $this->getSanitizer()->getString('db_name');
88
$this->existing_db_host = $this->getSanitizer()->getString('existing_host');
89
$this->existing_db_user = $this->getSanitizer()->getString('existing_db_username');
90
$this->existing_db_pass = $this->getSanitizer()->getString('existing_db_password');
91
$this->existing_db_name = $this->getSanitizer()->getString('existing_db_name');
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');
93
101
// If an administrator user name / password has been specified then we should create a new DB
94
102
if ($this->db_create == 1) {
111
119
// Try to create the new database
112
120
// Try and connect using these details and create the new database
114
$this->getStore()->connect($this->new_db_host, $this->db_admin_user, $this->db_admin_pass);
122
$store->connect($this->new_db_host, $this->db_admin_user, $this->db_admin_pass);
115
123
} catch (\PDOException $e) {
116
124
throw new InstallationError(sprintf(__('Could not connect to MySQL with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
119
127
// Try to create the new database
121
$dbh = $this->getStore()->getConnection();
129
$dbh = $store->getConnection();
122
130
$dbh->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8 COLLATE utf8_general_ci', $this->new_db_name));
123
131
} catch (\PDOException $e) {
124
132
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()));
127
135
// Try to create the new user
129
$dbh = $this->getStore()->getConnection();
137
$dbh = $store->getConnection();
131
139
// Create the user and grant privileges
132
140
if ($this->new_db_host == 'localhost') {
176
185
// Try and make a connection with this database
178
$this->getStore()->connect($this->existing_db_host, $this->existing_db_user, $this->existing_db_pass, $this->existing_db_name);
187
$store->connect($this->existing_db_host, $this->existing_db_user, $this->existing_db_pass, $this->existing_db_name);
179
188
} catch (\PDOException $e) {
180
189
throw new InstallationError(sprintf(__('Could not connect to MySQL with the administrator details. Please check and try again. Error Message = [%s]'), $e->getMessage()));
215
224
$secretKey = Install::generateSecret();
217
226
// Escape the password before we write it to disk
218
$dbh = $this->getStore()->getConnection();
227
$dbh = $store->getConnection();
219
228
$existing_db_pass = addslashes($this->existing_db_pass);
221
230
$settings = <<<END
262
271
// This is handled by the calling function (i.e. there is no output from this call, we just reload and move on)
265
277
public function Step4()
270
public function Step5()
283
* @param StorageServiceInterface $store
284
* @throws InstallationError
286
public function Step5($store)
272
288
// Configure the user account
273
$username = $this->getSanitizer()->getString('admin_username');
274
$password = $this->getSanitizer()->getString('admin_password');
289
$username = $this->sanitizer->getString('admin_username');
290
$password = $this->sanitizer->getString('admin_password');
276
292
if ($username == '')
277
293
throw new InstallationError(__('Missing the admin username.'));
282
298
// Update user id 1 with these details.
284
$dbh = $this->getStore()->getConnection();
300
$dbh = $store->getConnection();
286
302
$sth = $dbh->prepare('UPDATE `user` SET UserName = :username, UserPassword = :password WHERE UserID = 1 LIMIT 1');
287
303
$sth->execute(array(
310
public function Step7()
330
* @param StorageServiceInterface $store
331
* @throws InstallationError
333
public function Step7($store)
312
$server_key = $this->getSanitizer()->getString('server_key');
313
$library_location = $this->getSanitizer()->getString('library_location');
314
$stats = $this->getSanitizer()->getCheckbox('stats');
335
$server_key = $this->sanitizer->getString('server_key');
336
$library_location = $this->sanitizer->getString('library_location');
337
$stats = $this->sanitizer->getCheckbox('stats');
316
339
if ($server_key == '')
317
340
throw new InstallationError(__('Missing the server key.'));