diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-02-15 11:11:49 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-02-15 11:11:49 +0100 |
commit | 45c16c802720faf9de6c3028ba41753c5edba974 (patch) | |
tree | e20148091cf0f9b6ff11efe65a76cfe1d1bad24c /application/controllers/tools.php | |
parent | 9535ede862e01d834ebdd553184b1f6544b06d2c (diff) | |
parent | 01226a9afd760a920e9cb3377913ee296f0ab2ca (diff) |
Merge branch 'api-rework' into working
Diffstat (limited to 'application/controllers/tools.php')
-rw-r--r-- | application/controllers/tools.php | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/application/controllers/tools.php b/application/controllers/tools.php index b80dc5024..e36b09b79 100644 --- a/application/controllers/tools.php +++ b/application/controllers/tools.php @@ -15,7 +15,7 @@ class Tools extends MY_Controller { $this->load->model('mfile'); if (!$this->input->is_cli_request()) { - show_error("This can only be called via CLI"); + throw new \exceptions\ApiException("api/cli-only", "This can only be called via CLI"); } } @@ -39,7 +39,48 @@ class Tools extends MY_Controller { { $this->load->library('migration'); if ( ! $this->migration->current()) { - show_error($this->migration->error_string()); + throw new \exceptions\ApiException("tools/update_database/migration-error", $this->migration->error_string()); + } + } + + function drop_all_tables_using_prefix() + { + $tables = $this->db->list_tables(); + $prefix = $this->db->dbprefix; + $tables_to_drop = array(); + + foreach ($tables as $table) { + if (strpos($table, $prefix) === 0) { + $tables_to_drop[] = $this->db->protect_identifiers($table); + } + } + + if (empty($tables_to_drop)) { + return; + } + + $this->db->query('SET FOREIGN_KEY_CHECKS = 0'); + $this->db->query('DROP TABLE '.implode(", ", $tables_to_drop)); + $this->db->query('SET FOREIGN_KEY_CHECKS = 1'); + } + + function test() + { + global $argv; + $url = $argv[3]; + $testcase = $argv[4]; + + $testclass = '\tests\\'.$testcase; + $test = new $testclass(); + $test->setServer($url); + + $refl = new ReflectionClass($test); + foreach ($refl->getMethods() as $method) { + if (strpos($method->name, "test_") === 0) { + $test->init(); + $test->{$method->name}(); + $test->cleanup(); + } } } } |