Add more debugging output to DbUpdate class and install_nntmux script

This commit is contained in:
DariusIII
2017-06-16 11:42:58 +02:00
parent 10bf1821f8
commit 02cc687e64
3 changed files with 37 additions and 26 deletions
+2
View File
@@ -1,3 +1,5 @@
2017-06-16 DariusIII
* Chg: Add more debugging output to DbUpdate class and install_nntmux script
2017-06-15 DariusIII
* Fix: Fix collection regexes testing page
2017-06-14 DariusIII
+22 -22
View File
@@ -24,8 +24,8 @@ if (file_exists(NN_ROOT . '_install/install.lock')) {
}
// Check if user selected right DB type.
if (getenv('DB_SYSTEM') !== 'mysql') {
ColorCLI::doEcho(ColorCLI::error('Invalid database system. Must be: mysql ; Not: ' . getenv('DB_SYSTEM')));
if (env('DB_SYSTEM') !== 'mysql') {
ColorCLI::doEcho(ColorCLI::error('Invalid database system. Must be: mysql ; Not: ' . env('DB_SYSTEM')));
$error = true;
} else {
// Connect to the SQL server.
@@ -35,13 +35,13 @@ if (getenv('DB_SYSTEM') !== 'mysql') {
[
'checkVersion' => true,
'createDb' => true,
'dbhost' => getenv('DB_HOST'),
'dbname' => getenv('DB_NAME'),
'dbpass' => getenv('DB_PASSWORD'),
'dbport' => getenv('PORT'),
'dbsock' => getenv('DB_SOCKET'),
'dbtype' => getenv('DB_SYSTEM'),
'dbuser' => getenv('DB_USER'),
'dbhost' => env('DB_HOST'),
'dbname' => env('DB_NAME'),
'dbpass' => env('DB_PASSWORD'),
'dbport' => env('PORT'),
'dbsock' => env('DB_SOCKET'),
'dbtype' => env('DB_SYSTEM'),
'dbuser' => env('DB_USER'),
]
);
$dbConnCheck = true;
@@ -78,7 +78,7 @@ if (getenv('DB_SYSTEM') !== 'mysql') {
$error = true;
ColorCLI::doEcho(ColorCLI::error(
'You are using an unsupported version of ' .
getenv('DB_SYSTEM') .
env('DB_SYSTEM') .
' the minimum allowed version is ' .
NN_MINIMUM_MYSQL_VERSION
)
@@ -149,13 +149,13 @@ if (!$error) {
}
}
//Insert admin user into database
if (getenv('ADMIN_USER') === '' || getenv('ADMIN_PASS') === '' || getenv('ADMIN_EMAIL') === '') {
if (env('ADMIN_USER') === '' || env('ADMIN_PASS') === '' || env('ADMIN_EMAIL') === '') {
$error = true;
ColorCLI::doEcho(ColorCLI::error('Admin user data cannot be empty! Please edit .env file and fill in admin user details and run this script again!'));
exit();
}
switch (getenv('DB_SYSTEM')) {
switch (env('DB_SYSTEM')) {
case 'mysql':
$adapter = 'MySql';
break;
@@ -167,10 +167,10 @@ switch (getenv('DB_SYSTEM')) {
}
if ($adapter !== null) {
if (empty(getenv('DB_SOCKET'))) {
$host = empty(getenv('DB_PORT')) ? getenv('DB_HOST') : getenv('DB_HOST') . ':' . getenv('DB_PORT');
if (empty(env('DB_SOCKET'))) {
$host = empty(env('DB_PORT')) ? env('DB_HOST') : env('DB_HOST') . ':' . env('DB_PORT');
} else {
$host = getenv('DB_SOCKET');
$host = env('DB_SOCKET');
}
lithium\data\Connections::add('default',
@@ -178,9 +178,9 @@ if ($adapter !== null) {
'type' => 'database',
'adapter' => $adapter,
'host' => $host,
'login' => getenv('DB_USER'),
'password' => getenv('DB_PASSWORD'),
'database' => getenv('DB_NAME'),
'login' => env('DB_USER'),
'password' => env('DB_PASSWORD'),
'database' => env('DB_NAME'),
'encoding' => 'UTF-8',
'persistent' => false,
]
@@ -188,20 +188,20 @@ if ($adapter !== null) {
}
$user = new Users();
if (!$user->isValidUsername(getenv('ADMIN_USER'))) {
if (!$user->isValidUsername(env('ADMIN_USER'))) {
$error = true;
} else {
$usrCheck = $user->getByUsername(getenv('ADMIN_USER'));
$usrCheck = $user->getByUsername(env('ADMIN_USER'));
if ($usrCheck) {
$error = true;
}
}
if (!$user->isValidEmail(getenv('ADMIN_EMAIL'))) {
if (!$user->isValidEmail(env('ADMIN_EMAIL'))) {
$error = true;
}
if (!$error) {
$adminCheck = $user->add(getenv('ADMIN_USER'), getenv('ADMIN_PASS'), getenv('ADMIN_EMAIL'), 2, '', '');
$adminCheck = $user->add(env('ADMIN_USER'), env('ADMIN_PASS'), env('ADMIN_EMAIL'), 2, '', '');
if (!is_numeric($adminCheck)) {
$error = true;
}
+13 -4
View File
@@ -84,6 +84,7 @@ class DbUpdate
public function loadTables(array $options = [])
{
$defaults = [
'enclosedby' => null,
'ext' => 'tsv',
'files' => [],
'path' => NN_RES . 'db' . DS . 'schema' . DS . 'data',
@@ -96,8 +97,10 @@ class DbUpdate
$files = empty($options['files']) ? Utility::getDirFiles($options) : $options['files'];
natsort($files);
$local = $this->pdo->isLocalDb() ? '' : 'LOCAL ';
$enclosedby = empty($options['enclosedby']) ? '' : 'OPTIONALLY ENCLOSED BY "' .
$options['enclosedby'] . '"';
$sql = 'LOAD DATA ' .
$local . 'INFILE "%s" IGNORE INTO TABLE `%s` FIELDS TERMINATED BY "\t" OPTIONALLY ENCLOSED BY "\"" LINES TERMINATED BY "\n" IGNORE 1 LINES (%s)';
$local . 'INFILE "%s" IGNORE INTO TABLE `%s` FIELDS TERMINATED BY "\t" ' . $enclosedby . 'LINES TERMINATED BY "\n" IGNORE 1 LINES (%s)';
foreach ($files as $file) {
if ($show === true) {
echo "File: $file\n";
@@ -107,7 +110,7 @@ class DbUpdate
if (preg_match($options['regex'], $file, $matches)) {
$table = $matches['table'];
// Get the first line of the file which holds the columns used.
$handle = @fopen($file, "r");
$handle = @fopen($file, 'rb');
if (is_resource($handle)) {
$line = fgets($handle);
fclose($handle);
@@ -118,12 +121,18 @@ class DbUpdate
$fields = trim($line);
if ($show === true) {
echo "Inserting data into table: '$table'\n";
ColorCLI::doEcho(ColorCLI::info('Inserting data into table: ' . $table));
}
if (Utility::isWin()) {
$file = str_replace("\\", '\/', $file);
}
$this->pdo->exec(sprintf($sql, $file, $table, $fields));
$this->pdo->queryExec(sprintf($sql, $file, $table, $fields));
$success = $this->pdo->query(sprintf('SELECT COUNT(id) AS num FROM %s', $table));
if (empty($success[0]['num'])) {
ColorCLI::doEcho(ColorCLI::error('Failed to insert data into table: ' . $table ));
} else {
ColorCLI::doEcho(ColorCLI::notice('Successfully inserted data into ' . $table . ' table'));
}
} else {
exit("Failed to open file: '$file'\n");
}