summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-09-27 19:34:04 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-11-01 17:29:04 +0100
commit588cb99b96f90a0893a313812a0e49e92027fede (patch)
tree7205f78a20401fb8cdc51483f54fc9ec92475eb4
parent65477e2f2551b087d65e2cb807a5728cd1672f03 (diff)
c/MY_Controller: Extract database migration code into method
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/core/MY_Controller.php34
1 files changed, 20 insertions, 14 deletions
diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php
index ba31f4e29..cbb95aa33 100644
--- a/application/core/MY_Controller.php
+++ b/application/core/MY_Controller.php
@@ -22,20 +22,7 @@ class MY_Controller extends CI_Controller {
// check if DB is up to date
if (!($this->input->is_cli_request() && $this->uri->segment(1) === "tools")) {
- if (!$this->db->table_exists('migrations')){
- throw new \exceptions\PublicApiException("general/db/not-initialized", "Database not initialized. Can't find migrations table. Please run the migration script. (php index.php tools update_database)");
- } else {
- $this->config->load("migration", true);
- $target_version = $this->config->item("migration_version", "migration");
-
- // TODO: wait 20 seconds for an update so requests don't get lost for short updates?
- $row = $this->db->get('migrations')->row();
-
- $current_version = $row ? $row->version : 0;
- if ($current_version != $target_version) {
- throw new \exceptions\PublicApiException("general/db/wrong-version", "Database version is $current_version, we want $target_version. Please run the migration script. (php index.php tools update_database)");
- }
- }
+ $this->_ensure_database_schema_up_to_date();
}
$old_path = getenv("PATH");
@@ -102,4 +89,23 @@ class MY_Controller extends CI_Controller {
throw new \exceptions\PublicApiException("api/cli-only", "This function can only be accessed via the CLI interface");
}
}
+
+ private function _ensure_database_schema_up_to_date()
+ {
+ if (!$this->db->table_exists('migrations')){
+ throw new \exceptions\PublicApiException("general/db/not-initialized", "Database not initialized. Can't find migrations table. Please run the migration script. (php index.php tools update_database)");
+ } else {
+ $this->config->load("migration", true);
+ $target_version = $this->config->item("migration_version", "migration");
+
+ // TODO: wait 20 seconds for an update so requests don't get lost for short updates?
+ $row = $this->db->get('migrations')->row();
+
+ $current_version = $row ? $row->version : 0;
+ if ($current_version != $target_version) {
+ throw new \exceptions\PublicApiException("general/db/wrong-version", "Database version is $current_version, we want $target_version. Please run the migration script. (php index.php tools update_database)");
+ }
+ }
+ }
+
}