From 19f0aab3221dd7760387cbec745c1eca9b215af7 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 9 Sep 2017 16:08:00 +0200 Subject: WIP: CI3 migration Signed-off-by: Florian Pritz --- application/controllers/Tools.php | 130 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 application/controllers/Tools.php (limited to 'application/controllers/Tools.php') diff --git a/application/controllers/Tools.php b/application/controllers/Tools.php new file mode 100644 index 000000000..9e0ddfb5f --- /dev/null +++ b/application/controllers/Tools.php @@ -0,0 +1,130 @@ + + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +class Tools extends MY_Controller { + + function __construct() + { + parent::__construct(); + + $this->load->model('mfile'); + $this->_require_cli_request(); + } + + function index() + { + echo "php index.php [arguments]\n"; + echo "\n"; + echo "Functions:\n"; + echo " file cron Cronjob\n"; + echo " file nuke_id Nukes all IDs sharing the same hash\n"; + echo " user cron Cronjob\n"; + echo " tools update_database Update/Initialise the database\n"; + echo "\n"; + echo "Functions that shouldn't have to be run:\n"; + echo " file clean_stale_files Remove files without database entries\n"; + echo " file update_file_metadata Update filesize and mimetype in database\n"; + exit; + } + + function update_database() + { + $this->load->library('migration'); + $upgraded = $this->migration->current(); + if ( ! $upgraded) { + throw new \exceptions\ApiException("tools/update_database/migration-error", $this->migration->error_string()); + } + + if ($upgraded === true) { + echo "Already at latest database version. No upgrade performed\n"; + } + + if (is_int($upgraded)) { + echo "Database upgraded sucessfully to version: $upgraded\n"; + } + } + + function drop_all_tables() + { + $tables = $this->db->list_tables(); + $prefix = $this->db->dbprefix; + $tables_to_drop = array(); + + foreach ($tables as $table) { + if ($prefix === "" || strpos($table, $prefix) === 0) { + $tables_to_drop[] = $this->db->protect_identifiers($table); + } + } + + if (empty($tables_to_drop)) { + return; + } + + + if ($this->db->dbdriver !== 'postgre') { + $this->db->query('SET FOREIGN_KEY_CHECKS = 0'); + } + $this->db->query('DROP TABLE '.implode(", ", $tables_to_drop)); + if ($this->db->dbdriver !== 'postgre') { + $this->db->query('SET FOREIGN_KEY_CHECKS = 1'); + } + } + + function test() + { + global $argv; + $testcase = $argv[3]; + + $testcase = str_replace("application/", "", $testcase); + $testcase = str_replace("/", "\\", $testcase); + $testcase = str_replace(".php", "", $testcase); + + $test = new $testcase(); + + $exitcode = 0; + + $refl = new ReflectionClass($test); + foreach ($refl->getMethods() as $method) { + if (strpos($method->name, "test_") === 0) { + try { + $test->setTestNamePrefix($method->name." - "); + $test->init(); + $test->setTestID("{$testcase}->{$method->name}"); + $test->{$method->name}(); + $test->cleanup(); + } catch (\Exception $e) { + echo "not ok - uncaught exception in {$testcase}->{$method->name}\n"; + \libraries\ExceptionHandler::exception_handler($e); + $exitcode = 255; + } + } + } + + if ($exitcode == 0) { + $test->done_testing(); + } else { + exit($exitcode); + } + } + + function generate_coverage_report() + { + include APPPATH."../vendor/autoload.php"; + $coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage(); + foreach (glob(FCPATH."/test-coverage-data/*") as $file) { + $coverage->merge(unserialize(file_get_contents($file))); + } + + $writer = new \SebastianBergmann\CodeCoverage\Report\Clover(); + $writer->process($coverage, 'code-coverage-report.xml'); + $writer = new \SebastianBergmann\CodeCoverage\Report\Html\Facade(); + $writer->process($coverage, 'code-coverage-report'); + print "Report saved to ./code-coverage-report/index.html\n"; + } +} -- cgit v1.2.3-24-g4f1b From 6be5f77331a82d0154f1ed82b07b64917c2a102d Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 18 Sep 2017 12:14:27 +0200 Subject: Remove secondary controller for CLI usage output Signed-off-by: Florian Pritz --- application/controllers/Tools.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'application/controllers/Tools.php') diff --git a/application/controllers/Tools.php b/application/controllers/Tools.php index 9e0ddfb5f..bb481db80 100644 --- a/application/controllers/Tools.php +++ b/application/controllers/Tools.php @@ -19,17 +19,7 @@ class Tools extends MY_Controller { function index() { - echo "php index.php [arguments]\n"; - echo "\n"; - echo "Functions:\n"; - echo " file cron Cronjob\n"; - echo " file nuke_id Nukes all IDs sharing the same hash\n"; - echo " user cron Cronjob\n"; - echo " tools update_database Update/Initialise the database\n"; - echo "\n"; - echo "Functions that shouldn't have to be run:\n"; - echo " file clean_stale_files Remove files without database entries\n"; - echo " file update_file_metadata Update filesize and mimetype in database\n"; + output_cli_usage(); exit; } -- cgit v1.2.3-24-g4f1b