diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-17 19:28:26 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-17 19:28:26 +0000 |
commit | fe396410894f9fcf430e31216312f70db800d96e (patch) | |
tree | fc1222c074e0f8ffd2d952688353f5bf79e360f5 | |
parent | 093fb407a839b1bdacd0cd6036b349a42dcfea7d (diff) |
Update Kohana code to r3799 from their svn head. All tests pass.
Resolved upstream tickets:
http://dev.kohanaphp.com/ticket/972
Command:
svn merge -c19275 vendor/kohana/modified/kohana trunk/kohana
-rw-r--r-- | kohana/config/sql_types.php | 37 | ||||
-rw-r--r-- | kohana/helpers/form.php | 4 | ||||
-rw-r--r-- | kohana/helpers/html.php | 2 | ||||
-rw-r--r-- | kohana/helpers/valid.php | 13 | ||||
-rw-r--r-- | kohana/libraries/Database.php | 13 | ||||
-rw-r--r-- | kohana/libraries/ORM.php | 49 | ||||
-rw-r--r-- | kohana/libraries/ORM_Versioned.php | 143 | ||||
-rw-r--r-- | kohana/libraries/drivers/Database/Mssql.php | 4 | ||||
-rw-r--r-- | kohana/libraries/drivers/Image/GraphicsMagick.php | 6 | ||||
-rw-r--r-- | kohana/views/kohana_profiler_table.php | 2 |
10 files changed, 240 insertions, 33 deletions
diff --git a/kohana/config/sql_types.php b/kohana/config/sql_types.php index f1a267fd..2431c707 100644 --- a/kohana/config/sql_types.php +++ b/kohana/config/sql_types.php @@ -8,24 +8,25 @@ */ $config = array ( - 'tinyint' => array('type' => 'int', 'max' => 127), - 'smallint' => array('type' => 'int', 'max' => 32767), - 'mediumint' => array('type' => 'int', 'max' => 8388607), - 'int' => array('type' => 'int', 'max' => 2147483647), - 'integer' => array('type' => 'int', 'max' => 2147483647), - 'bigint' => array('type' => 'int', 'max' => 9223372036854775807), - 'float' => array('type' => 'float'), - 'boolean' => array('type' => 'boolean'), - 'time' => array('type' => 'string', 'format' => '00:00:00'), - 'date' => array('type' => 'string', 'format' => '0000-00-00'), - 'year' => array('type' => 'string', 'format' => '0000'), - 'datetime' => array('type' => 'string', 'format' => '0000-00-00 00:00:00'), - 'char' => array('type' => 'string', 'exact' => TRUE), - 'binary' => array('type' => 'string', 'binary' => TRUE, 'exact' => TRUE), - 'varchar' => array('type' => 'string'), - 'varbinary' => array('type' => 'string', 'binary' => TRUE), - 'blob' => array('type' => 'string', 'binary' => TRUE), - 'text' => array('type' => 'string') + 'tinyint' => array('type' => 'int', 'max' => 127), + 'smallint' => array('type' => 'int', 'max' => 32767), + 'mediumint' => array('type' => 'int', 'max' => 8388607), + 'int' => array('type' => 'int', 'max' => 2147483647), + 'integer' => array('type' => 'int', 'max' => 2147483647), + 'bigint' => array('type' => 'int', 'max' => 9223372036854775807), + 'float' => array('type' => 'float'), + 'float unsigned' => array('type' => 'float', 'min' => 0), + 'boolean' => array('type' => 'boolean'), + 'time' => array('type' => 'string', 'format' => '00:00:00'), + 'date' => array('type' => 'string', 'format' => '0000-00-00'), + 'year' => array('type' => 'string', 'format' => '0000'), + 'datetime' => array('type' => 'string', 'format' => '0000-00-00 00:00:00'), + 'char' => array('type' => 'string', 'exact' => TRUE), + 'binary' => array('type' => 'string', 'binary' => TRUE, 'exact' => TRUE), + 'varchar' => array('type' => 'string'), + 'varbinary' => array('type' => 'string', 'binary' => TRUE), + 'blob' => array('type' => 'string', 'binary' => TRUE), + 'text' => array('type' => 'string') ); // DOUBLE diff --git a/kohana/helpers/form.php b/kohana/helpers/form.php index 30753f1e..5162a1ad 100644 --- a/kohana/helpers/form.php +++ b/kohana/helpers/form.php @@ -241,6 +241,7 @@ class form_Core { */ public static function dropdown($data, $options = NULL, $selected = NULL, $extra = '') { + if ( ! is_array($data)) { $data = array('name' => $data); @@ -266,6 +267,9 @@ class form_Core { // Key should always be a string $key = (string) $key; + // Selected must always be a string + $selected = (string) $selected; + if (is_array($val)) { $input .= '<optgroup label="'.$key.'">'."\n"; diff --git a/kohana/helpers/html.php b/kohana/helpers/html.php index b11ea755..d1f09612 100644 --- a/kohana/helpers/html.php +++ b/kohana/helpers/html.php @@ -307,7 +307,7 @@ class html_Core { $length = strlen($suffix); - if (substr_compare($href, $suffix, -$length, $length, FALSE) !== 0) + if ( $length > 0 AND substr_compare($href, $suffix, -$length, $length, FALSE) !== 0) { // Add the defined suffix $href .= $suffix; diff --git a/kohana/helpers/valid.php b/kohana/helpers/valid.php index d71dbcae..3d3206c8 100644 --- a/kohana/helpers/valid.php +++ b/kohana/helpers/valid.php @@ -87,10 +87,12 @@ class valid_Core { * @param boolean allow IPv6 addresses * @return boolean */ - public static function ip($ip, $ipv6 = FALSE) + public static function ip($ip, $ipv6 = FALSE, $allow_private = FALSE) { - // Do not allow private and reserved range IPs + // By default do not allow private and reserved range IPs $flags = FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE; + if ($allow_private === TRUE) + $flags = FILTER_FLAG_NO_RES_RANGE; if ($ipv6 === TRUE) return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flags); @@ -264,12 +266,17 @@ class valid_Core { /** * Checks whether a string is a valid number (negative and decimal numbers allowed). * + * @see Uses locale conversion to allow decimal point to be locale specific. + * @see http://www.php.net/manual/en/function.localeconv.php + * * @param string input string * @return boolean */ public static function numeric($str) { - return (is_numeric($str) AND preg_match('/^[-0-9.]++$/D', (string) $str)); + // Use localeconv to set the decimal_point value: Usually a comma or period. + $locale = localeconv(); + return (preg_match('/^[-0-9'.$locale['decimal_point'].']++$/D', (string) $str)); } /** diff --git a/kohana/libraries/Database.php b/kohana/libraries/Database.php index ca4f6512..fd1ae3fa 100644 --- a/kohana/libraries/Database.php +++ b/kohana/libraries/Database.php @@ -621,6 +621,12 @@ class Database_Core { if ($val != '') { + // Add the table prefix if we are using table.column names + if(strpos($val, '.')) + { + $val = $this->config['table_prefix'].$val; + } + $this->groupby[] = $this->driver->escape_column($val); } } @@ -674,11 +680,18 @@ class Database_Core { { $direction = strtoupper(trim($direction)); + // Add a direction if the provided one isn't valid if ( ! in_array($direction, array('ASC', 'DESC', 'RAND()', 'RANDOM()', 'NULL'))) { $direction = 'ASC'; } + // Add the table prefix if a table.column was passed + if (strpos($column, '.')) + { + $column = $this->config['table_prefix'].$column; + } + $this->orderby[] = $this->driver->escape_column($column).' '.$direction; } diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php index a26fdcdd..4a76701b 100644 --- a/kohana/libraries/ORM.php +++ b/kohana/libraries/ORM.php @@ -1,5 +1,4 @@ -<?php - +<?php defined('SYSPATH') OR die('No direct access allowed.'); /** * [Object Relational Mapping][ref-orm] (ORM) is a method of abstracting database * access to standard PHP calls. All table rows are represented as model objects, @@ -438,7 +437,15 @@ class ORM_Core { */ public function as_array() { - return $this->object; + $object = array(); + + foreach ($this->object as $key => $val) + { + // Reconstruct the array (calls __get) + $object[$key] = $this->$key; + } + + return $object; } /** @@ -450,9 +457,11 @@ class ORM_Core { */ public function with($object) { - // Don't join anything already joined if (isset($this->with_applied[$object])) + { + // Don't join anything already joined return $this; + } $prefix = $table = $object; @@ -815,11 +824,16 @@ class ORM_Core { // Delete only given ids $this->db->in($this->primary_key, $ids); } - else + elseif (is_null($ids)) { // Delete all records $this->db->where(TRUE); } + else + { + // Do nothing - safeguard + return $this; + } // Delete all objects $this->db->delete($this->table_name); @@ -1167,6 +1181,29 @@ class ORM_Core { return $table; } + + /** + * Outputs ORM iterator joined with given model + * @param $related_model ORM Model the model related to this ORM + * @return ORM iterator + * @author credits to Josh Domagala + */ + public function join_model($related_model) + { + if( !in_array( $related_model->table_name, $this->has_and_belongs_to_many ) ) + { + return FALSE; + } + + // Get the join table name + $join_table = $this->join_table($related_model->table_name); + + // Return ORM iterator of model + return $this + ->join($join_table, $this->foreign_key(NULL, $join_table), $this->foreign_key(TRUE)) + ->where($related_model->foreign_key(NULL, $join_table), $related_model->id) + ->find_all(); + } /** * Returns an ORM model for the given object name; @@ -1211,7 +1248,7 @@ class ORM_Core { $this->object = $this->changed = $this->related = array(); // Set the loaded and saved object status based on the primary key - $this->loaded = $this->saved = ($values[$this->primary_key] > 0); + $this->loaded = $this->saved = (bool) $values[$this->primary_key]; } // Related objects diff --git a/kohana/libraries/ORM_Versioned.php b/kohana/libraries/ORM_Versioned.php new file mode 100644 index 00000000..7c3ee5d3 --- /dev/null +++ b/kohana/libraries/ORM_Versioned.php @@ -0,0 +1,143 @@ +<?php +/** + * Object Relational Mapping (ORM) "versioned" extension. Allows ORM objects to + * be revisioned instead of updated. + * + * $Id$ + * + * @package ORM + * @author Kohana Team + * @copyright (c) 2007-2008 Kohana Team + * @license http://kohanaphp.com/license.html + */ +class ORM_Versioned_Core extends ORM { + + protected $last_version = NULL; + + /** + * Overload ORM::save() to support versioned data + * + * @chainable + * @return ORM + */ + public function save() + { + $this->last_version = 1 + ($this->last_version === NULL ? $this->object['version'] : $this->last_version); + $this->__set('version', $this->last_version); + + parent::save(); + + if ($this->saved) + { + $data = array(); + foreach ($this->object as $key => $value) + { + if ($key === 'id') + continue; + + $data[$key] = $value; + } + $data[$this->foreign_key()] = $this->id; + + $this->db->insert($this->table_name.'_versions', $data); + } + + return $this; + } + + /** + * Loads previous version from current object + * + * @chainable + * @return ORM + */ + public function previous() + { + if ( ! $this->loaded) + return $this; + + $this->last_version = ($this->last_version === NULL) ? $this->object['version'] : $this->last_version; + $version = $this->last_version - 1; + + $query = $this->db + ->where($this->foreign_key(), $this->object[$this->primary_key]) + ->where('version', $version) + ->limit(1) + ->get($this->table_name.'_versions'); + + if ($query->count()) + { + $this->load_values($query->result(FALSE)->current()); + } + + return $this; + } + + /** + * Restores the object with data from stored version + * + * @param integer version number you want to restore + * @return ORM + */ + public function restore($version) + { + if ( ! $this->loaded) + return $this; + + $query = $this->db + ->where($this->foreign_key(), $this->object[$this->primary_key]) + ->where('version', $version) + ->limit(1) + ->get($this->table_name.'_versions'); + + if ($query->count()) + { + $row = $query->result(FALSE)->current(); + + foreach ($row as $key => $value) + { + if ($key === $this->primary_key OR $key === $this->foreign_key()) + { + // Do not overwrite the primary key + continue; + } + + if ($key === 'version') + { + // Always use the current version + $value = $this->version; + } + + $this->__set($key, $value); + } + + $this->save(); + } + + return $this; + } + + /** + * Overloads ORM::delete() to delete all versioned entries of current object + * and the object itself + * + * @param integer id of the object you want to delete + * @return ORM + */ + public function delete($id = NULL) + { + if ($id === NULL) + { + // Use the current object id + $id = $this->object[$this->primary_key]; + } + + if ($status = parent::delete($id)) + { + $this->db->where($this->foreign_key(), $id)->delete($this->table_name.'_versions'); + } + + return $status; + } + +}
\ No newline at end of file diff --git a/kohana/libraries/drivers/Database/Mssql.php b/kohana/libraries/drivers/Database/Mssql.php index 644d4a13..401770a2 100644 --- a/kohana/libraries/drivers/Database/Mssql.php +++ b/kohana/libraries/drivers/Database/Mssql.php @@ -58,7 +58,9 @@ class Database_Mssql_Driver extends Database_Driver // Build the connection info $host = isset($host) ? $host : $socket; - $port = (isset($port) AND is_string($port)) ? ':'.$port : ''; + + // Windows uses a comma instead of a colon + $port = (isset($port) AND is_string($port)) ? (KOHANA_IS_WIN ? ',' : ':').$port : ''; // Make the connection and select the database if (($this->link = $connect($host.$port, $user, $pass, TRUE)) AND mssql_select_db($database, $this->link)) diff --git a/kohana/libraries/drivers/Image/GraphicsMagick.php b/kohana/libraries/drivers/Image/GraphicsMagick.php index a1392c23..8840eb80 100644 --- a/kohana/libraries/drivers/Image/GraphicsMagick.php +++ b/kohana/libraries/drivers/Image/GraphicsMagick.php @@ -30,7 +30,7 @@ class Image_GraphicsMagick_Driver extends Image_Driver { if (empty($config['directory'])) { // Attempt to locate GM by using "which" (only works for *nix!) - if ( ! is_file($path = exec('which gmdisplay'))) + if ( ! is_file($path = exec('which gm'))) throw new Kohana_Exception('image.graphicsmagick.not_found'); $config['directory'] = dirname($path); @@ -40,8 +40,8 @@ class Image_GraphicsMagick_Driver extends Image_Driver { $this->ext = (PHP_SHLIB_SUFFIX === 'dll') ? '.exe' : ''; // Check to make sure the provided path is correct - if ( ! is_file(realpath($config['directory']).'/gmdisplay'.$this->ext)) - throw new Kohana_Exception('image.graphicsmagick.not_found', 'gmdisplay'.$this->ext); + if ( ! is_file(realpath($config['directory']).'/gm'.$this->ext)) + throw new Kohana_Exception('image.graphicsmagick.not_found', 'gm'.$this->ext); // Set the installation directory diff --git a/kohana/views/kohana_profiler_table.php b/kohana/views/kohana_profiler_table.php index b4970311..b6b46530 100644 --- a/kohana/views/kohana_profiler_table.php +++ b/kohana/views/kohana_profiler_table.php @@ -22,4 +22,4 @@ $style = empty($row['style']) ? '' : ' style="'.$row['style'].'"'; endforeach; ?> -</table> +</table>
\ No newline at end of file |