Fix installation and tests

This commit is contained in:
DariusIII
2018-01-18 13:34:26 +01:00
parent 841e5c93af
commit de91486ec5
4 changed files with 22 additions and 101 deletions
-1
View File
@@ -49,7 +49,6 @@ before_script:
- mysql -u root -e "GRANT ALL ON TEST.* TO 'TEST'@'localhost' IDENTIFIED BY 'TEST';"
- mysql -u root -e "GRANT FILE ON *.* TO 'TEST'@'localhost';"
- mysql -u TEST -pTEST TEST < resources/db/schema/mysql-ddl.sql
- mysql --local-infile=1 -u TEST -pTEST -e "LOAD DATA LOCAL INFILE 'resources/db/schema/data/10-settings.tsv' IGNORE INTO TABLE TEST.settings FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY '\n' IGNORE 1 LINES (section,subsection,name,value,hint,setting);"
# Disable apparmor.
- if service apparmor status; then service apparmor stop; update-rc.d -f apparmor remove; service apparmor teardown; fi
# Change MySQL settings.
+1
View File
@@ -1,4 +1,5 @@
2018-01-18 DariusIII
* Fix: Fix installation and tests
* Chg: Update scrutinizer config
* Chg: Change installation, remove tsv files and related tables, use migrations and seeding for them
2018-01-17 DariusIII
+11 -50
View File
@@ -11,7 +11,6 @@ use nntmux\ColorCLI;
use nntmux\db\DbUpdate;
use nntmux\config\Configure;
use App\Extensions\util\Versions;
use Illuminate\Database\Capsule\Manager as Capsule;
$config = new Configure('install');
@@ -97,15 +96,18 @@ if (! $error) {
);
$pdo->exec('SET FOREIGN_KEY_CHECKS=0;');
try {
$DbSetup->processSQLFile(); // Setup default schema
ColorCLI::doEcho(ColorCLI::header('Migrating tables and populating them'));
passthru('php '.NN_ROOT.'artisan migrate');
passthru('php '.NN_ROOT.'artisan db:seed');
} catch (\RuntimeException $err) {
$DbSetup->processSQLFile(); // Setup default schema
//Insert admin user into database
if (env('ADMIN_USER') === '' || env('ADMIN_PASS') === '' || env('ADMIN_EMAIL') === '') {
$error = true;
ColorCLI::doEcho(ColorCLI::error('Error ('.$err->getMessage().')'));
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();
}
$pdo->queryExec(sprintf('INSERT INTO users (username, email, password, user_roles_id, created_at) VALUES (%s, %s, %s, 2, NOW())', $pdo->escapeString(env('ADMIN_USER')), $pdo->escapeString(env('ADMIN_EMAIL')), $pdo->escapeString(User::hashPassword(env('ADMIN_PASS')))));
ColorCLI::doEcho(ColorCLI::header('Migrating tables and populating them'));
passthru('php '.NN_ROOT.'artisan migrate');
passthru('php '.NN_ROOT.'artisan db:seed');
if (! $error) {
// Check one of the standard tables was created and has data.
@@ -128,7 +130,7 @@ if (! $error) {
if ($dbInstallWorked) {
$updateSettings = false;
if ($patch > 0) {
$updateSettings = $pdo->exec(
$updateSettings = $pdo->queryExec(
"UPDATE settings SET value = '$patch' WHERE section = '' AND subsection = '' AND name = 'sqlpatch'"
);
}
@@ -146,47 +148,6 @@ if (! $error) {
}
}
}
//Insert admin user into database
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();
}
$capsule = new Capsule;
// Same as database configuration file of Laravel.
$capsule->addConnection([
'driver' => env('DB_SYSTEM'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_NAME', 'nntmux'),
'username' => env('DB_USER', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'strict' => false,
]);
$capsule->bootEloquent();
if (! User::isValidUsername(env('ADMIN_USER'))) {
$error = true;
} else {
$usrCheck = User::getByUsername(env('ADMIN_USER'));
if ($usrCheck) {
$error = true;
}
}
if (! User::isValidEmail(env('ADMIN_EMAIL'))) {
$error = true;
}
if (! $error) {
$adminCheck = User::add(env('ADMIN_USER'), env('ADMIN_PASS'), env('ADMIN_EMAIL'), 2, '', '');
if (! is_numeric($adminCheck)) {
$error = true;
}
}
if (! $error) {
$doCheck = true;
+10 -50
View File
@@ -125,15 +125,17 @@ class InstallTest extends \PHPUnit\Framework\TestCase
);
$pdo->exec('SET FOREIGN_KEY_CHECKS=0;');
try {
$DbSetup->processSQLFile(); // Setup default schema
ColorCLI::doEcho(ColorCLI::header('Migrating tables and populating them'));
passthru('php '.NN_ROOT.'artisan migrate');
passthru('php '.NN_ROOT.'artisan db:seed');
} catch (\RuntimeException $err){
$DbSetup->processSQLFile(); // Setup default schema
//Insert admin user into database
if (env('ADMIN_USER') === '' || env('ADMIN_PASS') === '' || env('ADMIN_EMAIL') === '') {
$error = true;
ColorCLI::doEcho(ColorCLI::error('Error (' . $err->getMessage() . ')'));
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();
}
$pdo->queryExec(sprintf('INSERT INTO users (username, email, password, user_roles_id, created_at) VALUES (%s, %s, %s, 2, NOW())', $pdo->escapeString(env('ADMIN_USER')), $pdo->escapeString(env('ADMIN_EMAIL')), $pdo->escapeString(User::hashPassword(env('ADMIN_PASS')))));
ColorCLI::doEcho(ColorCLI::header('Migrating tables and populating them'));
passthru('php '.NN_ROOT.'artisan migrate');
passthru('php '.NN_ROOT.'artisan db:seed');
if (!$error) {
// Check one of the standard tables was created and has data.
@@ -156,7 +158,7 @@ class InstallTest extends \PHPUnit\Framework\TestCase
if ($dbInstallWorked) {
$updateSettings = false;
if ($patch > 0) {
$updateSettings = $pdo->exec(
$updateSettings = $pdo->queryExec(
"UPDATE settings SET value = '$patch' WHERE section = '' AND subsection = '' AND name = 'sqlpatch'"
);
}
@@ -176,48 +178,6 @@ class InstallTest extends \PHPUnit\Framework\TestCase
}
}
}
//Insert admin user into database
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();
}
$capsule = new Capsule;
// Same as database configuration file of Laravel.
$capsule->addConnection([
'driver' => env('DB_SYSTEM'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_NAME', 'nntmux'),
'username' => env('DB_USER', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'strict' => false
], 'default'
);
$capsule->bootEloquent();
if (!User::isValidUsername(env('ADMIN_USER'))) {
$error = true;
} else {
$usrCheck = User::getByUsername(env('ADMIN_USER'));
if ($usrCheck) {
$error = true;
}
}
if (!User::isValidEmail(env('ADMIN_EMAIL'))) {
$error = true;
}
if (!$error) {
$adminCheck = User::add(env('ADMIN_USER'), env('ADMIN_PASS'), env('ADMIN_EMAIL'), 2, '', '');
if (!is_numeric($adminCheck)) {
$error = true;
}
}
if (!$error) {
$doCheck = true;