summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-03-21 17:32:19 +0100
committerAndrey Andreev <narf@devilix.net>2016-03-21 17:32:19 +0100
commitb4d719dc7fb3b010b53c09e7e82f979abf731ff9 (patch)
tree34e3d8213830f8d6362fbb868718806ad100dceb /system
parent99e8dc396f6f79980623daaf9265f4933b897ff6 (diff)
parenteb373a1abb348515001123ecbaca5e5384e69d19 (diff)
Merge branch '3.0-stable' into develop
Resolved conflicts: user_guide_src/source/changelog.rst user_guide_src/source/conf.py user_guide_src/source/installation/downloads.rst user_guide_src/source/installation/upgrading.rst
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Form_validation.php29
-rw-r--r--system/libraries/Migration.php98
-rw-r--r--system/libraries/Session/Session.php18
3 files changed, 91 insertions, 54 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 9fb686892..e4a518957 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -486,7 +486,7 @@ class CI_Form_validation {
}
// Now we need to re-set the POST data with the new, processed data
- $this->_reset_post_array();
+ empty($this->validation_data) && $this->_reset_post_array();
return ($total_errors === 0);
}
@@ -527,10 +527,7 @@ class CI_Form_validation {
{
if ($row['is_array'] === FALSE)
{
- if (isset($_POST[$row['field']]))
- {
- $_POST[$row['field']] = $row['postdata'];
- }
+ isset($_POST[$field]) && $_POST[$field] = $row['postdata'];
}
else
{
@@ -550,20 +547,7 @@ class CI_Form_validation {
}
}
- if (is_array($row['postdata']))
- {
- $array = array();
- foreach ($row['postdata'] as $k => $v)
- {
- $array[$k] = $v;
- }
-
- $post_ref = $array;
- }
- else
- {
- $post_ref = $row['postdata'];
- }
+ $post_ref = $row['postdata'];
}
}
}
@@ -1515,10 +1499,11 @@ class CI_Form_validation {
* This function allows HTML to be safely shown in a form.
* Special characters are converted.
*
- * @param string
- * @return string
+ * @deprecated 3.0.6 Not used anywhere within the framework and pretty much useless
+ * @param mixed $data Input data
+ * @return mixed
*/
- public function prep_for_form($data = '')
+ public function prep_for_form($data)
{
if ($this->_safe_form_data === FALSE OR empty($data))
{
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index 7aefb6c23..316c94ae3 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,66 @@ class CI_Migration {
if ($target_version > $current_version)
{
- // Moving Up
$method = 'up';
}
- else
+ elseif ($target_version < $current_version)
{
- // Moving Down, apply in reverse order
$method = 'down';
+ // We need this so that migrations are applied in reverse order
krsort($migrations);
}
-
- if (empty($migrations))
+ else
{
+ // Well, there's nothing to migrate then ...
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 +288,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 +320,6 @@ class CI_Migration {
}
log_message('debug', 'Finished migrating to '.$current_version);
-
return $current_version;
}
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
index 77c56ae70..c9d2e8adc 100644
--- a/system/libraries/Session/Session.php
+++ b/system/libraries/Session/Session.php
@@ -584,6 +584,24 @@ class CI_Session {
// ------------------------------------------------------------------------
/**
+ * __isset()
+ *
+ * @param string $key 'session_id' or a session data key
+ * @return bool
+ */
+ public function __isset($key)
+ {
+ if ($key === 'session_id')
+ {
+ return (session_status() === PHP_SESSION_ACTIVE);
+ }
+
+ return isset($_SESSION[$key]);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* __set()
*
* @param string $key Session data key