mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Update migrations, add stored procedures and trigers, fix phpunit test
This commit is contained in:
@@ -7,8 +7,8 @@ use nntmux\ColorCLI;
|
||||
use App\Models\Settings;
|
||||
use App\Extensions\util\Versions;
|
||||
|
||||
if (! defined('NN_INSTALLER')) {
|
||||
define('NN_INSTALLER', true);
|
||||
if (! \defined('NN_INSTALLER')) {
|
||||
\define('NN_INSTALLER', true);
|
||||
}
|
||||
|
||||
$error = false;
|
||||
@@ -18,16 +18,22 @@ if (file_exists(NN_ROOT.'_install/install.lock')) {
|
||||
exit();
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
// Check if user selected right DB type.
|
||||
if (env('DB_SYSTEM') !== 'mysql') {
|
||||
ColorCLI::doEcho(ColorCLI::error('Invalid database system. Must be: mysql ; Not: '.env('DB_SYSTEM')));
|
||||
if (env('DB_SYSTEM') !== 'mysql') {
|
||||
ColorCLI::doEcho(ColorCLI::error('Invalid database system. Must be: mysql ; Not: '.env('DB_SYSTEM')));
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(new Settings())->isDbVersionAtLeast(NN_MINIMUM_MARIA_VERSION) || !(new Settings())->isDbVersionAtLeast(NN_MINIMUM_MYSQL_VERSION)) {
|
||||
ColorCLI::doEcho(ColorCLI::error('Version of MariaDB used is lower than required version: ' . NN_MINIMUM_MARIA_VERSION));
|
||||
$error = true;
|
||||
}
|
||||
// Start inserting data into the DB.
|
||||
if (! $error) {
|
||||
ColorCLI::doEcho(ColorCLI::header('Migrating tables and populating them'));
|
||||
passthru('php '.NN_ROOT.'artisan migrate:fresh');
|
||||
passthru('php '.NN_ROOT.'artisan db:seed');
|
||||
passthru('php '.NN_ROOT.'artisan migrate:fresh --seed');
|
||||
}
|
||||
// Check one of the standard tables was created and has data.
|
||||
$ver = new Versions();
|
||||
|
||||
@@ -310,10 +310,10 @@ class Settings extends Model
|
||||
*/
|
||||
private function fetchDbVersion()
|
||||
{
|
||||
$pdo = DB::connection()->getPdo();
|
||||
$result = $pdo->exec('SELECT VERSION() AS version');
|
||||
$result = DB::select('SELECT VERSION() AS version');
|
||||
|
||||
if (! empty($result)) {
|
||||
$dummy = explode('-', $result['version'], 2);
|
||||
$dummy = explode('-', $result[0]->version, 2);
|
||||
$this->dbVersion = $dummy[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTriggers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared('CREATE TRIGGER check_insert BEFORE INSERT ON releases FOR EACH ROW BEGIN IF NEW.searchname REGEXP "[a-fA-F0-9]{32}" OR NEW.name REGEXP "[a-fA-F0-9]{32}"
|
||||
THEN SET NEW.ishashed = 1;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER check_update BEFORE UPDATE ON releases FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.searchname REGEXP "[a-fA-F0-9]{32}" OR NEW.name REGEXP "[a-fA-F0-9]{32}"
|
||||
THEN SET NEW.ishashed = 1;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER check_rfinsert BEFORE INSERT ON release_files FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.name REGEXP "[a-fA-F0-9]{32}"
|
||||
THEN SET NEW.ishashed = 1;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER check_rfupdate BEFORE UPDATE ON release_files FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.name REGEXP "[a-fA-F0-9]{32}"
|
||||
THEN SET NEW.ishashed = 1;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER insert_search AFTER INSERT ON releases FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO release_search_data (releases_id, guid, name, searchname, fromname) VALUES (NEW.id, NEW.guid, NEW.name, NEW.searchname, NEW.fromname);
|
||||
END;
|
||||
|
||||
CREATE TRIGGER update_search AFTER UPDATE ON releases FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.guid != OLD.guid
|
||||
THEN UPDATE release_search_data SET guid = NEW.guid WHERE releases_id = OLD.id;
|
||||
END IF;
|
||||
IF NEW.name != OLD.name
|
||||
THEN UPDATE release_search_data SET name = NEW.name WHERE releases_id = OLD.id;
|
||||
END IF;
|
||||
IF NEW.searchname != OLD.searchname
|
||||
THEN UPDATE release_search_data SET searchname = NEW.searchname WHERE releases_id = OLD.id;
|
||||
END IF;
|
||||
IF NEW.fromname != OLD.fromname
|
||||
THEN UPDATE release_search_data SET fromname = NEW.fromname WHERE releases_id = OLD.id;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER delete_search AFTER DELETE ON releases FOR EACH ROW
|
||||
BEGIN
|
||||
DELETE FROM release_search_data WHERE releases_id = OLD.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER insert_hashes AFTER INSERT ON predb FOR EACH ROW BEGIN INSERT INTO predb_hashes (hash, predb_id) VALUES (UNHEX(MD5(NEW.title)), NEW.id), (UNHEX(MD5(MD5(NEW.title))), NEW.id), (UNHEX(SHA1(NEW.title)), NEW.id), (UNHEX(SHA2(NEW.title, 256)), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid))), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid, NEW.requestid))), NEW.id);END;
|
||||
|
||||
CREATE TRIGGER update_hashes AFTER UPDATE ON predb FOR EACH ROW BEGIN IF NEW.title != OLD.title THEN DELETE FROM predb_hashes WHERE hash IN ( UNHEX(md5(OLD.title)), UNHEX(md5(md5(OLD.title))), UNHEX(sha1(OLD.title)), UNHEX(sha2(OLD.title, 256)), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid)))) AND predb_id = OLD.id; INSERT INTO predb_hashes (hash, predb_id) VALUES (UNHEX(MD5(NEW.title)), NEW.id), (UNHEX(MD5(MD5(NEW.title))), NEW.id), (UNHEX(SHA1(NEW.title)), NEW.id), (UNHEX(SHA2(NEW.title, 256)), NEW.id), (UNHEX(MD5(CONCAT((NEW.title, NEW.requestid)))), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid, NEW.requestid))), NEW.id);END IF;END;
|
||||
|
||||
CREATE TRIGGER delete_hashes AFTER DELETE ON predb FOR EACH ROW BEGIN DELETE FROM predb_hashes WHERE hash IN ( UNHEX(md5(OLD.title)), UNHEX(md5(md5(OLD.title))), UNHEX(sha1(OLD.title)), UNHEX(sha2(OLD.title, 256)), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid))), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid, OLD.requestid)))) AND predb_id = OLD.id;END;
|
||||
|
||||
CREATE TRIGGER insert_MD5 BEFORE INSERT ON release_comments FOR EACH ROW
|
||||
SET
|
||||
NEW.text_hash = MD5(NEW.text);
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared('DROP TRIGGER check_insert; DROP TRIGGER check_update; DROP TRIGGER check_rfinsert; DROP TRIGGER check_rfupdate; DROP TRIGGER insert_search; DROP TRIGGER update_search; DROP TRIGGER delete_search; DROP TRIGGER insert_hashes; DROP TRIGGER update_hashes; DROP TRIGGER delete_hashes; DROP TRIGGER insert_MD5;');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddStoredProcedures extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared('DROP PROCEDURE IF EXISTS loop_cbpm; DROP PROCEDURE IF EXISTS delete_release; CREATE PROCEDURE loop_cbpm(IN method CHAR(10))
|
||||
COMMENT "Performs tasks on All CBPM tables one by one -- REPAIR/ANALYZE/OPTIMIZE or DROP/TRUNCATE"
|
||||
|
||||
main: BEGIN
|
||||
DECLARE done INT DEFAULT 0;
|
||||
DECLARE tname VARCHAR(255) DEFAULT "";
|
||||
DECLARE regstr VARCHAR(255) CHARSET utf8 COLLATE utf8_general_ci DEFAULT "";
|
||||
|
||||
DECLARE cur1 CURSOR FOR
|
||||
SELECT TABLE_NAME
|
||||
FROM information_schema.TABLES
|
||||
WHERE
|
||||
TABLE_SCHEMA = (SELECT DATABASE())
|
||||
AND TABLE_NAME REGEXP regstr
|
||||
ORDER BY TABLE_NAME ASC;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
||||
|
||||
IF method NOT IN ("repair", "analyze", "optimize", "drop", "truncate")
|
||||
THEN LEAVE main; END IF;
|
||||
|
||||
IF method = "drop" THEN SET regstr = "^(collections|binaries|parts|missed_parts)_[0-9]+$";
|
||||
ELSE SET regstr = "^(multigroup_)?(collections|binaries|parts|missed_parts)(_[0-9]+)?$";
|
||||
END IF;
|
||||
|
||||
OPEN cur1;
|
||||
cbpm_loop: LOOP FETCH cur1
|
||||
INTO tname;
|
||||
IF done
|
||||
THEN LEAVE cbpm_loop; END IF;
|
||||
SET @SQL := CONCAT(method, " TABLE ", tname);
|
||||
PREPARE _stmt FROM @SQL;
|
||||
EXECUTE _stmt;
|
||||
DEALLOCATE PREPARE _stmt;
|
||||
END LOOP;
|
||||
CLOSE cur1;
|
||||
END;
|
||||
|
||||
|
||||
CREATE PROCEDURE delete_release(IN is_numeric BOOLEAN, IN identifier VARCHAR(40))
|
||||
COMMENT "Cascade deletes release from child tables when parent row is deleted"
|
||||
COMMENT "If is_numeric is true, identifier should be the releases_id, if false the guid"
|
||||
|
||||
main: BEGIN
|
||||
|
||||
DECLARE where_constr VARCHAR(255) DEFAULT "";
|
||||
|
||||
IF is_numeric IS TRUE
|
||||
THEN
|
||||
DELETE r, rn, rc, uc, rf, ra, rs, rv, re, df, rg
|
||||
FROM releases r
|
||||
LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id
|
||||
LEFT OUTER JOIN release_comments rc ON rc.releases_id = r.id
|
||||
LEFT OUTER JOIN users_releases uc ON uc.releases_id = r.id
|
||||
LEFT OUTER JOIN release_files rf ON rf.releases_id = r.id
|
||||
LEFT OUTER JOIN audio_data ra ON ra.releases_id = r.id
|
||||
LEFT OUTER JOIN release_subtitles rs ON rs.releases_id = r.id
|
||||
LEFT OUTER JOIN video_data rv ON rv.releases_id = r.id
|
||||
LEFT OUTER JOIN releaseextrafull re ON re.releases_id = r.id
|
||||
LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id
|
||||
LEFT OUTER JOIN releases_groups rg ON rg.releases_id = r.id
|
||||
WHERE r.id = identifier;
|
||||
|
||||
ELSEIF is_numeric IS FALSE
|
||||
THEN
|
||||
DELETE r, rn, rc, uc, rf, ra, rs, rv, re, df, rg
|
||||
FROM releases r
|
||||
LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id
|
||||
LEFT OUTER JOIN release_comments rc ON rc.releases_id = r.id
|
||||
LEFT OUTER JOIN users_releases uc ON uc.releases_id = r.id
|
||||
LEFT OUTER JOIN release_files rf ON rf.releases_id = r.id
|
||||
LEFT OUTER JOIN audio_data ra ON ra.releases_id = r.id
|
||||
LEFT OUTER JOIN release_subtitles rs ON rs.releases_id = r.id
|
||||
LEFT OUTER JOIN video_data rv ON rv.releases_id = r.id
|
||||
LEFT OUTER JOIN releaseextrafull re ON re.releases_id = r.id
|
||||
LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id
|
||||
LEFT OUTER JOIN releases_groups rg ON rg.releases_id = r.id
|
||||
WHERE r.guid = identifier;
|
||||
|
||||
ELSE LEAVE main;
|
||||
END IF;
|
||||
|
||||
END;');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared('DROP PROCEDURE loop_cbpm; DROP PROCEDURE delete_release;');
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/* This file is for users that currently use InnoDB with MySQL 5.6+ and want to use InnoDB for their replicated releasesearch table. While this isn't a requirement to import, the team
|
||||
has decided to code the Fulltext searching within the site for MyISAM due to its larger compatibility and ease of future troubleshooting. One major difference between MyISAM's and InnoDB's
|
||||
full text search implementation is the stop word table. MyISAM's (seen below) consists of 543 entries while InnoDB's consists of only 36. This leads to greatly disparate results when
|
||||
searching the same data between the two engines. If you prefer your results using InnoDB's default stop word table, then ignore this file. If you wish to keep your search in-line with the
|
||||
way it was coded simply import this file into MySQL. Using this import constitutes (in general) a major change to the entire MySQL instance as the change is Global to use the new stop word
|
||||
table. Because of this, it is recommended you import this table into the mysql database, NOT nzedb. Do this with the following command (using an account that has access to the mysql database):
|
||||
|
||||
mysql -uroot mysql < /var/www/nZEDb/resources/db/schema/innodb_5.6_stopword_tbl.sql
|
||||
|
||||
Once imported, it is recommended to set:
|
||||
|
||||
innodb_ft_server_stopword_table = mysql/INNODB_FT_MYISAM_STOPWORD
|
||||
|
||||
In your my.cnf and restart MySQL services. Using this file will fail in any instance where the MySQL version is not 5.6+ or the InnoDB plugin is not enabled. This will have no effect if you did
|
||||
not run an ALTER TABLE releasesearch ENGINE=InnoDB command. The DEFAULT CHARSET not being UTF-8 is not an error. It must be latin1 or MySQL will error when applying it as the stopword table.*/
|
||||
|
||||
/* BEGIN STOPWORD IMPORT */
|
||||
|
||||
DROP TABLE IF EXISTS INNODB_FT_MYISAM_STOPWORD;
|
||||
|
||||
CREATE TABLE INNODB_FT_MYISAM_STOPWORD (value VARCHAR(18) NOT NULL DEFAULT '') ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=latin1;
|
||||
|
||||
INSERT INTO INNODB_FT_MYISAM_STOPWORD (value) VALUES ('a\'s'), ('able'), ('about'), ('above'), ('according'), ('accordingly'), ('across'), ('actually'), ('after'), ('afterwards'), ('again'),
|
||||
('against'), ('ain\'t'), ('all'), ('allow'), ('allows'), ('almost'), ('alone'), ('along'), ('already'), ('also'), ('although'), ('always'), ('am'), ('among'), ('amongst'), ('an'), ('and'),
|
||||
('another'), ('any'), ('anybody'), ('anyhow'), ('anyone'), ('anything'), ('anyway'), ('anyways'), ('anywhere'), ('apart'), ('appear'), ('appreciate'), ('appropriate'), ('are'), ('aren\'t'),
|
||||
('around'), ('as'), ('aside'), ('ask'), ('asking'), ('associated'), ('at'), ('available'), ('away'), ('awfully'), ('be'), ('became'), ('because'), ('become'), ('becomes'), ('becoming'), ('been'),
|
||||
('before'), ('beforehand'), ('behind'), ('being'), ('believe'), ('below'), ('beside'), ('besides'), ('best'), ('better'), ('between'), ('beyond'), ('both'), ('brief'), ('but'), ('by'), ('c\'mon'),
|
||||
('c\'s'), ('came'), ('can'), ('can\'t'), ('cannot'), ('cant'), ('cause'), ('causes'), ('certain'), ('certainly'), ('changes'), ('clearly'), ('co'), ('com'), ('come'), ('comes'), ('concerning'),
|
||||
('consequently'), ('consider'), ('considering'), ('contain'), ('containing'), ('contains'), ('corresponding'), ('could'), ('couldn\'t'), ('course'), ('currently'), ('definitely'), ('described'),
|
||||
('despite'), ('did'), ('didn\'t'), ('different'), ('do'), ('does'), ('doesn\'t'), ('doing'), ('don\'t'), ('done'), ('down'), ('downwards'), ('during'), ('each'), ('edu'), ('eg'), ('eight'),
|
||||
('either'), ('else'), ('elsewhere'), ('enough'), ('entirely'), ('especially'), ('et'), ('etc'), ('even'), ('ever'), ('every'), ('everybody'), ('everyone'), ('everything'), ('everywhere'), ('ex'),
|
||||
('exactly'), ('example'), ('except'), ('far'), ('few'), ('fifth'), ('first'), ('five'), ('followed'), ('following'), ('follows'), ('for'), ('former'), ('formerly'), ('forth'), ('four'), ('from'),
|
||||
('further'), ('furthermore'), ('get'), ('gets'), ('getting'), ('given'), ('gives'), ('go'), ('goes'), ('going'), ('gone'), ('got'), ('gotten'), ('greetings'), ('had'), ('hadn\'t'), ('happens'),
|
||||
('hardly'), ('has'), ('hasn\'t'), ('have'), ('haven\'t'), ('having'), ('he'), ('he\'s'), ('hello'), ('help'), ('hence'), ('her'), ('here'), ('here\'s'), ('hereafter'), ('hereby'), ('herein'),
|
||||
('hereupon'), ('hers'), ('herself'), ('hi'), ('him'), ('himself'), ('his'), ('hither'), ('hopefully'), ('how'), ('howbeit'), ('however'), ('i\'d'), ('i\'ll'), ('i\'m'), ('i\'ve'), ('ie'), ('if'),
|
||||
('ignored'), ('immediate'), ('in'), ('inasmuch'), ('inc'), ('indeed'), ('indicate'), ('indicated'), ('indicates'), ('inner'), ('insofar'), ('instead'), ('into'), ('inward'), ('is'), ('isn\'t'), ('it'),
|
||||
('it\'d'), ('it\'ll'), ('it\'s'), ('its'), ('itself'), ('just'), ('keep'), ('keeps'), ('kept'), ('know'), ('known'), ('knows'), ('last'), ('lately'), ('later'), ('latter'), ('latterly'), ('least'),
|
||||
('less'), ('lest'), ('let'), ('let\'s'), ('like'), ('liked'), ('likely'), ('little'), ('look'), ('looking'), ('looks'), ('ltd'), ('mainly'), ('many'), ('may'), ('maybe'), ('me'), ('mean'), ('meanwhile'),
|
||||
('merely'), ('might'), ('more'), ('moreover'), ('most'), ('mostly'), ('much'), ('must'), ('my'), ('myself'), ('name'), ('namely'), ('nd'), ('near'), ('nearly'), ('necessary'), ('need'), ('needs'),
|
||||
('neither'), ('never'), ('nevertheless'), ('new'), ('next'), ('nine'), ('no'), ('nobody'), ('non'), ('none'), ('noone'), ('nor'), ('normally'), ('not'), ('nothing'), ('novel'), ('now'), ('nowhere'),
|
||||
('obviously'), ('of'), ('off'), ('often'), ('oh'), ('ok'), ('okay'), ('old'), ('on'), ('once'), ('one'), ('ones'), ('only'), ('onto'), ('or'), ('other'), ('others'), ('otherwise'), ('ought'), ('our'),
|
||||
('ours'), ('ourselves'), ('out'), ('outside'), ('over'), ('overall'), ('own'), ('particular'), ('particularly'), ('per'), ('perhaps'), ('placed'), ('please'), ('plus'), ('possible'), ('presumably'),
|
||||
('probably'), ('provides'), ('que'), ('quite'), ('qv'), ('rather'), ('rd'), ('re'), ('really'), ('reasonably'), ('regarding'), ('regardless'), ('regards'), ('relatively'), ('respectively'), ('right'),
|
||||
('said'), ('same'), ('saw'), ('say'), ('saying'), ('says'), ('second'), ('secondly'), ('see'), ('seeing'), ('seem'), ('seemed'), ('seeming'), ('seems'), ('seen'), ('self'), ('selves'), ('sensible'),
|
||||
('sent'), ('serious'), ('seriously'), ('seven'), ('several'), ('shall'), ('she'), ('should'), ('shouldn\'t'), ('since'), ('six'), ('so'), ('some'), ('somebody'), ('somehow'), ('someone'), ('something'),
|
||||
('sometime'), ('sometimes'), ('somewhat'), ('somewhere'), ('soon'), ('sorry'), ('specified'), ('specify'), ('specifying'), ('still'), ('sub'), ('such'), ('sup'), ('sure'), ('t\'s'), ('take'), ('taken'),
|
||||
('tell'), ('tends'), ('th'), ('than'), ('thank'), ('thanks'), ('thanx'), ('that'), ('that\'s'), ('thats'), ('the'), ('their'), ('theirs'), ('them'), ('themselves'), ('then'), ('thence'), ('there'),
|
||||
('there\'s'), ('thereafter'), ('thereby'), ('therefore'), ('therein'), ('theres'), ('thereupon'), ('these'), ('they'), ('they\'d'), ('they\'ll'), ('they\'re'), ('they\'ve'), ('think'), ('third'),
|
||||
('this'), ('thorough'), ('thoroughly'), ('those'), ('though'), ('three'), ('through'), ('throughout'), ('thru'), ('thus'), ('to'), ('together'), ('too'), ('took'), ('toward'), ('towards'), ('tried'),
|
||||
('tries'), ('truly'), ('try'), ('trying'), ('twice'), ('two'), ('un'), ('under'), ('unfortunately'), ('unless'), ('unlikely'), ('until'), ('unto'), ('up'), ('upon'), ('us'), ('use'), ('used'), ('useful'),
|
||||
('uses'), ('using'), ('usually'), ('value'), ('various'), ('very'), ('via'), ('viz'), ('vs'), ('want'), ('wants'), ('was'), ('wasn\'t'), ('way'), ('we'), ('we\'d'), ('we\'ll'), ('we\'re'), ('we\'ve'),
|
||||
('welcome'), ('well'), ('went'), ('were'), ('weren\'t'), ('what'), ('what\'s'), ('whatever'), ('when'), ('whence'), ('whenever'), ('where'), ('where\'s'), ('whereafter'), ('whereas'), ('whereby'), ('wherein'),
|
||||
('whereupon'), ('wherever'), ('whether'), ('which'), ('while'), ('whither'), ('who'), ('who\'s'), ('whoever'), ('whole'), ('whom'), ('whose'), ('why'), ('will'), ('willing'), ('wish'), ('with'), ('within'),
|
||||
('without'), ('won\'t'), ('wonder'), ('would'), ('wouldn\'t'), ('yes'), ('yet'), ('you'), ('you\'d'), ('you\'ll'), ('you\'re'), ('you\'ve'), ('your'), ('yours'), ('yourself'), ('yourselves'), ('zero');
|
||||
|
||||
/* END STOPWORD IMPORT */
|
||||
+73
-183
@@ -16,10 +16,9 @@ namespace tests;
|
||||
require_once \dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'bootstrap/autoload.php';
|
||||
|
||||
use App\Extensions\util\Versions;
|
||||
use App\Models\Settings;
|
||||
use App\Models\User;
|
||||
use nntmux\config\Configure;
|
||||
use nntmux\db\DB;
|
||||
use nntmux\db\DbUpdate;
|
||||
use nntmux\ColorCLI;
|
||||
|
||||
/**
|
||||
@@ -37,203 +36,94 @@ class InstallTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
public function testFullInstall()
|
||||
{
|
||||
if (! \defined('NN_INSTALLER')) {
|
||||
\define('NN_INSTALLER', true);
|
||||
}
|
||||
if (! \defined('NN_INSTALLER')) {
|
||||
\define('NN_INSTALLER', true);
|
||||
}
|
||||
|
||||
$this->config = new Configure('install');
|
||||
$error = false;
|
||||
|
||||
$pdo = new DB();
|
||||
$error = false;
|
||||
// Connect to the SQL server.
|
||||
try {
|
||||
// HAS to be DB because settings table does not exist yet.
|
||||
$pdo = new DB(
|
||||
[
|
||||
'checkVersion' => true,
|
||||
'createDb' => true,
|
||||
'dbhost' => env('DB_HOST'),
|
||||
'dbname' => env('DB_NAME'),
|
||||
'dbpass' => env('DB_PASSWORD'),
|
||||
'dbport' => env('DB_PORT'),
|
||||
'dbsock' => env('DB_SOCKET'),
|
||||
'dbtype' => env('DB_SYSTEM'),
|
||||
'dbuser' => env('DB_USER'),
|
||||
]
|
||||
);
|
||||
} catch (\PDOException $e) {
|
||||
ColorCLI::doEcho(ColorCLI::error('Unable to connect to MySQL server.'));
|
||||
$error = true;
|
||||
} catch (\RuntimeException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
$error = true;
|
||||
ColorCLI::doEcho(ColorCLI::alternate($e->getMessage()));
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
passthru('php '.NN_ROOT.'artisan migrate:fresh --seed');
|
||||
|
||||
// Check if the MySQL version is correct.
|
||||
if (!$error) {
|
||||
try {
|
||||
$goodVersion = $pdo->isDbVersionAtLeast(NN_MINIMUM_MYSQL_VERSION);
|
||||
} catch (\PDOException $e) {
|
||||
$goodVersion = false;
|
||||
$error = true;
|
||||
ColorCLI::doEcho(ColorCLI::error('Could not get version from MySQL server.'));
|
||||
}
|
||||
// Check one of the standard tables was created and has data.
|
||||
$ver = new Versions();
|
||||
$patch = $ver->getSQLPatchFromFile();
|
||||
$updateSettings = false;
|
||||
if ($patch > 0) {
|
||||
$updateSettings = Settings::query()->where(['section' => '', 'subsection' => '', 'name' => 'sqlpatch'])->update(['value' => $patch]);
|
||||
}
|
||||
// If it all worked, continue the install process.
|
||||
if ($updateSettings === 0) {
|
||||
$message = 'Database updated successfully';
|
||||
} else {
|
||||
$error = true;
|
||||
$message = 'Could not update sqlpatch to '.$patch.' for your database.';
|
||||
}
|
||||
|
||||
if ($goodVersion === false) {
|
||||
$error = true;
|
||||
ColorCLI::doEcho(ColorCLI::error(
|
||||
'You are using an unsupported version of ' .
|
||||
env('DB_SYSTEM') .
|
||||
' the minimum allowed version is ' .
|
||||
NN_MINIMUM_MYSQL_VERSION
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (! $error) {
|
||||
|
||||
// Start inserting data into the DB.
|
||||
if (!$error) {
|
||||
$DbSetup = new DbUpdate(
|
||||
[
|
||||
'backup' => false,
|
||||
'db' => $pdo,
|
||||
]
|
||||
);
|
||||
$pdo->exec('SET FOREIGN_KEY_CHECKS=0;');
|
||||
$covers_path = NN_RES.'covers'.DS;
|
||||
$nzb_path = NN_RES.'nzb'.DS;
|
||||
$tmp_path = NN_RES.'tmp'.DS;
|
||||
$unrar_path = $tmp_path.'unrar'.DS;
|
||||
|
||||
$DbSetup->processSQLFile(); // Setup default schema
|
||||
//Insert admin user into database
|
||||
if (env('ADMIN_USER') === '' || env('ADMIN_PASS') === '' || env('ADMIN_EMAIL') === '') {
|
||||
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();
|
||||
$nzbPathCheck = is_writable($nzb_path);
|
||||
if ($nzbPathCheck === false) {
|
||||
$error = true;
|
||||
$message = $nzb_path.' is not writable. Please fix folder permissions';
|
||||
}
|
||||
$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.
|
||||
$dbInstallWorked = false;
|
||||
$reschk = $pdo->query('SELECT COUNT(id) AS num FROM tmux');
|
||||
if ($reschk === false) {
|
||||
$error = true;
|
||||
ColorCLI::doEcho(ColorCLI::warningOver('Could not select data from your database, check that tables and data are properly created/inserted.'));
|
||||
} else {
|
||||
foreach ($reschk as $row) {
|
||||
if ($row['num'] > 0) {
|
||||
$dbInstallWorked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$ver = new Versions();
|
||||
$patch = $ver->getSQLPatchFromFile();
|
||||
if ($dbInstallWorked) {
|
||||
$updateSettings = false;
|
||||
if ($patch > 0) {
|
||||
$updateSettings = $pdo->queryExec(
|
||||
"UPDATE settings SET value = '$patch' WHERE section = '' AND subsection = '' AND name = 'sqlpatch'"
|
||||
);
|
||||
}
|
||||
// If it all worked, continue the install process.
|
||||
if ($updateSettings) {
|
||||
$message = 'Database updated successfully';
|
||||
echo $message . PHP_EOL;
|
||||
} else {
|
||||
$error = true;
|
||||
$message = 'Could not update sqlpatch to ' . $patch . ' for your database.';
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$error = true;
|
||||
ColorCLI::doEcho(ColorCLI::warning('Could not select data from your database.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
$lastchar = substr($nzb_path, \strlen($nzb_path) - 1);
|
||||
if ($lastchar !== '/') {
|
||||
$nzb_path .= '/';
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$covers_path = NN_RES . 'covers' . DS;
|
||||
$nzb_path = NN_RES . 'nzb' . DS;
|
||||
$tmp_path = NN_RES . 'tmp' . DS;
|
||||
$unrar_path = $tmp_path . 'unrar' . DS;
|
||||
if (! file_exists($unrar_path)) {
|
||||
if (! @mkdir($unrar_path) && ! is_dir($unrar_path)) {
|
||||
throw new \RuntimeException('Unable to create '.$unrar_path.' folder');
|
||||
}
|
||||
}
|
||||
$unrarPathCheck = is_writable($unrar_path);
|
||||
if ($unrarPathCheck === false) {
|
||||
$error = true;
|
||||
$message = $unrar_path.' is not writable. Please fix folder permissions';
|
||||
}
|
||||
|
||||
$lastchar = substr($unrar_path, \strlen($unrar_path) - 1);
|
||||
if ($lastchar !== '/') {
|
||||
$unrar_path .= '/';
|
||||
}
|
||||
|
||||
$nzbPathCheck = is_writable($nzb_path);
|
||||
if ($nzbPathCheck === false) {
|
||||
$error = true;
|
||||
$message = $nzb_path . ' is not writable. Please fix folder permissions';
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
$coversPathCheck = is_writable($covers_path);
|
||||
if ($coversPathCheck === false) {
|
||||
$error = true;
|
||||
$message = $covers_path.' is not writable. Please fix folder permissions';
|
||||
}
|
||||
|
||||
$lastchar = substr($nzb_path, \strlen($nzb_path) - 1);
|
||||
if ($lastchar !== '/') {
|
||||
$nzb_path .= '/';
|
||||
}
|
||||
$lastchar = substr($covers_path, \strlen($covers_path) - 1);
|
||||
if ($lastchar !== '/') {
|
||||
$covers_path .= '/';
|
||||
}
|
||||
|
||||
if (!file_exists($unrar_path)) {
|
||||
ColorCLI::doEcho(ColorCLI::primary('Creating missing ' . $unrar_path . ' folder'));
|
||||
if (!@mkdir($unrar_path) && !is_dir($unrar_path)) {
|
||||
throw new \RuntimeException('Unable to create ' . $unrar_path . ' folder');
|
||||
}
|
||||
$message = 'Folder ' . $unrar_path . ' successfully created';
|
||||
echo $message;
|
||||
}
|
||||
$unrarPathCheck = is_writable($unrar_path);
|
||||
if ($unrarPathCheck === false) {
|
||||
$error = true;
|
||||
$message = $unrar_path . ' is not writable. Please fix folder permissions';
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
if (! $error) {
|
||||
$sql1 = Settings::query()->where('setting', '=', 'nzbpath')->update(['value' => $nzb_path]);
|
||||
$sql2 = Settings::query()->where('setting', '=', 'tmpunrarpath')->update(['value' => $unrar_path]);
|
||||
$sql3 = Settings::query()->where('setting', '=', 'coverspath')->update(['value' => $covers_path]);
|
||||
if ($sql1 === null || $sql2 === null || $sql3 === null) {
|
||||
$error = true;
|
||||
} else {
|
||||
$message = 'Settings table updated successfully';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$lastchar = substr($unrar_path, \strlen($unrar_path) - 1);
|
||||
if ($lastchar !== '/') {
|
||||
$unrar_path .= '/';
|
||||
}
|
||||
if (! $error) {
|
||||
|
||||
$coversPathCheck = is_writable($covers_path);
|
||||
if ($coversPathCheck === false) {
|
||||
$error = true;
|
||||
$message = $covers_path . ' is not writable. Please fix folder permissions';
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
User::add(env('ADMIN_USER'), env('ADMIN_PASS'), env('ADMIN_EMAIL'), 2, '', '', '', '');
|
||||
|
||||
$lastchar = substr($covers_path, \strlen($covers_path) - 1);
|
||||
if ($lastchar !== '/') {
|
||||
$covers_path .= '/';
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
|
||||
$sql1 = sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbpath'", $pdo->escapeString($nzb_path));
|
||||
$sql2 = sprintf("UPDATE settings SET value = %s WHERE setting = 'tmpunrarpath'", $pdo->escapeString($unrar_path));
|
||||
$sql3 = sprintf("UPDATE settings SET value = %s WHERE setting = 'coverspath'", $pdo->escapeString($covers_path));
|
||||
if ($pdo->queryExec($sql1) === false || $pdo->queryExec($sql2) === false || $pdo->queryExec($sql3) === false) {
|
||||
$error = true;
|
||||
} else {
|
||||
$message = 'Settings table updated successfully';
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
@file_put_contents(NN_ROOT . '_install/install.lock', '');
|
||||
$message = 'NNTmux installation completed successfully';
|
||||
$pdo->exec('SET FOREIGN_KEY_CHECKS=1;');
|
||||
echo $message . PHP_EOL;
|
||||
} else {
|
||||
$message = 'NNTmux installation failed. Please fix reported problems and run this script again';
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
@file_put_contents(NN_ROOT.'_install/install.lock', '');
|
||||
passthru('php '.NN_ROOT.'artisan key:generate');
|
||||
$message = 'NNTmux installation completed successfully';
|
||||
}
|
||||
$this->assertEquals('NNTmux installation completed successfully', $message, 'Test Failed');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user