Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 19 commits
  • 33 files changed
  • 0 commit comments
  • 4 contributors
Commits on Apr 14, 2012
@cryode cryode Add mobile detection to robot user agents. 001a764
Commits on Oct 31, 2012
Jonathon Hill Added support for timestamp-based migrations
Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
34c8b9c
Commits on Nov 12, 2012
Jonathon Hill Fixed a mismatched constraint value when creating the migration table
Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
275cf27
Jonathon Hill Merge remote-tracking branch 'upstream/develop' into develop
Conflicts:
	user_guide_src/source/changelog.rst

Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
3978fc3
Jonathon Hill Changed the `migration_style` config setting to `migration_type`
Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
b719bfd
@narfbg narfbg Some micro-optimizations 7a7ad78
@narfbg narfbg Remove 'services' directive from .travis.yml
According to the Travis docs at http://about.travis-ci.org/docs/user/database-setup/,
mysql and postgre are started on boot (and therefore don't need manual a start), while
we all know that sqlite is not a service and doesn't need that either.
de00a69
@narfbg narfbg Fix issue #1992 fe367a9
Jonathon Hill Fixed a typo
Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
49c5eda
Jonathon Hill Code style fixes
Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
02ea66e
@narfbg narfbg Fix issue #1994 9e94576
Jonathon Hill Improved code readability 4ddf944
Jonathon Hill Fixed an issue with my merge
Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
93f989b
Commits on Nov 13, 2012
@narfbg narfbg Add seed values support for Query Builder order_by
(feature request #1987)
98e46cf
@narfbg narfbg Merge pull request #1949 from compwright/develop
Added support for timestamp-based migrations
5d5bc05
@narfbg narfbg Clean-up following PR #1949 39eb806
@narfbg narfbg Merge pull request #1258 from cryode/feature/robot_mobile
Add mobile detection to robot user agents.
2978d77
@narfbg narfbg [ci skip] Add changelog entry for PR #1258 324762b
@it-can ci update 91bb051
Showing with 334 additions and 168 deletions.
  1. +18 −0 application/config/migration.php
  2. +2 −2 system/core/Input.php
  3. +2 −2 system/core/Output.php
  4. +2 −2 system/database/DB_driver.php
  5. +8 −5 system/database/DB_query_builder.php
  6. +2 −2 system/database/DB_utility.php
  7. +7 −0 system/database/drivers/cubrid/cubrid_driver.php
  8. +2 −2 system/database/drivers/ibase/ibase_driver.php
  9. +2 −2 system/database/drivers/mssql/mssql_driver.php
  10. +2 −2 system/database/drivers/oci8/oci8_driver.php
  11. +7 −2 system/database/drivers/odbc/odbc_driver.php
  12. +7 −0 system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
  13. +2 −2 system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
  14. +2 −2 system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
  15. +9 −0 system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
  16. +2 −2 system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
  17. +7 −0 system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
  18. +37 −2 system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
  19. +1 −1 system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
  20. +2 −2 system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
  21. +37 −2 system/database/drivers/postgre/postgre_driver.php
  22. +2 −2 system/database/drivers/sqlite/sqlite_driver.php
  23. +2 −2 system/database/drivers/sqlite3/sqlite3_driver.php
  24. +2 −2 system/database/drivers/sqlsrv/sqlsrv_driver.php
  25. +2 −2 system/helpers/date_helper.php
  26. +1 −0 system/language/english/migration_lang.php
  27. +2 −2 system/libraries/Email.php
  28. +5 −15 system/libraries/Form_validation.php
  29. +6 −6 system/libraries/Image_lib.php
  30. +136 −101 system/libraries/Migration.php
  31. +14 −1 system/libraries/Parser.php
  32. +1 −1 system/libraries/Trackback.php
  33. +1 −0 system/libraries/User_agent.php
View
18 application/config/migration.php
@@ -39,6 +39,24 @@
/*
|--------------------------------------------------------------------------
+| Migration Type
+|--------------------------------------------------------------------------
+|
+| Migration file names may be based on a sequential identifier or on
+| a timestamp. Options are:
+|
+| 'sequential' = Default migration naming (001_add_blog.php)
+| 'timestamp' = Timestamp migration naming (20121031104401_add_blog.php)
+| Use timestamp format YYYYMMDDHHIISS.
+|
+| If this configuration value is missing the Migration library defaults
+| to 'sequential' for backward compatibility.
+|
+*/
+$config['migration_type'] = 'timestamp';
+
+/*
+|--------------------------------------------------------------------------
| Migrations table
|--------------------------------------------------------------------------
|
View
4 system/core/Input.php
@@ -768,9 +768,9 @@ public function request_headers($xss_clean = FALSE)
foreach ($_SERVER as $key => $val)
{
- if (strpos($key, 'HTTP_') === 0)
+ if (sscanf($key, 'HTTP_%s', $header) === 1)
{
- $headers[substr($key, 5)] = $this->_fetch_from_array($_SERVER, $key, $xss_clean);
+ $headers[$header] = $this->_fetch_from_array($_SERVER, $key, $xss_clean);
}
}
}
View
4 system/core/Output.php
@@ -256,9 +256,9 @@ public function get_content_type()
{
for ($i = 0, $c = count($this->headers); $i < $c; $i++)
{
- if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches))
+ if (sscanf($this->headers[$i][0], 'Content-Type: %s', $content_type) === 1)
{
- return $matches[1];
+ return $content_type;
}
}
View
4 system/database/DB_driver.php
@@ -329,9 +329,9 @@
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' RAND()';
+ protected $_random_keyword = array('RAND()', 'RAND(%d)');
/**
* COUNT string
View
13 system/database/DB_query_builder.php
@@ -1144,13 +1144,16 @@ public function or_having($key, $value = NULL, $escape = NULL)
*/
public function order_by($orderby, $direction = '', $escape = NULL)
{
- $direction = trim($direction);
+ $direction = strtoupper(trim($direction));
- if (strtolower($direction) === 'random' OR $orderby === $this->_random_keyword)
+ if ($direction === 'RANDOM')
{
- // Random ordered results don't need a field name
- $orderby = $this->_random_keyword;
$direction = '';
+
+ // Do we have a seed value?
+ $orderby = ctype_digit((string) $orderby)
+ ? $orderby = sprintf($this->_random_keyword[1], $orderby)
+ : $this->_random_keyword[0];
}
elseif (empty($orderby))
{
@@ -1158,7 +1161,7 @@ public function order_by($orderby, $direction = '', $escape = NULL)
}
elseif ($direction !== '')
{
- $direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' '.$direction : '';
+ $direction = in_array($direction, array('ASC', 'DESC'), TRUE) ? ' '.$direction : '';
}
is_bool($escape) OR $escape = $this->_protect_identifiers;
View
4 system/database/DB_utility.php
@@ -106,9 +106,9 @@ public function list_databases()
return $this->db->data_cache['db_names'];
}
- for ($i = 0, $c = count($query); $i < $c; $i++)
+ for ($i = 0, $query = $query->result_array(), $c = count($query); $i < $c; $i++)
{
- $this->db->data_cache['db_names'] = current($query[$i]);
+ $this->db->data_cache['db_names'][] = current($query[$i]);
}
return $this->db->data_cache['db_names'];
View
7 system/database/drivers/cubrid/cubrid_driver.php
@@ -64,6 +64,13 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected $_escape_char = '`';
+ /**
+ * ORDER BY random keyword
+ *
+ * @var array
+ */
+ protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
+
// --------------------------------------------------------------------
/**
View
4 system/database/drivers/ibase/ibase_driver.php
@@ -53,9 +53,9 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' Random()';
+ protected $_random_keyword = array('RAND()', 'RAND()');
/**
* IBase Transaction status flag
View
4 system/database/drivers/mssql/mssql_driver.php
@@ -53,9 +53,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' NEWID()';
+ protected $_random_keyword = array('NEWID()', 'RAND(%d)');
/**
* Quoted identifier flag
View
4 system/database/drivers/oci8/oci8_driver.php
@@ -102,9 +102,9 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' ASC'; // not currently supported
+ protected $_random_keyword = array('ASC', 'ASC'); // not currently supported
/**
* COUNT string
View
9 system/database/drivers/odbc/odbc_driver.php
@@ -73,6 +73,13 @@ class CI_DB_odbc_driver extends CI_DB {
*/
protected $_like_escape_str = " {escape '%s'} ";
+ /**
+ * ORDER BY random keyword
+ *
+ * @var array
+ */
+ protected $_random_keyword = array('RND()', 'RND(%d)');
+
// --------------------------------------------------------------------
/**
@@ -85,8 +92,6 @@ public function __construct($params)
{
parent::__construct($params);
- $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
-
// Legacy support for DSN in the hostname field
if (empty($this->dsn))
{
View
7 system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
@@ -55,6 +55,13 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*/
protected $_escape_char = '`';
+ /**
+ * ORDER BY random keyword
+ *
+ * @var array
+ */
+ protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
+
// --------------------------------------------------------------------
/**
View
4 system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
@@ -53,9 +53,9 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' NEWID()';
+ protected $_random_keyword = array('NEWID()', 'RAND(%d)');
/**
* Quoted identifier flag
View
4 system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
@@ -53,9 +53,9 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' RANDOM()';
+ protected $_random_keyword = array('RAND()', 'RAND()');
// --------------------------------------------------------------------
View
9 system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
@@ -51,6 +51,15 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
+ * ORDER BY random keyword
+ *
+ * @var array
+ */
+ protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
+
+ // --------------------------------------------------------------------
+
+ /**
* Class constructor
*
* Builds the DSN if not already set.
View
4 system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
@@ -62,9 +62,9 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' ASC'; // Currently not supported
+ protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
/**
* COUNT string
View
7 system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
@@ -73,6 +73,13 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*/
protected $_like_escape_str = " {escape '%s'} ";
+ /**
+ * ORDER BY random keyword
+ *
+ * @var array
+ */
+ protected $_random_keyword = array('RND()', 'RND(%d)');
+
// --------------------------------------------------------------------
/**
View
39 system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
@@ -60,9 +60,9 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' RANDOM()';
+ protected $_random_keyword = array('RANDOM()', 'RANDOM()');
// --------------------------------------------------------------------
@@ -110,6 +110,41 @@ public function insert_id($name = NULL)
// --------------------------------------------------------------------
/**
+ * ORDER BY
+ *
+ * @param string $orderby
+ * @param string $direction ASC or DESC
+ * @param bool $escape
+ * @return object
+ */
+ public function order_by($orderby, $direction = '', $escape = NULL)
+ {
+ $direction = strtoupper(trim($direction));
+ if ($direction === 'RANDOM')
+ {
+ if ( ! is_float($orderby) && ctype_digit((string) $orderby))
+ {
+ $orderby = ($orderby > 1)
+ ? (float) '0.'.$orderby
+ : (float) $orderby;
+ }
+
+ if (is_float($orderby))
+ {
+ $this->simple_query('SET SEED '.$orderby);
+ }
+
+ $orderby = $this->_random_keyword[0];
+ $direction = '';
+ $escape = FALSE;
+ }
+
+ return parent::order_by($orderby, $direction, $escape);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
View
2 system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
@@ -53,7 +53,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
protected $_random_keyword = ' RANDOM()';
View
4 system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
@@ -53,9 +53,9 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' NEWID()';
+ protected $_random_keyword = array('NEWID()', 'RAND(%d)');
/**
* Quoted identifier flag
View
39 system/database/drivers/postgre/postgre_driver.php
@@ -60,9 +60,9 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' RANDOM()'; // database specific random keyword
+ protected $_random_keyword = array('RANDOM()', 'RANDOM()');
// --------------------------------------------------------------------
@@ -482,6 +482,41 @@ public function error()
// --------------------------------------------------------------------
/**
+ * ORDER BY
+ *
+ * @param string $orderby
+ * @param string $direction ASC or DESC
+ * @param bool $escape
+ * @return object
+ */
+ public function order_by($orderby, $direction = '', $escape = NULL)
+ {
+ $direction = strtoupper(trim($direction));
+ if ($direction === 'RANDOM')
+ {
+ if ( ! is_float($orderby) && ctype_digit((string) $orderby))
+ {
+ $orderby = ($orderby > 1)
+ ? (float) '0.'.$orderby
+ : (float) $orderby;
+ }
+
+ if (is_float($orderby))
+ {
+ $this->simple_query('SET SEED '.$orderby);
+ }
+
+ $orderby = $this->_random_keyword[0];
+ $direction = '';
+ $escape = FALSE;
+ }
+
+ return parent::order_by($orderby, $direction, $escape);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Update statement
*
* Generates a platform-specific update string from the supplied data
View
4 system/database/drivers/sqlite/sqlite_driver.php
@@ -53,9 +53,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' Random()'; // database specific random keyword
+ protected $_random_keyword = array('RANDOM()', 'RANDOM()');
// --------------------------------------------------------------------
View
4 system/database/drivers/sqlite3/sqlite3_driver.php
@@ -54,9 +54,9 @@ class CI_DB_sqlite3_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' RANDOM()';
+ protected $_random_keyword = array('RANDOM()', 'RANDOM()');
// --------------------------------------------------------------------
View
4 system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -53,9 +53,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* ORDER BY random keyword
*
- * @var string
+ * @var array
*/
- protected $_random_keyword = ' NEWID()';
+ protected $_random_keyword = array('NEWID()', 'RAND(%d)');
/**
* Quoted identifier flag
View
4 system/helpers/date_helper.php
@@ -677,8 +677,8 @@ function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y
$is_unix = ! ( ! $is_unix OR $is_unix === 'days');
// Validate input and try strtotime() on invalid timestamps/intervals, just in case
- if ( ( ! preg_match('/^[0-9]+$/', $unix_start) && ($unix_start = @strtotime($unix_time)) === FALSE)
- OR ( ! preg_match('/^[0-9]+$/', $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE))
+ if ( ( ! ctype_digit((string) $unix_start) && ($unix_start = @strtotime($unix_time)) === FALSE)
+ OR ( ! ctype_digit((string) $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE))
OR ($is_unix === TRUE && $mixed < $unix_start))
{
return FALSE;
View
1 system/language/english/migration_lang.php
@@ -28,6 +28,7 @@
$lang['migration_none_found'] = 'No migrations were found.';
$lang['migration_not_found'] = 'No migration could be found with the version number: %d.';
+$lang['migration_sequence_gap'] = 'There is a gap in the migration sequence near version number: %d.';
$lang['migration_multiple_version'] = 'There are multiple migrations with the same version number: %d.';
$lang['migration_class_doesnt_exist'] = 'The migration class "%s" could not be found.';
$lang['migration_missing_up_method'] = 'The migration class "%s" is missing an "up" method.';
View
4 system/libraries/Email.php
@@ -1935,7 +1935,7 @@ protected function _send_command($cmd, $data = '')
$this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
- if ( (int) substr($reply, 0, 3) !== $resp)
+ if ((int) substr($reply, 0, 3) !== $resp)
{
$this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE;
@@ -2093,7 +2093,7 @@ protected function _set_error_message($msg, $val = '')
$CI =& get_instance();
$CI->lang->load('email');
- if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
+ if (sscanf($msg, 'lang:%s', $line) !== 1 OR FALSE === ($line = $CI->lang->line($line)))
{
$this->_debug_msg[] = str_replace('%s', $val, $msg).'<br />';
}
View
20 system/libraries/Form_validation.php
@@ -199,12 +199,10 @@ public function set_rules($field, $label = '', $rules = '')
// Is the field name an array? If it is an array, we break it apart
// into its components so that we can fetch the corresponding POST data later
+ $indexes = array();
if (preg_match_all('/\[(.*?)\]/', $field, $matches))
{
- // Note: Due to a bug in current() that affects some versions
- // of PHP we can not pass function call directly into it
- $x = explode('[', $field);
- $indexes[] = current($x);
+ sscanf($field, '%[^[][', $indexes[0]);
for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
@@ -218,7 +216,6 @@ public function set_rules($field, $label = '', $rules = '')
}
else
{
- $indexes = array();
$is_array = FALSE;
}
@@ -673,11 +670,7 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
- if (preg_match('/(.*?)\[(.*)\]/', $rule, $match))
- {
- $rule = $match[1];
- $param = $match[2];
- }
+ sscanf($rule, '%[^[][%[^]]', $rule, $param);
// Call the function that corresponds to the rule
if ($callback === TRUE)
@@ -796,11 +789,8 @@ protected function _translate_fieldname($fieldname)
{
// Do we need to translate the field name?
// We look for the prefix lang: to determine this
- if (strpos($fieldname, 'lang:') === 0)
+ if (sscanf($fieldname, 'lang:%s', $line) === 1)
{
- // Grab the variable
- $line = substr($fieldname, 5);
-
// Were we able to translate the field name? If not we use $line
if (FALSE === ($fieldname = $this->CI->lang->line($line)))
{
@@ -1002,7 +992,7 @@ public function differs($str, $field)
*/
public function is_unique($str, $field)
{
- list($table, $field) = explode('.', $field);
+ sscanf($field, '%[^.].%[^.]', $table, $field);
if (isset($this->CI->db))
{
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
View
12 system/libraries/Image_lib.php
@@ -605,7 +605,7 @@ public function initialize($props = array())
// Set the quality
$this->quality = trim(str_replace('%', '', $this->quality));
- if ($this->quality === '' OR $this->quality === 0 OR ! preg_match('/^[0-9]+$/', $this->quality))
+ if ($this->quality === '' OR $this->quality === 0 OR ! ctype_digit($this->quality))
{
$this->quality = 90;
}
@@ -1277,8 +1277,8 @@ public function text_watermark()
if ($this->wm_use_drop_shadow === FALSE)
$this->wm_shadow_distance = 0;
- $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
- $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
+ $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
+ $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
// Set verticle alignment
if ($this->wm_vrt_alignment === 'M')
@@ -1518,13 +1518,13 @@ public function image_display_gd($resource)
public function image_reproportion()
{
if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
- OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height))
- OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height))
+ OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
+ OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
{
return;
}
- // Sanitize so we don't call preg_match() anymore
+ // Sanitize
$this->width = (int) $this->width;
$this->height = (int) $this->height;
View
237 system/libraries/Migration.php
@@ -48,6 +48,13 @@ class CI_Migration {
protected $_migration_enabled = FALSE;
/**
+ * Migration numbering type
+ *
+ * @var bool
+ */
+ protected $_migration_type = 'sequential';
+
+ /**
* Path to migration classes
*
* @var string
@@ -71,11 +78,18 @@ class CI_Migration {
/**
* Whether to automatically run migrations
*
- * @var bool
+ * @var bool
*/
protected $_migration_auto_latest = FALSE;
/**
+ * Migration basename regex
+ *
+ * @var bool
+ */
+ protected $_migration_regex = NULL;
+
+ /**
* Error message
*
* @var string
@@ -85,7 +99,7 @@ class CI_Migration {
/**
* Initialize Migration Class
*
- * @param array
+ * @param array $config
* @return void
*/
public function __construct($config = array())
@@ -127,11 +141,22 @@ public function __construct($config = array())
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')))
+ {
+ show_error('An invalid migration numbering type was specified: '.$this->_migration_type);
+ }
+
// 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' => 20),
));
$this->dbforge->create_table($this->_migration_table, TRUE);
@@ -154,118 +179,86 @@ public function __construct($config = array())
* 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)
{
- $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 && ! 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;
+ }
- // Only one migration per step is permitted
- if (count($f) > 1)
- {
- $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $i);
- return FALSE;
- }
+ $previous = FALSE;
- // Migration step not found
- if (count($f) === 0)
+ // Validate all available migrations, and run the ones within our target range
+ foreach ($migrations as $number => $file)
+ {
+ // Check for sequence gaps
+ if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1)
{
- // 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_sequence_gap'), $number);
return FALSE;
}
- $file = basename($f[0]);
- $name = basename($f[0], '.php');
+ include $file;
+ $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php'))));
- // Filename validations
- if (preg_match('/^\d{3}_(\w+)$/', $name, $match))
+ // Validate the migration file structure
+ if ( ! class_exists($class))
{
- $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];
+ $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class);
+ return FALSE;
}
- 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;
}
- }
- log_message('debug', 'Current migration: '.$current_version);
+ $previous = $number;
- $version = $i + ($step === 1 ? -1 : 0);
-
- // If there is nothing to do so quit
- if ($migrations === array())
- {
- return TRUE;
+ // 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)
+ )
+ {
+ 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', '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);
}
@@ -279,11 +272,13 @@ public function version($target_version)
/**
* 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()
{
- if ( ! $migrations = $this->find_migrations())
+ $migrations = $this->find_migrations();
+
+ if (empty($migrations))
{
$this->_error_string = $this->lang->line('migration_none_found');
return FALSE;
@@ -293,7 +288,7 @@ public function latest()
// 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));
}
// --------------------------------------------------------------------
@@ -301,7 +296,7 @@ public function latest()
/**
* 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()
{
@@ -327,22 +322,62 @@ public function error_string()
*
* @return array list of migration file paths sorted by version
*/
- protected function find_migrations()
+ public function find_migrations()
{
- // Load all *_*.php files in the migrations path
- $files = glob($this->_migration_path.'*_*.php');
+ $migrations = array();
- for ($i = 0, $c = count($files); $i < $c; $i++)
+ // Load all *_*.php files in the migrations path
+ 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
+ *
+ * @param string $migration
+ * @return int Numeric portion of a migration filename
+ */
+ protected function _get_migration_number($migration)
+ {
+ return sscanf($migration, '%d', $number)
+ ? $number : 0;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Extracts the migration class name from a filename
+ *
+ * @param string $migration
+ * @return string text portion of a migration filename
+ */
+ protected function _get_migration_name($migration)
+ {
+ $parts = explode('_', $migration);
+ array_shift($parts);
+ return implode('_', $parts);
}
// --------------------------------------------------------------------
@@ -363,13 +398,13 @@ protected function _get_version()
/**
* 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($migrations)
+ protected function _update_version($migration)
{
return $this->db->update($this->_migration_table, array(
- 'version' => $migrations
+ 'version' => $migration
));
}
@@ -378,7 +413,7 @@ protected function _update_version($migrations)
/**
* Enable the use of CI super-global
*
- * @param $var
+ * @param string $var
* @return mixed
*/
public function __get($var)
View
15 system/libraries/Parser.php
@@ -58,6 +58,20 @@ class CI_Parser {
*/
protected $CI;
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->CI =& get_instance();
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Parse a template
*
@@ -71,7 +85,6 @@ class CI_Parser {
*/
public function parse($template, $data, $return = FALSE)
{
- $this->CI =& get_instance();
$template = $this->CI->load->view($template, $data, TRUE);
return $this->_parse($template, $data, $return);
View
2 system/libraries/Trackback.php
@@ -394,7 +394,7 @@ public function get_id($url)
}
}
- return preg_match('/^[0-9]+$/', $tb_id) ? $tb_id : FALSE;
+ return ctype_digit((string) $tb_id) ? $tb_id : FALSE;
}
// --------------------------------------------------------------------
View
1 system/libraries/User_agent.php
@@ -310,6 +310,7 @@ protected function _set_robot()
{
$this->is_robot = TRUE;
$this->robot = $val;
+ $this->_set_mobile();
return TRUE;
}
}

No commit comments for this range

Something went wrong with that request. Please try again.