From dae42fa65fc65e43d704f1a6c139e985e93486f4 Mon Sep 17 00:00:00 2001 From: bubbafoley Date: Sun, 28 Aug 2011 00:54:24 -0500 Subject: Fix the default migration path. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3943ec130..3734e18f5 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -57,7 +57,7 @@ class CI_Migration { } // If not set, set it - $this->_migration_path == '' OR $this->_migration_path = APPPATH . 'migrations/'; + $this->_migration_path == '' AND $this->_migration_path = APPPATH . 'migrations/'; // Add trailing slash if not set $this->_migration_path = rtrim($this->_migration_path, '/').'/'; -- cgit v1.2.3-24-g4f1b From 539dcb0b2968a2d83c16b42a20252011152f2e65 Mon Sep 17 00:00:00 2001 From: "Cloudmanic Labs, LLC" Date: Sun, 18 Sep 2011 12:08:56 -0700 Subject: Added support to select the name of the database table you are going to use in Migrations --- system/libraries/Migration.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3734e18f5..682d90752 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -32,7 +32,8 @@ class CI_Migration { protected $_migration_enabled = FALSE; protected $_migration_path = NULL; protected $_migration_version = 0; - + protected $_migration_table = 'migrations'; + protected $_error_string = ''; public function __construct($config = array()) @@ -68,16 +69,22 @@ class CI_Migration { // They'll probably be using dbforge $this->load->dbforge(); + // Make sure the migration table name was set. + if ( (! isset($this->_migration_table)) OR (empty($this->_migration_table))) + { + show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); + } + // If the migrations table is missing, make it - if ( ! $this->db->table_exists('migrations')) + if ( ! $this->db->table_exists($this->_migration_table)) { $this->dbforge->add_field(array( 'version' => array('type' => 'INT', 'constraint' => 3), )); - $this->dbforge->create_table('migrations', TRUE); + $this->dbforge->create_table($this->_migration_table, TRUE); - $this->db->insert('migrations', array('version' => 0)); + $this->db->insert($this->_migration_table, array('version' => 0)); } } @@ -299,7 +306,7 @@ class CI_Migration { */ protected function _get_version() { - $row = $this->db->get('migrations')->row(); + $row = $this->db->get($this->_migration_table)->row(); return $row ? $row->version : 0; } @@ -314,7 +321,7 @@ class CI_Migration { */ protected function _update_version($migrations) { - return $this->db->update('migrations', array( + return $this->db->update($this->_migration_table, array( 'version' => $migrations )); } -- cgit v1.2.3-24-g4f1b From d1ba8f790eb91deb2898ff19d7827ce86e40ee7c Mon Sep 17 00:00:00 2001 From: "Cloudmanic Labs, LLC" Date: Sun, 18 Sep 2011 12:23:00 -0700 Subject: Migrations: Added a config that allows the system to migration to the latest migration when you load the library. This way you do not have to call migrations anywhere else in your code and can always be at the latest migration --- system/libraries/Migration.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 682d90752..28b1dd69f 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -33,6 +33,7 @@ class CI_Migration { protected $_migration_path = NULL; protected $_migration_version = 0; protected $_migration_table = 'migrations'; + protected $_migration_auto_latest = FALSE; protected $_error_string = ''; @@ -86,6 +87,15 @@ class CI_Migration { $this->db->insert($this->_migration_table, array('version' => 0)); } + + // Do we auto migrate to the latest migration? + if ( $this->_migration_auto_latest == TRUE ) + { + if ( ! $this->latest() ) + { + show_error($this->error_string()); + } + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 63b61e3bedd2a5729bef15b79ea64fa0a9d54893 Mon Sep 17 00:00:00 2001 From: "Cloudmanic Labs, LLC" Date: Mon, 19 Sep 2011 09:35:05 -0700 Subject: Fixed style guide suggestion from philsturgeon on code review --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 28b1dd69f..840cefe08 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -71,7 +71,7 @@ class CI_Migration { $this->load->dbforge(); // Make sure the migration table name was set. - if ( (! isset($this->_migration_table)) OR (empty($this->_migration_table))) + if (empty($this->_migration_table)) { show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); } -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Migration.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 840cefe08..b7edf7195 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -1,15 +1,27 @@ - Date: Fri, 11 Nov 2011 22:46:21 -0800 Subject: Fixed small typeo --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index b7edf7195..233a901e4 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -252,7 +252,7 @@ class CI_Migration { { if ( ! $migrations = $this->find_migrations()) { - $this->_error_string = $this->line->lang('migration_none_found'); + $this->_error_string = $this->lang->line('migration_none_found'); return false; } -- cgit v1.2.3-24-g4f1b From dd81c435c145792e79e17f5a51f5c036adbc8044 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Wed, 16 Nov 2011 11:07:35 -0500 Subject: Migrations - Changed config migration_version to state it is used in migration->current. Removed white space and coding standards. --- system/libraries/Migration.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 233a901e4..94961b568 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -5,9 +5,9 @@ * An open source application development framework for PHP 5.1.6 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -46,7 +46,7 @@ class CI_Migration { protected $_migration_version = 0; protected $_migration_table = 'migrations'; protected $_migration_auto_latest = FALSE; - + protected $_error_string = ''; public function __construct($config = array()) @@ -71,7 +71,7 @@ class CI_Migration { } // If not set, set it - $this->_migration_path == '' AND $this->_migration_path = APPPATH . 'migrations/'; + $this->_migration_path == '' AND $this->_migration_path = APPPATH.'migrations/'; // Add trailing slash if not set $this->_migration_path = rtrim($this->_migration_path, '/').'/'; @@ -85,7 +85,7 @@ class CI_Migration { // Make sure the migration table name was set. if (empty($this->_migration_table)) { - show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); + show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); } // If the migrations table is missing, make it @@ -99,9 +99,9 @@ class CI_Migration { $this->db->insert($this->_migration_table, array('version' => 0)); } - + // Do we auto migrate to the latest migration? - if ( $this->_migration_auto_latest == TRUE ) + if ($this->_migration_auto_latest == TRUE) { if ( ! $this->latest() ) { @@ -140,7 +140,7 @@ class CI_Migration { // Moving Down $step = -1; } - + $method = $step === 1 ? 'up' : 'down'; $migrations = array(); @@ -148,7 +148,7 @@ class CI_Migration { // But first let's make sure that everything is the way it should be for ($i = $start; $i != $stop; $i += $step) { - $f = glob(sprintf($this->_migration_path . '%03d_*.php', $i)); + $f = glob(sprintf($this->_migration_path.'%03d_*.php', $i)); // Only one migration per step is permitted if (count($f) > 1) @@ -189,7 +189,7 @@ class CI_Migration { } include $f[0]; - $class = 'Migration_' . ucfirst($match[1]); + $class = 'Migration_'.ucfirst($match[1]); if ( ! class_exists($class)) { @@ -212,7 +212,7 @@ class CI_Migration { } } - log_message('debug', 'Current migration: ' . $current_version); + log_message('debug', 'Current migration: '.$current_version); $version = $i + ($step == 1 ? -1 : 0); @@ -222,13 +222,13 @@ class CI_Migration { return TRUE; } - log_message('debug', 'Migrating from ' . $method . ' to version ' . $version); + log_message('debug', 'Migrating from '.$method.' to version '.$version); // Loop through the migrations foreach ($migrations AS $migration) { // Run the migration class - $class = 'Migration_' . ucfirst(strtolower($migration)); + $class = 'Migration_'.ucfirst(strtolower($migration)); call_user_func(array(new $class, $method)); $current_version += $step; @@ -257,7 +257,7 @@ class CI_Migration { } $last_migration = basename(end($migrations)); - + // Calculate the last migration step from existing migration // filenames and procceed to the standard version migration return $this->version((int) substr($last_migration, 0, 3)); @@ -300,9 +300,9 @@ class CI_Migration { protected function find_migrations() { // Load all *_*.php files in the migrations path - $files = glob($this->_migration_path . '*_*.php'); + $files = glob($this->_migration_path.'*_*.php'); $file_count = count($files); - + for ($i = 0; $i < $file_count; $i++) { // Mark wrongly formatted files as false for later filtering @@ -312,7 +312,7 @@ class CI_Migration { $files[$i] = FALSE; } } - + sort($files); return $files; -- cgit v1.2.3-24-g4f1b From dd4702f39c363f1cb9d47fe642001a27963e405a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 24 Dec 2011 19:33:44 +0200 Subject: Improve the Migration library --- system/libraries/Migration.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 94961b568..eb5161d76 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -1,4 +1,4 @@ -_migration_auto_latest == TRUE) + if ($this->_migration_auto_latest === TRUE AND ! $this->latest()) { - if ( ! $this->latest() ) - { - show_error($this->error_string()); - } + show_error($this->error_string()); } } @@ -134,7 +131,6 @@ class CI_Migration { ++$stop; $step = 1; } - else { // Moving Down @@ -158,11 +154,11 @@ class CI_Migration { } // Migration step not found - if (count($f) == 0) + if (count($f) === 0) { // If trying to migrate up to a version greater than the last // existing one, migrate to the last one. - if ($step == 1) + if ($step === 1) { break; } @@ -214,7 +210,7 @@ class CI_Migration { log_message('debug', 'Current migration: '.$current_version); - $version = $i + ($step == 1 ? -1 : 0); + $version = $i + ($step === 1 ? -1 : 0); // If there is nothing to do so quit if ($migrations === array()) @@ -301,13 +297,11 @@ class CI_Migration { { // Load all *_*.php files in the migrations path $files = glob($this->_migration_path.'*_*.php'); - $file_count = count($files); - for ($i = 0; $i < $file_count; $i++) + for ($i = 0, $c = count($files); $i < $c; $i++) { // Mark wrongly formatted files as false for later filtering - $name = basename($files[$i], '.php'); - if ( ! preg_match('/^\d{3}_(\w+)$/', $name)) + if ( ! preg_match('/^\d{3}_(\w+)$/', basename($files[$i], '.php'))) { $files[$i] = FALSE; } @@ -364,4 +358,4 @@ class CI_Migration { } /* End of file Migration.php */ -/* Location: ./system/libraries/Migration.php */ \ No newline at end of file +/* Location: ./system/libraries/Migration.php */ -- cgit v1.2.3-24-g4f1b From d268eda6c2b502cc7fa352072482d1924e36127e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 31 Dec 2011 16:20:11 +0000 Subject: Added SELECT version to migrations to make the query a billionth faster. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index eb5161d76..f89391c0d 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -322,7 +322,7 @@ class CI_Migration { */ protected function _get_version() { - $row = $this->db->get($this->_migration_table)->row(); + $row = $this->db->select('version')->get($this->_migration_table)->row(); return $row ? $row->version : 0; } -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index f89391c0d..d07097223 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index d07097223..c045ac0e2 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 9b1db799ded4316d946ff0e27a6177d6688f7e78 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 19:45:51 +0300 Subject: Remove access description lines and cleanup the Migration library --- system/libraries/Migration.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index c045ac0e2..a18fcb9f1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Migration Class * @@ -71,7 +69,7 @@ class CI_Migration { } // If not set, set it - $this->_migration_path == '' AND $this->_migration_path = APPPATH.'migrations/'; + $this->_migration_path != '' OR $this->_migration_path = APPPATH.'migrations/'; // Add trailing slash if not set $this->_migration_path = rtrim($this->_migration_path, '/').'/'; @@ -101,7 +99,7 @@ class CI_Migration { } // Do we auto migrate to the latest migration? - if ($this->_migration_auto_latest === TRUE AND ! $this->latest()) + if ($this->_migration_auto_latest === TRUE && ! $this->latest()) { show_error($this->error_string()); } @@ -115,8 +113,7 @@ class CI_Migration { * Calls each migration step required to get to the schema version of * choice * - * @access public - * @param $version integer Target schema version + * @param int Target schema version * @return mixed TRUE if already latest, FALSE if failed, int if upgraded */ public function version($target_version) @@ -241,7 +238,6 @@ class CI_Migration { /** * Set's the schema to the latest migration * - * @access public * @return mixed true if already latest, false if failed, int if upgraded */ public function latest() @@ -264,7 +260,6 @@ class CI_Migration { /** * Set's the schema to the migration version set in config * - * @access public * @return mixed true if already current, false if failed, int if upgraded */ public function current() @@ -277,7 +272,6 @@ class CI_Migration { /** * Error string * - * @access public * @return string Error message returned as a string */ public function error_string() @@ -290,7 +284,6 @@ class CI_Migration { /** * Set's the schema to the latest migration * - * @access protected * @return mixed true if already latest, false if failed, int if upgraded */ protected function find_migrations() @@ -317,8 +310,7 @@ class CI_Migration { /** * Retrieves current schema version * - * @access protected - * @return integer Current Migration + * @return int Current Migration */ protected function _get_version() { @@ -331,9 +323,8 @@ class CI_Migration { /** * Stores the current schema version * - * @access protected - * @param $migrations integer Migration reached - * @return void Outputs a report of the migration + * @param int Migration reached + * @return void Outputs a report of the migration */ protected function _update_version($migrations) { @@ -347,8 +338,7 @@ class CI_Migration { /** * Enable the use of CI super-global * - * @access public - * @param $var + * @param $var * @return mixed */ public function __get($var) @@ -358,4 +348,4 @@ class CI_Migration { } /* End of file Migration.php */ -/* Location: ./system/libraries/Migration.php */ +/* Location: ./system/libraries/Migration.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 86611db279c17cf9b3d6ad8732a1c840cb833148 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 10:06:25 -0400 Subject: Fixed Cart, Migration, Parser and Zip libraries --- system/libraries/Migration.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index a18fcb9f1..ce4683fc1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -39,14 +39,53 @@ */ class CI_Migration { + /** + * Whether the library is enabled + * + * @var bool + */ protected $_migration_enabled = FALSE; + + /** + * Path to migration classes + * + * @var string + */ protected $_migration_path = NULL; + + /** + * Current migration version + * + * @var mixed + */ protected $_migration_version = 0; + + /** + * Database table with migration info + * + * @var string + */ protected $_migration_table = 'migrations'; + + /** + * Whether to automatically run migrations + * + * @var bool + */ protected $_migration_auto_latest = FALSE; + /** + * Error message + * + * @var string + */ protected $_error_string = ''; + /** + * Initialize Migration Class + * + * @param array + */ public function __construct($config = array()) { # Only run this constructor on main library load -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Migration.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index ce4683fc1..0a88e6926 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -45,28 +45,28 @@ class CI_Migration { * @var bool */ protected $_migration_enabled = FALSE; - + /** * Path to migration classes * * @var string */ protected $_migration_path = NULL; - + /** * Current migration version * * @var mixed */ protected $_migration_version = 0; - + /** * Database table with migration info * * @var string */ protected $_migration_table = 'migrations'; - + /** * Whether to automatically run migrations * @@ -85,6 +85,7 @@ class CI_Migration { * Initialize Migration Class * * @param array + * @return void */ public function __construct($config = array()) { @@ -96,7 +97,7 @@ class CI_Migration { foreach ($config as $key => $val) { - $this->{'_' . $key} = $val; + $this->{'_'.$key} = $val; } log_message('debug', 'Migrations class initialized'); @@ -340,7 +341,6 @@ class CI_Migration { } sort($files); - return $files; } @@ -384,6 +384,7 @@ class CI_Migration { { return get_instance()->$var; } + } /* End of file Migration.php */ -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 0a88e6926..4391b235d 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -109,7 +109,7 @@ class CI_Migration { } // If not set, set it - $this->_migration_path != '' OR $this->_migration_path = APPPATH.'migrations/'; + $this->_migration_path !== '' OR $this->_migration_path = APPPATH.'migrations/'; // Add trailing slash if not set $this->_migration_path = rtrim($this->_migration_path, '/').'/'; @@ -179,7 +179,7 @@ class CI_Migration { // We now prepare to actually DO the migrations // But first let's make sure that everything is the way it should be - for ($i = $start; $i != $stop; $i += $step) + for ($i = $start; $i !== $stop; $i += $step) { $f = glob(sprintf($this->_migration_path.'%03d_*.php', $i)); -- cgit v1.2.3-24-g4f1b From af6d85088d54ed35f7c36ed010384ff7592f8959 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 19 Jun 2012 15:30:47 -0500 Subject: Fixed Migrations and an incorrect strict comparison. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 4391b235d..3a1e7a0ad 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -179,7 +179,7 @@ class CI_Migration { // We now prepare to actually DO the migrations // But first let's make sure that everything is the way it should be - for ($i = $start; $i !== $stop; $i += $step) + for ($i = $start; $i != $stop; $i += $step) { $f = glob(sprintf($this->_migration_path.'%03d_*.php', $i)); -- cgit v1.2.3-24-g4f1b From 5db4827c006439a381ec48a49658cca7d3026233 Mon Sep 17 00:00:00 2001 From: Dumk0 Date: Thu, 5 Jul 2012 02:58:10 +0300 Subject: Fixed annotation for CI_Migration->find_migrations() method --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3a1e7a0ad..99ddc9ed1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -322,9 +322,9 @@ class CI_Migration { // -------------------------------------------------------------------- /** - * Set's the schema to the latest migration + * Retrieves list of available migration scripts * - * @return mixed true if already latest, false if failed, int if upgraded + * @return array list of migration file paths sorted by version */ protected function find_migrations() { -- cgit v1.2.3-24-g4f1b From 62e6816fc6c7651df9dc20abd713e0ec06a9ac34 Mon Sep 17 00:00:00 2001 From: Dumk0 Date: Thu, 5 Jul 2012 03:09:31 +0300 Subject: improvement for latest migration id calculation --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3a1e7a0ad..ea46ce665 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -292,7 +292,7 @@ class CI_Migration { // Calculate the last migration step from existing migration // filenames and procceed to the standard version migration - return $this->version((int) substr($last_migration, 0, 3)); + return $this->version((int)$last_migration); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From dc128cdcacd88980a9dcd3865e0065f19cb0c11c Mon Sep 17 00:00:00 2001 From: Dumk0 Date: Thu, 5 Jul 2012 03:20:09 +0300 Subject: added space after (int) --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index ea46ce665..cd49166f2 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -292,7 +292,7 @@ class CI_Migration { // Calculate the last migration step from existing migration // filenames and procceed to the standard version migration - return $this->version((int)$last_migration); + return $this->version((int) $last_migration); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From afee226aa4487b3645fb916f99b4cf7f012af536 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 15 Jul 2012 18:59:01 +0100 Subject: Changed TRUE and FALSE values to be uppercase --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index c786703ca..5d637d44a 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -285,7 +285,7 @@ class CI_Migration { if ( ! $migrations = $this->find_migrations()) { $this->_error_string = $this->lang->line('migration_none_found'); - return false; + return FALSE; } $last_migration = basename(end($migrations)); -- cgit v1.2.3-24-g4f1b From 34c8b9c45fdcd2eb0eee5e2275a52e4c2faed5dc Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Wed, 31 Oct 2012 14:02:35 -0400 Subject: Added support for timestamp-based migrations Signed-off-by: Jonathon Hill --- system/libraries/Migration.php | 230 +++++++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 100 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 5d637d44a..2a06aa011 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -45,6 +45,13 @@ class CI_Migration { * @var bool */ protected $_migration_enabled = FALSE; + + /** + * Migration numbering style + * + * @var bool + */ + protected $_migration_style = 'sequential'; /** * Path to migration classes @@ -73,6 +80,13 @@ class CI_Migration { * @var bool */ protected $_migration_auto_latest = FALSE; + + /** + * Migration basename regex + * + * @var bool + */ + protected $_migration_regex = NULL; /** * Error message @@ -125,12 +139,21 @@ class CI_Migration { { show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); } + + // Migration basename regex + $this->_migration_regex = $this->_migration_style === 'timestamp' ? '/^\d{14}_(\w+)$/' : '/^\d{3}_(\w+)$/'; + + // Make sure a valid migration numbering style was set. + if ( ! in_array($this->_migration_style, array('sequential', 'timestamp'))) + { + show_error('An invalid migration numbering style was specified: '.$this->_migration_style); + } // If the migrations table is missing, make it if ( ! $this->db->table_exists($this->_migration_table)) { $this->dbforge->add_field(array( - 'version' => array('type' => 'INT', 'constraint' => 3), + 'version' => array('type' => 'BIGINT', 'constraint' => 3), )); $this->dbforge->create_table($this->_migration_table, TRUE); @@ -158,113 +181,80 @@ class CI_Migration { */ public function version($target_version) { - $start = $current_version = $this->_get_version(); - $stop = $target_version; - + $current_version = (int) $this->_get_version(); + $target_version = (int) $target_version; + + $migrations = $this->find_migrations(); + + if ($target_version > 0 AND ! isset($migrations[$target_version])) + { + $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version); + return FALSE; + } + if ($target_version > $current_version) { // Moving Up - ++$start; - ++$stop; - $step = 1; + $method = 'up'; } else { - // Moving Down - $step = -1; + // Moving Down, apply in reverse order + $method = 'down'; + krsort($migrations); } - $method = $step === 1 ? 'up' : 'down'; - $migrations = array(); - - // We now prepare to actually DO the migrations - // But first let's make sure that everything is the way it should be - for ($i = $start; $i != $stop; $i += $step) + if (empty($migrations)) { - $f = glob(sprintf($this->_migration_path.'%03d_*.php', $i)); + return TRUE; + } + + $previous = FALSE; - // Only one migration per step is permitted - if (count($f) > 1) + // Validate all available migrations, and run the ones within our target range + foreach ($migrations as $number => $file) + { + // Check for sequence gaps + if ($this->_migration_style === 'sequential' AND $previous !== FALSE AND abs($number - $previous) > 1) { - $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $i); + $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); return FALSE; } + + include $file; + $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); - // Migration step not found - if (count($f) === 0) + // Validate the migration file structure + if ( ! class_exists($class)) { - // If trying to migrate up to a version greater than the last - // existing one, migrate to the last one. - if ($step === 1) - { - break; - } - - // If trying to migrate down but we're missing a step, - // something must definitely be wrong. - $this->_error_string = sprintf($this->lang->line('migration_not_found'), $i); + $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); return FALSE; } - - $file = basename($f[0]); - $name = basename($f[0], '.php'); - - // Filename validations - if (preg_match('/^\d{3}_(\w+)$/', $name, $match)) - { - $match[1] = strtolower($match[1]); - - // Cannot repeat a migration at different steps - if (in_array($match[1], $migrations)) - { - $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $match[1]); - return FALSE; - } - - include $f[0]; - $class = 'Migration_'.ucfirst($match[1]); - - if ( ! class_exists($class)) - { - $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); - return FALSE; - } - - if ( ! is_callable(array($class, $method))) - { - $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); - return FALSE; - } - - $migrations[] = $match[1]; - } - else + elseif ( ! is_callable(array($class, $method))) { - $this->_error_string = sprintf($this->lang->line('migration_invalid_filename'), $file); + $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); return FALSE; } + + $previous = $number; + + // Run migrations that are inside the target range + if ( + ($method === 'up' AND $number > $current_version AND $number <= $target_version) OR + ($method === 'down' AND $number <= $current_version AND $number > $target_version) + ) { + log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); + call_user_func(array(new $class, $method)); + $current_version = $number; + $this->_update_version($current_version); + } } - - log_message('debug', 'Current migration: '.$current_version); - - $version = $i + ($step === 1 ? -1 : 0); - - // If there is nothing to do so quit - if ($migrations === array()) - { - return TRUE; - } - - log_message('debug', 'Migrating from '.$method.' to version '.$version); - - // Loop through the migrations - foreach ($migrations AS $migration) + + // This is necessary when moving down, since the the last migration applied + // will be the down() method for the next migration up from the target + if ($current_version <> $target_version) { - // Run the migration class - $class = 'Migration_'.ucfirst(strtolower($migration)); - call_user_func(array(new $class, $method)); - - $current_version += $step; + $current_version = $target_version; $this->_update_version($current_version); } @@ -282,17 +272,19 @@ class CI_Migration { */ public function latest() { - if ( ! $migrations = $this->find_migrations()) + $migrations = $this->find_migrations(); + + if (empty($migrations)) { $this->_error_string = $this->lang->line('migration_none_found'); return FALSE; } $last_migration = basename(end($migrations)); - + // Calculate the last migration step from existing migration // filenames and procceed to the standard version migration - return $this->version((int) $last_migration); + return $this->version($this->_get_migration_number($last_migration)); } // -------------------------------------------------------------------- @@ -326,22 +318,60 @@ class CI_Migration { * * @return array list of migration file paths sorted by version */ - protected function find_migrations() + public function find_migrations() { + $migrations = array(); + // Load all *_*.php files in the migrations path - $files = glob($this->_migration_path.'*_*.php'); - - for ($i = 0, $c = count($files); $i < $c; $i++) + foreach (glob($this->_migration_path.'*_*.php') as $file) { - // Mark wrongly formatted files as false for later filtering - if ( ! preg_match('/^\d{3}_(\w+)$/', basename($files[$i], '.php'))) + $name = basename($file, '.php'); + + // Filter out non-migration files + if (preg_match($this->_migration_regex, $name)) { - $files[$i] = FALSE; + $number = $this->_get_migration_number($name); + + // There cannot be duplicate migration numbers + if (isset($migrations[$number])) + { + $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number); + show_error($this->_error_string); + } + + $migrations[$number] = $file; } } - sort($files); - return $files; + ksort($migrations); + return $migrations; + } + + // -------------------------------------------------------------------- + + /** + * Extracts the migration number from a filename + * + * @return int Numeric portion of a migration filename + */ + protected function _get_migration_number($migration) + { + $parts = explode('_', $migration); + return (int) $parts[0]; + } + + // -------------------------------------------------------------------- + + /** + * Extracts the migration class name from a filename + * + * @return string text portion of a migration filename + */ + protected function _get_migration_name($migration) + { + $parts = explode('_', $migration); + array_shift($parts); + return implode('_', $parts); } // -------------------------------------------------------------------- @@ -365,10 +395,10 @@ class CI_Migration { * @param int Migration reached * @return void Outputs a report of the migration */ - protected function _update_version($migrations) + protected function _update_version($migration) { return $this->db->update($this->_migration_table, array( - 'version' => $migrations + 'version' => $migration )); } -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Migration.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 5d637d44a..06f2f562c 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -1,4 +1,4 @@ - Date: Mon, 12 Nov 2012 08:42:28 -0500 Subject: Fixed a mismatched constraint value when creating the migration table Signed-off-by: Jonathon Hill --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 2a06aa011..f67725c18 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -153,7 +153,7 @@ class CI_Migration { if ( ! $this->db->table_exists($this->_migration_table)) { $this->dbforge->add_field(array( - 'version' => array('type' => 'BIGINT', 'constraint' => 3), + 'version' => array('type' => 'BIGINT', 'constraint' => 20), )); $this->dbforge->create_table($this->_migration_table, TRUE); -- cgit v1.2.3-24-g4f1b From b719bfdb268926e764a787ffcab1a3ea9c9759d7 Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Mon, 12 Nov 2012 09:03:36 -0500 Subject: Changed the `migration_style` config setting to `migration_type` Signed-off-by: Jonathon Hill --- system/libraries/Migration.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 275aeb048..af9e53030 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -48,11 +48,11 @@ class CI_Migration { protected $_migration_enabled = FALSE; /** - * Migration numbering style + * Migration numbering type * * @var bool */ - protected $_migration_style = 'sequential'; + protected $_migration_type = 'sequential'; /** * Path to migration classes @@ -142,12 +142,12 @@ class CI_Migration { } // Migration basename regex - $this->_migration_regex = $this->_migration_style === 'timestamp' ? '/^\d{14}_(\w+)$/' : '/^\d{3}_(\w+)$/'; + $this->_migration_regex = $this->_migration_type === 'timestamp' ? '/^\d{14}_(\w+)$/' : '/^\d{3}_(\w+)$/'; - // Make sure a valid migration numbering style was set. - if ( ! in_array($this->_migration_style, array('sequential', 'timestamp'))) + // Make sure a valid migration numbering type was set. + if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) { - show_error('An invalid migration numbering style was specified: '.$this->_migration_style); + show_error('An invalid migration numbering type was specified: '.$this->_migration_type); } // If the migrations table is missing, make it @@ -216,7 +216,7 @@ class CI_Migration { foreach ($migrations as $number => $file) { // Check for sequence gaps - if ($this->_migration_style === 'sequential' AND $previous !== FALSE AND abs($number - $previous) > 1) + if ($this->_migration_type === 'sequential' AND $previous !== FALSE AND abs($number - $previous) > 1) { $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); return FALSE; -- cgit v1.2.3-24-g4f1b From 02ea66eb922ade4646acbbe22be6354ad8916a0f Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Mon, 12 Nov 2012 17:26:36 -0500 Subject: Code style fixes Signed-off-by: Jonathon Hill --- system/libraries/Migration.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index af9e53030..d08afa598 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -187,7 +187,7 @@ class CI_Migration { $migrations = $this->find_migrations(); - if ($target_version > 0 AND ! isset($migrations[$target_version])) + if ($target_version > 0 && ! isset($migrations[$target_version])) { $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version); return FALSE; @@ -216,7 +216,7 @@ class CI_Migration { foreach ($migrations as $number => $file) { // Check for sequence gaps - if ($this->_migration_type === 'sequential' AND $previous !== FALSE AND abs($number - $previous) > 1) + if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1) { $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); return FALSE; @@ -241,9 +241,10 @@ class CI_Migration { // Run migrations that are inside the target range if ( - ($method === 'up' AND $number > $current_version AND $number <= $target_version) OR - ($method === 'down' AND $number <= $current_version AND $number > $target_version) - ) { + ($method === 'up' && $number > $current_version && $number <= $target_version) OR + ($method === 'down' && $number <= $current_version && $number > $target_version) + ) + { log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); call_user_func(array(new $class, $method)); $current_version = $number; -- cgit v1.2.3-24-g4f1b From 4ddf9443c553ee734a48432e08e9253fc514b43c Mon Sep 17 00:00:00 2001 From: Jonathon Hill Date: Mon, 12 Nov 2012 18:30:59 -0500 Subject: Improved code readability --- system/libraries/Migration.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index d08afa598..27d7df010 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -142,7 +142,9 @@ class CI_Migration { } // Migration basename regex - $this->_migration_regex = $this->_migration_type === 'timestamp' ? '/^\d{14}_(\w+)$/' : '/^\d{3}_(\w+)$/'; + $this->_migration_regex = ($this->_migration_type === 'timestamp') + ? '/^\d{14}_(\w+)$/' + : '/^\d{3}_(\w+)$/'; // Make sure a valid migration numbering type was set. if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) -- cgit v1.2.3-24-g4f1b From 39eb806dc491e5f4ffe9dc537e8dc224c2592ee7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 13 Nov 2012 03:36:40 +0200 Subject: Clean-up following PR #1949 --- system/libraries/Migration.php | 60 ++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 27d7df010..e96791cef 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -46,11 +46,11 @@ class CI_Migration { * @var bool */ protected $_migration_enabled = FALSE; - + /** * Migration numbering type * - * @var bool + * @var bool */ protected $_migration_type = 'sequential'; @@ -78,10 +78,10 @@ class CI_Migration { /** * Whether to automatically run migrations * - * @var bool + * @var bool */ protected $_migration_auto_latest = FALSE; - + /** * Migration basename regex * @@ -99,7 +99,7 @@ class CI_Migration { /** * Initialize Migration Class * - * @param array + * @param array $config * @return void */ public function __construct($config = array()) @@ -140,12 +140,12 @@ class CI_Migration { { show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); } - + // Migration basename regex $this->_migration_regex = ($this->_migration_type === 'timestamp') ? '/^\d{14}_(\w+)$/' : '/^\d{3}_(\w+)$/'; - + // Make sure a valid migration numbering type was set. if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) { @@ -179,22 +179,22 @@ class CI_Migration { * Calls each migration step required to get to the schema version of * choice * - * @param int Target schema version + * @param int $target_version Target schema version * @return mixed TRUE if already latest, FALSE if failed, int if upgraded */ public function version($target_version) { $current_version = (int) $this->_get_version(); $target_version = (int) $target_version; - + $migrations = $this->find_migrations(); - + if ($target_version > 0 && ! isset($migrations[$target_version])) { $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version); return FALSE; } - + if ($target_version > $current_version) { // Moving Up @@ -211,7 +211,7 @@ class CI_Migration { { return TRUE; } - + $previous = FALSE; // Validate all available migrations, and run the ones within our target range @@ -223,7 +223,7 @@ class CI_Migration { $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); return FALSE; } - + include $file; $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); @@ -238,7 +238,7 @@ class CI_Migration { $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); return FALSE; } - + $previous = $number; // Run migrations that are inside the target range @@ -253,7 +253,7 @@ class CI_Migration { $this->_update_version($current_version); } } - + // This is necessary when moving down, since the the last migration applied // will be the down() method for the next migration up from the target if ($current_version <> $target_version) @@ -272,12 +272,12 @@ class CI_Migration { /** * Set's the schema to the latest migration * - * @return mixed true if already latest, false if failed, int if upgraded + * @return mixed TRUE if already latest, FALSE if failed, int if upgraded */ public function latest() { $migrations = $this->find_migrations(); - + if (empty($migrations)) { $this->_error_string = $this->lang->line('migration_none_found'); @@ -285,7 +285,7 @@ class CI_Migration { } $last_migration = basename(end($migrations)); - + // Calculate the last migration step from existing migration // filenames and procceed to the standard version migration return $this->version($this->_get_migration_number($last_migration)); @@ -296,7 +296,7 @@ class CI_Migration { /** * Set's the schema to the migration version set in config * - * @return mixed true if already current, false if failed, int if upgraded + * @return mixed TRUE if already current, FALSE if failed, int if upgraded */ public function current() { @@ -325,24 +325,24 @@ class CI_Migration { public function find_migrations() { $migrations = array(); - + // Load all *_*.php files in the migrations path foreach (glob($this->_migration_path.'*_*.php') as $file) { $name = basename($file, '.php'); - + // Filter out non-migration files if (preg_match($this->_migration_regex, $name)) { $number = $this->_get_migration_number($name); - + // There cannot be duplicate migration numbers if (isset($migrations[$number])) { $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number); show_error($this->_error_string); } - + $migrations[$number] = $file; } } @@ -356,12 +356,13 @@ class CI_Migration { /** * Extracts the migration number from a filename * - * @return int Numeric portion of a migration filename + * @param string $migration + * @return int Numeric portion of a migration filename */ protected function _get_migration_number($migration) { - $parts = explode('_', $migration); - return (int) $parts[0]; + return sscanf($migration, '%d', $number) + ? $number : 0; } // -------------------------------------------------------------------- @@ -369,7 +370,8 @@ class CI_Migration { /** * Extracts the migration class name from a filename * - * @return string text portion of a migration filename + * @param string $migration + * @return string text portion of a migration filename */ protected function _get_migration_name($migration) { @@ -396,7 +398,7 @@ class CI_Migration { /** * Stores the current schema version * - * @param int Migration reached + * @param int $migration Migration reached * @return void Outputs a report of the migration */ protected function _update_version($migration) @@ -411,7 +413,7 @@ class CI_Migration { /** * Enable the use of CI super-global * - * @param $var + * @param string $var * @return mixed */ public function __get($var) -- cgit v1.2.3-24-g4f1b From e1d6c46b7d5e3d82dc6953af29f0b02ccb03e2dc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 28 Nov 2012 19:06:20 +0200 Subject: Fix #2037 --- system/libraries/Migration.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index e96791cef..bf2d18e07 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -233,11 +233,6 @@ class CI_Migration { $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); return FALSE; } - elseif ( ! is_callable(array($class, $method))) - { - $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); - return FALSE; - } $previous = $number; @@ -247,8 +242,15 @@ class CI_Migration { ($method === 'down' && $number <= $current_version && $number > $target_version) ) { + $instance = new $class(); + if ( ! is_callable(array($instance, $method))) + { + $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); + return FALSE; + } + log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); - call_user_func(array(new $class, $method)); + call_user_func(array($instance, $method)); $current_version = $number; $this->_update_version($current_version); } -- cgit v1.2.3-24-g4f1b From 838a9d69a9139b6bcd6f8765fdd2d58b929e70ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Dec 2012 14:37:47 +0200 Subject: [ci skip] Cleaned some spaces --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index bf2d18e07..e591ab64a 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -143,8 +143,8 @@ class CI_Migration { // Migration basename regex $this->_migration_regex = ($this->_migration_type === 'timestamp') - ? '/^\d{14}_(\w+)$/' - : '/^\d{3}_(\w+)$/'; + ? '/^\d{14}_(\w+)$/' + : '/^\d{3}_(\w+)$/'; // Make sure a valid migration numbering type was set. if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index e591ab64a..443fff7e6 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 -- cgit v1.2.3-24-g4f1b From f69973df6ab099846ad69f9794944ad41d992023 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 3 Jan 2013 12:00:27 +0200 Subject: Fix #2108 --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 443fff7e6..fd915c382 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -224,7 +224,7 @@ class CI_Migration { return FALSE; } - include $file; + include_once $file; $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); // Validate the migration file structure -- cgit v1.2.3-24-g4f1b From 8151cbb586edf565a57e33287b01222d9c4a85b6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 30 Jan 2013 13:57:56 +0200 Subject: Fix/improve #2211 --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index fd915c382..b673e9cb7 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -104,8 +104,8 @@ class CI_Migration { */ public function __construct($config = array()) { - # Only run this constructor on main library load - if (get_parent_class($this) !== FALSE) + // Only run this constructor on main library load + if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE)) { return; } -- cgit v1.2.3-24-g4f1b From 49e68de96b420a444c826995746a5f09470e76d9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 21 Feb 2013 16:30:55 +0200 Subject: Disable autoloader call from class_exists() occurences to improve performance Note: The Driver libary tests seem to depend on that, so one occurence in CI_Loader is left until we resolve that. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index b673e9cb7..cc6fe48f0 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -228,7 +228,7 @@ class CI_Migration { $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); // Validate the migration file structure - if ( ! class_exists($class)) + if ( ! class_exists($class, FALSE)) { $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); return FALSE; -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index cc6fe48f0..932b06ef0 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 -- cgit v1.2.3-24-g4f1b From 35f6a54882901ab2b7fe98cf648de7d666536673 Mon Sep 17 00:00:00 2001 From: Jacob Tabak Date: Wed, 19 Feb 2014 15:38:26 -0600 Subject: Fixed typos in Migration library documentation Signed-off-by: Jacob Tabak --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 932b06ef0..2ead3aec1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -272,7 +272,7 @@ class CI_Migration { // -------------------------------------------------------------------- /** - * Set's the schema to the latest migration + * Sets the schema to the latest migration * * @return mixed TRUE if already latest, FALSE if failed, int if upgraded */ @@ -296,7 +296,7 @@ class CI_Migration { // -------------------------------------------------------------------- /** - * Set's the schema to the migration version set in config + * Sets the schema to the migration version set in config * * @return mixed TRUE if already current, FALSE if failed, int if upgraded */ -- cgit v1.2.3-24-g4f1b From 3a9f325cdff1fda2f2b37498a689ac2cde058195 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 25 Feb 2014 11:47:45 +0200 Subject: Use strings instead of integers for migration version numbers - Allows timestamp versions to work on 32-bit systems. - Fixes #2902. - Supersedes PR #2368. --- system/libraries/Migration.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 2ead3aec1..b226ee804 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -179,13 +179,14 @@ class CI_Migration { * Calls each migration step required to get to the schema version of * choice * - * @param int $target_version Target schema version - * @return mixed TRUE if already latest, FALSE if failed, int if upgraded + * @param string $target_version Target schema version + * @return mixed TRUE if already latest, FALSE if failed, string if upgraded */ public function version($target_version) { - $current_version = (int) $this->_get_version(); - $target_version = (int) $target_version; + // Note: We use strings, so that timestamp versions work on 32-bit systems + $current_version = $this->_get_version(); + $target_version = (string) $target_version; $migrations = $this->find_migrations(); @@ -224,7 +225,7 @@ class CI_Migration { return FALSE; } - include_once $file; + include_once($file); $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); // Validate the migration file structure @@ -274,7 +275,7 @@ class CI_Migration { /** * Sets the schema to the latest migration * - * @return mixed TRUE if already latest, FALSE if failed, int if upgraded + * @return mixed TRUE if already latest, FALSE if failed, string if upgraded */ public function latest() { @@ -289,7 +290,7 @@ class CI_Migration { $last_migration = basename(end($migrations)); // Calculate the last migration step from existing migration - // filenames and procceed to the standard version migration + // filenames and proceed to the standard version migration return $this->version($this->_get_migration_number($last_migration)); } @@ -298,7 +299,7 @@ class CI_Migration { /** * Sets the schema to the migration version set in config * - * @return mixed TRUE if already current, FALSE if failed, int if upgraded + * @return mixed TRUE if already current, FALSE if failed, string if upgraded */ public function current() { @@ -359,12 +360,12 @@ class CI_Migration { * Extracts the migration number from a filename * * @param string $migration - * @return int Numeric portion of a migration filename + * @return string Numeric portion of a migration filename */ protected function _get_migration_number($migration) { - return sscanf($migration, '%d', $number) - ? $number : 0; + return sscanf($migration, '%[0-9]+', $number) + ? $number : '0'; } // -------------------------------------------------------------------- @@ -387,12 +388,12 @@ class CI_Migration { /** * Retrieves current schema version * - * @return int Current Migration + * @return string Current migration version */ protected function _get_version() { $row = $this->db->select('version')->get($this->_migration_table)->row(); - return $row ? $row->version : 0; + return $row ? $row->version : '0'; } // -------------------------------------------------------------------- @@ -400,7 +401,7 @@ class CI_Migration { /** * Stores the current schema version * - * @param int $migration Migration reached + * @param string $migration Migration reached * @return void Outputs a report of the migration */ protected function _update_version($migration) -- cgit v1.2.3-24-g4f1b From 9b19887fcc16a3bce52f2cbe84e98b8200bab23d Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 1 Apr 2014 01:13:05 +0300 Subject: Fix #2970 --- system/libraries/Migration.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index b226ee804..009b54fb4 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -186,7 +186,12 @@ class CI_Migration { { // Note: We use strings, so that timestamp versions work on 32-bit systems $current_version = $this->_get_version(); - $target_version = (string) $target_version; + $target_version = (string) $target_version; + + if ($this->_migration_type == 'sequential') + { + $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT); + } $migrations = $this->find_migrations(); -- cgit v1.2.3-24-g4f1b From 59739019bee552d6fa7e5c2bd5eddd932e44b045 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 1 Apr 2014 01:40:37 +0300 Subject: Fixed according to comment. --- system/libraries/Migration.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 009b54fb4..71e0c6993 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -185,13 +185,16 @@ class CI_Migration { public function version($target_version) { // Note: We use strings, so that timestamp versions work on 32-bit systems - $current_version = $this->_get_version(); - $target_version = (string) $target_version; + $current_version = $this->_get_version(); - if ($this->_migration_type == 'sequential') + if ($this->_migration_type === 'sequential') { $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT); } + else + { + $target_version = (string) $target_version; + } $migrations = $this->find_migrations(); -- cgit v1.2.3-24-g4f1b From e2e5c26294cf831daf49b9d6b51db1278c28beb2 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 1 Apr 2014 01:54:39 +0300 Subject: Removed tabs. --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 71e0c6993..bb20c8473 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -185,11 +185,11 @@ class CI_Migration { public function version($target_version) { // Note: We use strings, so that timestamp versions work on 32-bit systems - $current_version = $this->_get_version(); + $current_version = $this->_get_version(); if ($this->_migration_type === 'sequential') { - $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT); + $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT); } else { -- cgit v1.2.3-24-g4f1b From b10a6d62c580980e770ce52b484302d8174764e5 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 1 Apr 2014 02:00:50 +0300 Subject: Removed tab on empty line too. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index bb20c8473..9185adff1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -186,7 +186,7 @@ class CI_Migration { { // Note: We use strings, so that timestamp versions work on 32-bit systems $current_version = $this->_get_version(); - + if ($this->_migration_type === 'sequential') { $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT); -- cgit v1.2.3-24-g4f1b From 46e216c2be69f0819d97f6bead167f28714e9d70 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Apr 2014 12:05:02 +0300 Subject: Optimize #2982 --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 9185adff1..9af4a8297 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -189,7 +189,7 @@ class CI_Migration { if ($this->_migration_type === 'sequential') { - $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT); + $target_version = sprintf('%03d', $target_version); } else { -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/libraries/Migration.php | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 9af4a8297..1c3ae48a1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is - * also available through the world wide web at this URL: - * http://opensource.org/licenses/OSL-3.0 - * If you did not receive a copy of the license and are unable to obtain it - * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 3.0 + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 3.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/libraries/Migration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 1c3ae48a1..f46d45f5a 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 3.0.0 -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index f46d45f5a..a2dce1371 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -126,7 +126,7 @@ class CI_Migration { $this->{'_'.$key} = $val; } - log_message('debug', 'Migrations class initialized'); + log_message('info', 'Migrations Class Initialized'); // Are they trying to use migrations while it is disabled? if ($this->_migration_enabled !== TRUE) -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/libraries/Migration.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index a2dce1371..8ce4243fe 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -444,6 +444,3 @@ class CI_Migration { } } - -/* End of file Migration.php */ -/* Location: ./system/libraries/Migration.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1fb500077784638399be79b32fe354aec257413c Mon Sep 17 00:00:00 2001 From: Gabriel Potkány Date: Wed, 4 Feb 2015 01:45:59 +0100 Subject: Fixed inconsistent return types --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 8ce4243fe..f61814988 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -421,7 +421,7 @@ class CI_Migration { * Stores the current schema version * * @param string $migration Migration reached - * @return void Outputs a report of the migration + * @return object Outputs a report of the migration */ protected function _update_version($migration) { -- cgit v1.2.3-24-g4f1b From cea5fb713822d00460222deaa1cf66543effccf8 Mon Sep 17 00:00:00 2001 From: Gabriel Potkány Date: Wed, 4 Feb 2015 08:22:06 +0100 Subject: Adjusted returns/return types to suggestions --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index f61814988..ae36a3b45 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -421,11 +421,11 @@ class CI_Migration { * Stores the current schema version * * @param string $migration Migration reached - * @return object Outputs a report of the migration + * @return void */ protected function _update_version($migration) { - return $this->db->update($this->_migration_table, array( + $this->db->update($this->_migration_table, array( 'version' => $migration )); } -- cgit v1.2.3-24-g4f1b From b8978ee517fab43fea511869337ac40b577f00a3 Mon Sep 17 00:00:00 2001 From: ftwbzhao Date: Wed, 20 May 2015 16:10:35 +0800 Subject: optimize migrations class reference --- system/libraries/Migration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index ae36a3b45..e17f41696 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -191,7 +191,7 @@ class CI_Migration { * choice * * @param string $target_version Target schema version - * @return mixed TRUE if already latest, FALSE if failed, string if upgraded + * @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure */ public function version($target_version) { @@ -294,7 +294,7 @@ class CI_Migration { /** * Sets the schema to the latest migration * - * @return mixed TRUE if already latest, FALSE if failed, string if upgraded + * @return mixed current version string on success, FALSE on failure */ public function latest() { @@ -318,7 +318,7 @@ class CI_Migration { /** * Sets the schema to the migration version set in config * - * @return mixed TRUE if already current, FALSE if failed, string if upgraded + * @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure */ public function current() { -- cgit v1.2.3-24-g4f1b From 8d132bb1e999c2b2bdc2125d6d4ec36649556fc7 Mon Sep 17 00:00:00 2001 From: ftwbzhao Date: Thu, 21 May 2015 20:28:54 +0800 Subject: update function latest --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index e17f41696..45a3cbbce 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -294,7 +294,7 @@ class CI_Migration { /** * Sets the schema to the latest migration * - * @return mixed current version string on success, FALSE on failure + * @return mixed Current version string on success, FALSE on failure */ public function latest() { -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 45a3cbbce..d0254abfc 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 3.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index d0254abfc..259c83c54 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 3.0.0 * @filesource */ -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 259c83c54..7aefb6c23 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From f8490b994c959de3e1eabba27d8d919433e3fc70 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 16 Mar 2016 16:22:14 +0200 Subject: Fix #4539 --- system/libraries/Migration.php | 97 +++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 34 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 7aefb6c23..74bec3d60 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -96,9 +96,9 @@ class CI_Migration { /** * Migration basename regex * - * @var bool + * @var string */ - protected $_migration_regex = NULL; + protected $_migration_regex; /** * Error message @@ -217,31 +217,61 @@ class CI_Migration { if ($target_version > $current_version) { - // Moving Up $method = 'up'; } else { - // Moving Down, apply in reverse order $method = 'down'; + // We need this so that migrations are applied in reverse order krsort($migrations); } - if (empty($migrations)) - { - return TRUE; - } - - $previous = FALSE; - - // Validate all available migrations, and run the ones within our target range + // Validate all available migrations within our target range. + // + // Unfortunately, we'll have to use another loop to run them + // in order to avoid leaving the procedure in a broken state. + // + // See https://github.com/bcit-ci/CodeIgniter/issues/4539 + $pending = array(); foreach ($migrations as $number => $file) { + // Ignore versions out of our range. + // + // Because we've previously sorted the $migrations array depending on the direction, + // we can safely break the loop once we reach $target_version ... + if ($method === 'up') + { + if ($number <= $current_version) + { + continue; + } + elseif ($number > $target_version) + { + break; + } + } + else + { + if ($number > $current_version) + { + continue; + } + elseif ($number <= $target_version) + { + break; + } + } + // Check for sequence gaps - if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1) + if ($this->_migration_type === 'sequential') { - $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); - return FALSE; + if (isset($previous) && abs($number - $previous) > 1) + { + $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); + return FALSE; + } + + $previous = $number; } include_once($file); @@ -253,27 +283,27 @@ class CI_Migration { $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); return FALSE; } + // method_exists() returns true for non-public methods, + // while is_callable() can't be used without instantiating. + // Only get_class_methods() satisfies both conditions. + elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class)))) + { + $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); + return FALSE; + } - $previous = $number; + $pending[$number] = array($class, $method); + } - // Run migrations that are inside the target range - if ( - ($method === 'up' && $number > $current_version && $number <= $target_version) OR - ($method === 'down' && $number <= $current_version && $number > $target_version) - ) - { - $instance = new $class(); - if ( ! is_callable(array($instance, $method))) - { - $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); - return FALSE; - } + // Now just run the necessary migrations + foreach ($pending as $number => $migration) + { + log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); - log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); - call_user_func(array($instance, $method)); - $current_version = $number; - $this->_update_version($current_version); - } + $migration[0] = new $migration[0]; + call_user_func($migration); + $current_version = $number; + $this->_update_version($current_version); } // This is necessary when moving down, since the the last migration applied @@ -285,7 +315,6 @@ class CI_Migration { } log_message('debug', 'Finished migrating to '.$current_version); - return $current_version; } -- cgit v1.2.3-24-g4f1b From 3df07729b8018acd764a7a8a08f34f1579c43e5e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 16 Mar 2016 21:15:52 +0200 Subject: A small Migrations tweak --- system/libraries/Migration.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 74bec3d60..316c94ae3 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -219,12 +219,17 @@ class CI_Migration { { $method = 'up'; } - else + elseif ($target_version < $current_version) { $method = 'down'; // We need this so that migrations are applied in reverse order krsort($migrations); } + else + { + // Well, there's nothing to migrate then ... + return TRUE; + } // Validate all available migrations within our target range. // -- cgit v1.2.3-24-g4f1b From a838279625becfba98ccb7635d35c67297129c42 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 28 Jul 2016 16:40:12 +0300 Subject: Remove dead code written for PHP 5.2 --- system/libraries/Migration.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 316c94ae3..3e2107e83 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -288,10 +288,7 @@ class CI_Migration { $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); return FALSE; } - // method_exists() returns true for non-public methods, - // while is_callable() can't be used without instantiating. - // Only get_class_methods() satisfies both conditions. - elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class)))) + elseif ( ! is_callable(array($class, $method))) { $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); return FALSE; -- cgit v1.2.3-24-g4f1b From da60e9bc66ec90970fbd2dfd08b0a6e66b9f5f5f Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Migration.php') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3e2107e83..2a87d9d7c 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 -- cgit v1.2.3-24-g4f1b