From 3ed7a5af46586f186a4627d8b029aec7c3ff579d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:24:02 -0800 Subject: Rename I18n to Gallery_I18n to avoid conflict with Kohana 2.4 --- modules/gallery/controllers/l10n_client.php | 8 +- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/locales.php | 6 +- modules/gallery/hooks/init_gallery.php | 2 +- modules/gallery/libraries/Gallery_I18n.php | 430 ++++++++++++++++++++++++++++ modules/gallery/libraries/I18n.php | 430 ---------------------------- modules/gallery/tests/I18n_Test.php | 6 +- 7 files changed, 442 insertions(+), 442 deletions(-) create mode 100644 modules/gallery/libraries/Gallery_I18n.php delete mode 100644 modules/gallery/libraries/I18n.php (limited to 'modules') diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 6db67d3b..3801e6aa 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -24,7 +24,7 @@ class L10n_Client_Controller extends Controller { access::forbidden(); } - $locale = I18n::instance()->locale(); + $locale = Gallery_I18n::instance()->locale(); $input = Input::instance(); $key = $input->post("l10n-message-key"); @@ -36,7 +36,7 @@ class L10n_Client_Controller extends Controller { if (!$root_message->loaded) { throw new Exception("@todo bad request data / illegal state"); } - $is_plural = I18n::is_plural_message(unserialize($root_message->message)); + $is_plural = Gallery_I18n::is_plural_message(unserialize($root_message->message)); if ($is_plural) { $plural_forms = l10n_client::plural_forms($locale); @@ -122,9 +122,9 @@ class L10n_Client_Controller extends Controller { $calls[$row->key] = array(unserialize($row->message), array()); } } else { - $calls = I18n::instance()->call_log(); + $calls = Gallery_I18n::instance()->call_log(); } - $locale = I18n::instance()->locale(); + $locale = Gallery_I18n::instance()->locale(); if ($calls) { $translations = array(); diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index a8059b3a..e36d419d 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -37,7 +37,7 @@ class l10n_scanner_Core { } } - $key = I18n::get_message_key($message); + $key = Gallery_I18n::get_message_key($message); if (array_key_exists($key, $cache)) { return $cache[$key]; } diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index 2de029ff..8d76e333 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -125,13 +125,13 @@ class locales_Core { if (empty(self::$locales)) { self::_init_language_data(); } - $locale or $locale = I18n::instance()->locale(); + $locale or $locale = Gallery_I18n::instance()->locale(); return self::$locales["$locale"]; } static function is_rtl($locale=null) { - $locale or $locale = I18n::instance()->locale(); + $locale or $locale = Gallery_I18n::instance()->locale(); list ($language, $territory) = explode('_', $locale . "_"); return in_array($language, array("he", "fa", "ar")); } @@ -233,7 +233,7 @@ class locales_Core { } // If we have any preference, override the site's default locale if ($locale) { - I18n::instance()->locale($locale); + Gallery_I18n::instance()->locale($locale); } } diff --git a/modules/gallery/hooks/init_gallery.php b/modules/gallery/hooks/init_gallery.php index b2d9c4de..4ce9bab4 100644 --- a/modules/gallery/hooks/init_gallery.php +++ b/modules/gallery/hooks/init_gallery.php @@ -24,7 +24,7 @@ if (!file_exists(VARPATH . "database.php")) { url::redirect(url::abs_file("installer")); } -Event::add("system.ready", array("I18n", "instance")); +Event::add("system.ready", array("Gallery_I18n", "instance")); Event::add("system.ready", array("module", "load_modules")); Event::add("system.ready", array("gallery", "ready")); Event::add("system.post_routing", array("url", "parse_url")); diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php new file mode 100644 index 00000000..0571fe58 --- /dev/null +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -0,0 +1,430 @@ +translate($message, $options); +} + +/** + * Translates a localizable message with plural forms. + * @param $singular String The message to be translated. E.g. "There is one album." + * @param $plural String The plural message to be translated. E.g. + * "There are %count albums." + * @param $count Number The number which is inserted for the %count placeholder and + * which is used to select the proper plural form ($singular or $plural). + * @param $options array (optional) Options array for key value pairs which are used + * for pluralization and interpolation. Special key: "locale" to override the + * currently configured locale. + * @return String The translated message string. + */ +function t2($singular, $plural, $count, $options=array()) { + return Gallery_I18n::instance()->translate(array("one" => $singular, "other" => $plural), + array_merge($options, array("count" => $count))); +} + +class Gallery_I18n_Core { + private static $_instance; + private $_config = array(); + private $_call_log = array(); + private $_cache = array(); + + private function __construct($config) { + $this->_config = $config; + $this->locale($config['default_locale']); + } + + public static function instance($config=null) { + if (self::$_instance == NULL || isset($config)) { + $config = isset($config) ? $config : Kohana::config('locale'); + if (empty($config['default_locale'])) { + $config['default_locale'] = module::get_var('gallery', 'default_locale'); + } + self::$_instance = new Gallery_I18n_Core($config); + } + + return self::$_instance; + } + + public function locale($locale=null) { + if ($locale) { + $this->_config['default_locale'] = $locale; + // Attempt to set PHP's locale as well (for number formatting, collation, etc.) + // TODO: See G2 for better fallack code. + $locale_prefs = array($locale); + $locale_prefs[] = 'en_US'; + $new_locale = setlocale(LC_ALL, $locale_prefs); + if (is_string($new_locale) && strpos($new_locale, 'tr') === 0) { + // Make PHP 5 work with Turkish (the localization results are mixed though). + // Hack for http://bugs.php.net/18556 + setlocale(LC_CTYPE, 'C'); + } + } + return $this->_config['default_locale']; + } + + /** + * Translates a localizable message. + * + * Security: + * The returned string is safe for use in HTML (it contains a safe subset of HTML and + * interpolation parameters are converted to HTML entities). + * For use in JavaScript, please call ->for_js() on it. + * + * @param $message String|array The message to be translated. E.g. "Hello world" + * or array("one" => "One album", "other" => "%count albums") + * @param $options array (optional) Options array for key value pairs which are used + * for pluralization and interpolation. Special keys are "count" and "locale", + * the latter to override the currently configured locale. + * @return String The translated message string. + */ + public function translate($message, $options=array()) { + $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; + $count = isset($options['count']) ? $options['count'] : null; + $values = $options; + unset($values['locale']); + $this->log($message, $options); + + $entry = $this->lookup($locale, $message); + + if (null === $entry) { + // Default to the root locale. + $entry = $message; + $locale = $this->_config['root_locale']; + } + + $entry = $this->pluralize($locale, $entry, $count); + + $entry = $this->interpolate($locale, $entry, $values); + + return SafeString::of_safe_html($entry); + } + + private function lookup($locale, $message) { + if (!isset($this->_cache[$locale])) { + $this->_cache[$locale] = array(); + // TODO: Load data from locale file instead of the DB. + foreach (Database::instance() + ->select("key", "translation") + ->from("incoming_translations") + ->where(array("locale" => $locale)) + ->get() + ->as_array() as $row) { + $this->_cache[$locale][$row->key] = unserialize($row->translation); + } + + // Override incoming with outgoing... + foreach (Database::instance() + ->select("key", "translation") + ->from("outgoing_translations") + ->where(array("locale" => $locale)) + ->get() + ->as_array() as $row) { + $this->_cache[$locale][$row->key] = unserialize($row->translation); + } + } + + $key = self::get_message_key($message); + + if (isset($this->_cache[$locale][$key])) { + return $this->_cache[$locale][$key]; + } else { + return null; + } + } + + public function has_translation($message, $options=null) { + $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; + + $entry = $this->lookup($locale, $message); + + if (null === $entry) { + return false; + } else if (!is_array($message)) { + return $entry !== ''; + } else { + if (!is_array($entry) || empty($entry)) { + return false; + } + // It would be better to verify that all the locale's plural forms have a non-empty + // translation, but this is fine for now. + foreach ($entry as $value) { + if ($value === '') { + return false; + } + } + return true; + } + } + + static function get_message_key($message) { + $as_string = is_array($message) ? implode('|', $message) : $message; + return md5($as_string); + } + + static function is_plural_message($message) { + return is_array($message); + } + + private function interpolate($locale, $string, $key_values) { + // TODO: Handle locale specific number formatting. + + // Replace x_y before replacing x. + krsort($key_values, SORT_STRING); + + $keys = array(); + $values = array(); + foreach ($key_values as $key => $value) { + $keys[] = "%$key"; + $values[] = new SafeString($value); + } + return str_replace($keys, $values, $string); + } + + private function pluralize($locale, $entry, $count) { + if (!is_array($entry)) { + return $entry; + } + + $plural_key = self::get_plural_key($locale, $count); + if (!isset($entry[$plural_key])) { + // Fallback to the default plural form. + $plural_key = 'other'; + } + + if (isset($entry[$plural_key])) { + return $entry[$plural_key]; + } else { + // Fallback to just any plural form. + list ($plural_key, $string) = each($entry); + return $string; + } + } + + private function log($message, $options) { + $key = self::get_message_key($message); + isset($this->_call_log[$key]) or $this->_call_log[$key] = array($message, $options); + } + + public function call_log() { + return $this->_call_log; + } + + private static function get_plural_key($locale, $count) { + $parts = explode('_', $locale); + $language = $parts[0]; + + // Data from CLDR 1.6 (http://unicode.org/cldr/data/common/supplemental/plurals.xml). + // Docs: http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html + switch ($language) { + case 'az': + case 'fa': + case 'hu': + case 'ja': + case 'ko': + case 'my': + case 'to': + case 'tr': + case 'vi': + case 'yo': + case 'zh': + case 'bo': + case 'dz': + case 'id': + case 'jv': + case 'ka': + case 'km': + case 'kn': + case 'ms': + case 'th': + return 'other'; + + case 'ar': + if ($count == 0) { + return 'zero'; + } else if ($count == 1) { + return 'one'; + } else if ($count == 2) { + return 'two'; + } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 10) { + return 'few'; + } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 99) { + return 'many'; + } else { + return 'other'; + } + + case 'pt': + case 'am': + case 'bh': + case 'fil': + case 'tl': + case 'guw': + case 'hi': + case 'ln': + case 'mg': + case 'nso': + case 'ti': + case 'wa': + if ($count == 0 || $count == 1) { + return 'one'; + } else { + return 'other'; + } + + case 'fr': + if ($count >= 0 and $count < 2) { + return 'one'; + } else { + return 'other'; + } + + case 'lv': + if ($count == 0) { + return 'zero'; + } else if ($count % 10 == 1 && $count % 100 != 11) { + return 'one'; + } else { + return 'other'; + } + + case 'ga': + case 'se': + case 'sma': + case 'smi': + case 'smj': + case 'smn': + case 'sms': + if ($count == 1) { + return 'one'; + } else if ($count == 2) { + return 'two'; + } else { + return 'other'; + } + + case 'ro': + case 'mo': + if ($count == 1) { + return 'one'; + } else if (is_int($count) && $count == 0 && ($i = $count % 100) >= 1 && $i <= 19) { + return 'few'; + } else { + return 'other'; + } + + case 'lt': + if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { + return 'one'; + } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 9 && ($i = $count % 100) < 11 && $i > 19) { + return 'few'; + } else { + return 'other'; + } + + case 'hr': + case 'ru': + case 'sr': + case 'uk': + case 'be': + case 'bs': + case 'sh': + if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { + return 'one'; + } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && ($i = $count % 100) < 12 && $i > 14) { + return 'few'; + } else if (is_int($count) && ($count % 10 == 0 || (($i = $count % 10) >= 5 && $i <= 9) || (($i = $count % 100) >= 11 && $i <= 14))) { + return 'many'; + } else { + return 'other'; + } + + case 'cs': + case 'sk': + if ($count == 1) { + return 'one'; + } else if (is_int($count) && $count >= 2 && $count <= 4) { + return 'few'; + } else { + return 'other'; + } + + case 'pl': + if ($count == 1) { + return 'one'; + } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && + ($i = $count % 100) < 12 && $i > 14 && ($i = $count % 100) < 22 && $i > 24) { + return 'few'; + } else { + return 'other'; + } + + case 'sl': + if ($count % 100 == 1) { + return 'one'; + } else if ($count % 100 == 2) { + return 'two'; + } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 4) { + return 'few'; + } else { + return 'other'; + } + + case 'mt': + if ($count == 1) { + return 'one'; + } else if ($count == 0 || is_int($count) && ($i = $count % 100) >= 2 && $i <= 10) { + return 'few'; + } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 19) { + return 'many'; + } else { + return 'other'; + } + + case 'mk': + if ($count % 10 == 1) { + return 'one'; + } else { + return 'other'; + } + + case 'cy': + if ($count == 1) { + return 'one'; + } else if ($count == 2) { + return 'two'; + } else if ($count == 8 || $count == 11) { + return 'many'; + } else { + return 'other'; + } + + default: // en, de, etc. + return $count == 1 ? 'one' : 'other'; + } + } +} diff --git a/modules/gallery/libraries/I18n.php b/modules/gallery/libraries/I18n.php deleted file mode 100644 index c3336052..00000000 --- a/modules/gallery/libraries/I18n.php +++ /dev/null @@ -1,430 +0,0 @@ -translate($message, $options); -} - -/** - * Translates a localizable message with plural forms. - * @param $singular String The message to be translated. E.g. "There is one album." - * @param $plural String The plural message to be translated. E.g. - * "There are %count albums." - * @param $count Number The number which is inserted for the %count placeholder and - * which is used to select the proper plural form ($singular or $plural). - * @param $options array (optional) Options array for key value pairs which are used - * for pluralization and interpolation. Special key: "locale" to override the - * currently configured locale. - * @return String The translated message string. - */ -function t2($singular, $plural, $count, $options=array()) { - return I18n::instance()->translate(array("one" => $singular, "other" => $plural), - array_merge($options, array("count" => $count))); -} - -class I18n_Core { - private static $_instance; - private $_config = array(); - private $_call_log = array(); - private $_cache = array(); - - private function __construct($config) { - $this->_config = $config; - $this->locale($config['default_locale']); - } - - public static function instance($config=null) { - if (self::$_instance == NULL || isset($config)) { - $config = isset($config) ? $config : Kohana::config('locale'); - if (empty($config['default_locale'])) { - $config['default_locale'] = module::get_var('gallery', 'default_locale'); - } - self::$_instance = new I18n_Core($config); - } - - return self::$_instance; - } - - public function locale($locale=null) { - if ($locale) { - $this->_config['default_locale'] = $locale; - // Attempt to set PHP's locale as well (for number formatting, collation, etc.) - // TODO: See G2 for better fallack code. - $locale_prefs = array($locale); - $locale_prefs[] = 'en_US'; - $new_locale = setlocale(LC_ALL, $locale_prefs); - if (is_string($new_locale) && strpos($new_locale, 'tr') === 0) { - // Make PHP 5 work with Turkish (the localization results are mixed though). - // Hack for http://bugs.php.net/18556 - setlocale(LC_CTYPE, 'C'); - } - } - return $this->_config['default_locale']; - } - - /** - * Translates a localizable message. - * - * Security: - * The returned string is safe for use in HTML (it contains a safe subset of HTML and - * interpolation parameters are converted to HTML entities). - * For use in JavaScript, please call ->for_js() on it. - * - * @param $message String|array The message to be translated. E.g. "Hello world" - * or array("one" => "One album", "other" => "%count albums") - * @param $options array (optional) Options array for key value pairs which are used - * for pluralization and interpolation. Special keys are "count" and "locale", - * the latter to override the currently configured locale. - * @return String The translated message string. - */ - public function translate($message, $options=array()) { - $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; - $count = isset($options['count']) ? $options['count'] : null; - $values = $options; - unset($values['locale']); - $this->log($message, $options); - - $entry = $this->lookup($locale, $message); - - if (null === $entry) { - // Default to the root locale. - $entry = $message; - $locale = $this->_config['root_locale']; - } - - $entry = $this->pluralize($locale, $entry, $count); - - $entry = $this->interpolate($locale, $entry, $values); - - return SafeString::of_safe_html($entry); - } - - private function lookup($locale, $message) { - if (!isset($this->_cache[$locale])) { - $this->_cache[$locale] = array(); - // TODO: Load data from locale file instead of the DB. - foreach (Database::instance() - ->select("key", "translation") - ->from("incoming_translations") - ->where(array("locale" => $locale)) - ->get() - ->as_array() as $row) { - $this->_cache[$locale][$row->key] = unserialize($row->translation); - } - - // Override incoming with outgoing... - foreach (Database::instance() - ->select("key", "translation") - ->from("outgoing_translations") - ->where(array("locale" => $locale)) - ->get() - ->as_array() as $row) { - $this->_cache[$locale][$row->key] = unserialize($row->translation); - } - } - - $key = self::get_message_key($message); - - if (isset($this->_cache[$locale][$key])) { - return $this->_cache[$locale][$key]; - } else { - return null; - } - } - - public function has_translation($message, $options=null) { - $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; - - $entry = $this->lookup($locale, $message); - - if (null === $entry) { - return false; - } else if (!is_array($message)) { - return $entry !== ''; - } else { - if (!is_array($entry) || empty($entry)) { - return false; - } - // It would be better to verify that all the locale's plural forms have a non-empty - // translation, but this is fine for now. - foreach ($entry as $value) { - if ($value === '') { - return false; - } - } - return true; - } - } - - static function get_message_key($message) { - $as_string = is_array($message) ? implode('|', $message) : $message; - return md5($as_string); - } - - static function is_plural_message($message) { - return is_array($message); - } - - private function interpolate($locale, $string, $key_values) { - // TODO: Handle locale specific number formatting. - - // Replace x_y before replacing x. - krsort($key_values, SORT_STRING); - - $keys = array(); - $values = array(); - foreach ($key_values as $key => $value) { - $keys[] = "%$key"; - $values[] = new SafeString($value); - } - return str_replace($keys, $values, $string); - } - - private function pluralize($locale, $entry, $count) { - if (!is_array($entry)) { - return $entry; - } - - $plural_key = self::get_plural_key($locale, $count); - if (!isset($entry[$plural_key])) { - // Fallback to the default plural form. - $plural_key = 'other'; - } - - if (isset($entry[$plural_key])) { - return $entry[$plural_key]; - } else { - // Fallback to just any plural form. - list ($plural_key, $string) = each($entry); - return $string; - } - } - - private function log($message, $options) { - $key = self::get_message_key($message); - isset($this->_call_log[$key]) or $this->_call_log[$key] = array($message, $options); - } - - public function call_log() { - return $this->_call_log; - } - - private static function get_plural_key($locale, $count) { - $parts = explode('_', $locale); - $language = $parts[0]; - - // Data from CLDR 1.6 (http://unicode.org/cldr/data/common/supplemental/plurals.xml). - // Docs: http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html - switch ($language) { - case 'az': - case 'fa': - case 'hu': - case 'ja': - case 'ko': - case 'my': - case 'to': - case 'tr': - case 'vi': - case 'yo': - case 'zh': - case 'bo': - case 'dz': - case 'id': - case 'jv': - case 'ka': - case 'km': - case 'kn': - case 'ms': - case 'th': - return 'other'; - - case 'ar': - if ($count == 0) { - return 'zero'; - } else if ($count == 1) { - return 'one'; - } else if ($count == 2) { - return 'two'; - } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 10) { - return 'few'; - } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 99) { - return 'many'; - } else { - return 'other'; - } - - case 'pt': - case 'am': - case 'bh': - case 'fil': - case 'tl': - case 'guw': - case 'hi': - case 'ln': - case 'mg': - case 'nso': - case 'ti': - case 'wa': - if ($count == 0 || $count == 1) { - return 'one'; - } else { - return 'other'; - } - - case 'fr': - if ($count >= 0 and $count < 2) { - return 'one'; - } else { - return 'other'; - } - - case 'lv': - if ($count == 0) { - return 'zero'; - } else if ($count % 10 == 1 && $count % 100 != 11) { - return 'one'; - } else { - return 'other'; - } - - case 'ga': - case 'se': - case 'sma': - case 'smi': - case 'smj': - case 'smn': - case 'sms': - if ($count == 1) { - return 'one'; - } else if ($count == 2) { - return 'two'; - } else { - return 'other'; - } - - case 'ro': - case 'mo': - if ($count == 1) { - return 'one'; - } else if (is_int($count) && $count == 0 && ($i = $count % 100) >= 1 && $i <= 19) { - return 'few'; - } else { - return 'other'; - } - - case 'lt': - if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { - return 'one'; - } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 9 && ($i = $count % 100) < 11 && $i > 19) { - return 'few'; - } else { - return 'other'; - } - - case 'hr': - case 'ru': - case 'sr': - case 'uk': - case 'be': - case 'bs': - case 'sh': - if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { - return 'one'; - } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && ($i = $count % 100) < 12 && $i > 14) { - return 'few'; - } else if (is_int($count) && ($count % 10 == 0 || (($i = $count % 10) >= 5 && $i <= 9) || (($i = $count % 100) >= 11 && $i <= 14))) { - return 'many'; - } else { - return 'other'; - } - - case 'cs': - case 'sk': - if ($count == 1) { - return 'one'; - } else if (is_int($count) && $count >= 2 && $count <= 4) { - return 'few'; - } else { - return 'other'; - } - - case 'pl': - if ($count == 1) { - return 'one'; - } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && - ($i = $count % 100) < 12 && $i > 14 && ($i = $count % 100) < 22 && $i > 24) { - return 'few'; - } else { - return 'other'; - } - - case 'sl': - if ($count % 100 == 1) { - return 'one'; - } else if ($count % 100 == 2) { - return 'two'; - } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 4) { - return 'few'; - } else { - return 'other'; - } - - case 'mt': - if ($count == 1) { - return 'one'; - } else if ($count == 0 || is_int($count) && ($i = $count % 100) >= 2 && $i <= 10) { - return 'few'; - } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 19) { - return 'many'; - } else { - return 'other'; - } - - case 'mk': - if ($count % 10 == 1) { - return 'one'; - } else { - return 'other'; - } - - case 'cy': - if ($count == 1) { - return 'one'; - } else if ($count == 2) { - return 'two'; - } else if ($count == 8 || $count == 11) { - return 'many'; - } else { - return 'other'; - } - - default: // en, de, etc. - return $count == 1 ? 'one' : 'other'; - } - } -} diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php index 9010606a..d0555cbf 100644 --- a/modules/gallery/tests/I18n_Test.php +++ b/modules/gallery/tests/I18n_Test.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class I18n_Test extends Unit_Test_Case { +class Gallery_I18n_Test extends Unit_Test_Case { private $i18n; public function setup() { @@ -26,7 +26,7 @@ class I18n_Test extends Unit_Test_Case { 'root_locale' => 'en', 'default_locale' => 'te_ST', 'locale_dir' => VARPATH . 'locale/'); - $this->i18n = I18n::instance($config); + $this->i18n = Gallery_I18n::instance($config); ORM::factory("incoming_translation") ->where("locale", "te_ST") @@ -43,7 +43,7 @@ class I18n_Test extends Unit_Test_Case { foreach ($messages_te_ST as $data) { list ($message, $translation) = $data; $entry = ORM::factory("incoming_translation"); - $entry->key = I18n::get_message_key($message); + $entry->key = Gallery_I18n::get_message_key($message); $entry->message = serialize($message); $entry->translation = serialize($translation); $entry->locale = 'te_ST'; -- cgit v1.2.3 From 01e10d1708c024dcf2471f35cd3fd7625f0ad5c9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:24:38 -0800 Subject: K2.4 has its own parentheses support --- modules/gallery/libraries/MY_Database.php | 38 +------------------------------ 1 file changed, 1 insertion(+), 37 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index c56f16e8..0f29c09b 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -17,45 +17,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Database extends Database_Core { +abstract class Database extends Database_Core { protected $_table_names; - public function open_paren() { - $this->where[] = "("; - return $this; - } - - public function close_paren() { - // Search backwards for the last opening paren and resolve it - $i = count($this->where) - 1; - $this->where[$i] .= ")"; - while (--$i >= 0) { - if ($this->where[$i] == "(") { - // Remove the paren from the where clauses, and add it to the right of the operator of the - // next where clause. If removing the paren makes the next where clause the first element - // in the where list, then the operator shouldn't be there. It's there because we - // calculate whether or not we need an operator based on the number of where clauses, and - // the open paren seems like a where clause even though it isn't. - array_splice($this->where, $i, 1); - $this->where[$i] = preg_replace("/^(AND|OR) /", $i ? "\\1 (" : "(", $this->where[$i]); - return $this; - } - } - - throw new Kohana_Database_Exception('database.missing_open_paren'); - } - - /** - * Parse the query string and convert any strings of the form `\([a-zA-Z0-9_]*?)\] - * table prefix . $1 - */ - public function query($sql = '') { - if (!empty($sql)) { - $sql = $this->add_table_prefixes($sql); - } - return parent::query($sql); - } - public function add_table_prefixes($sql) { $prefix = $this->config["table_prefix"]; if (strpos($sql, "SHOW TABLES") === 0) { -- cgit v1.2.3 From e201536d82d6ed49b7c4832f367a01029de05dd6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:25:14 -0800 Subject: K24 has separate log sinks, this configures the file based log sink --- modules/gallery/config/log_file.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 modules/gallery/config/log_file.php (limited to 'modules') diff --git a/modules/gallery/config/log_file.php b/modules/gallery/config/log_file.php new file mode 100644 index 00000000..3d3f8edd --- /dev/null +++ b/modules/gallery/config/log_file.php @@ -0,0 +1,11 @@ + Date: Wed, 25 Nov 2009 13:22:24 -0800 Subject: Preliminary work to cut over to Kohana 2.4 - Kohana::log() -> Kohana_Log::add() - Kohana::config_XXX -> Kohana_Config::instance()->XXX - Implement View::set_global in MY_View - Updated Cache_Database_Driver to latest APIs - ORM::$loaded -> ORM::loaded() - Updated item::viewable() to use K2.4 parenthesization --- modules/akismet/helpers/akismet.php | 4 +- modules/comment/controllers/admin_comments.php | 2 +- modules/comment/models/comment.php | 2 +- modules/comment/tests/Comment_Event_Test.php | 2 +- modules/digibug/controllers/digibug.php | 2 +- modules/exif/helpers/exif.php | 4 +- modules/g2_import/helpers/g2_import.php | 14 ++-- modules/g2_import/helpers/g2_import_task.php | 2 +- modules/gallery/controllers/admin_maintenance.php | 8 +- modules/gallery/controllers/albums.php | 3 +- modules/gallery/controllers/file_proxy.php | 6 +- modules/gallery/controllers/l10n_client.php | 6 +- modules/gallery/controllers/permissions.php | 2 +- modules/gallery/controllers/rest.php | 4 +- modules/gallery/controllers/simple_uploader.php | 2 +- modules/gallery/helpers/MY_url.php | 4 +- modules/gallery/helpers/access.php | 18 ++-- modules/gallery/helpers/album.php | 2 +- modules/gallery/helpers/auth.php | 2 +- modules/gallery/helpers/gallery_graphics.php | 2 +- modules/gallery/helpers/gallery_task.php | 2 +- modules/gallery/helpers/graphics.php | 2 +- modules/gallery/helpers/identity.php | 4 +- modules/gallery/helpers/item.php | 18 ++-- modules/gallery/helpers/l10n_client.php | 2 +- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/model_cache.php | 4 +- modules/gallery/helpers/module.php | 35 ++++---- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/helpers/site_status.php | 4 +- modules/gallery/helpers/task.php | 8 +- modules/gallery/helpers/theme.php | 2 +- modules/gallery/libraries/Admin_View.php | 2 +- modules/gallery/libraries/Gallery_I18n.php | 8 +- modules/gallery/libraries/Gallery_View.php | 6 +- modules/gallery/libraries/IdentityProvider.php | 4 +- modules/gallery/libraries/MY_ORM.php | 10 --- modules/gallery/libraries/MY_View.php | 27 +++++- modules/gallery/libraries/ORM_MPTT.php | 56 ++++++++----- modules/gallery/libraries/SafeString.php | 2 +- modules/gallery/libraries/Sendmail.php | 4 +- modules/gallery/libraries/Theme_View.php | 2 +- .../gallery/libraries/drivers/Cache/Database.php | 95 ++++++++++++---------- modules/gallery/models/item.php | 6 +- modules/gallery/models/log.php | 2 +- modules/gallery/tests/Access_Helper_Test.php | 8 +- modules/gallery/views/kohana_error_page.php | 2 +- modules/notification/helpers/notification.php | 2 +- .../notification/helpers/notification_event.php | 28 +++---- modules/search/helpers/search.php | 2 +- modules/server_add/controllers/server_add.php | 4 +- modules/tag/controllers/admin_tags.php | 8 +- modules/tag/helpers/tag.php | 2 +- modules/tag/helpers/tag_event.php | 2 +- modules/tag/helpers/tag_rss.php | 2 +- modules/user/controllers/admin_users.php | 2 +- modules/user/controllers/password.php | 2 +- modules/user/helpers/group.php | 4 +- modules/user/helpers/user.php | 4 +- modules/user/models/group.php | 2 +- modules/user/models/user.php | 2 +- modules/user/tests/User_Groups_Test.php | 4 +- 63 files changed, 257 insertions(+), 225 deletions(-) (limited to 'modules') diff --git a/modules/akismet/helpers/akismet.php b/modules/akismet/helpers/akismet.php index 43549ffa..46a305b2 100644 --- a/modules/akismet/helpers/akismet.php +++ b/modules/akismet/helpers/akismet.php @@ -166,7 +166,7 @@ class akismet_Core { } $response = ""; - Kohana::log("debug", "Send request\n" . print_r($http_request, 1)); + Kohana_Log::add("debug", "Send request\n" . print_r($http_request, 1)); if (false !== ($fs = @fsockopen($host, 80, $errno, $errstr, 5))) { fwrite($fs, $http_request); while ( !feof($fs) ) { @@ -181,7 +181,7 @@ class akismet_Core { } else { throw new Exception("@todo CONNECTION TO SPAM SERVICE FAILED"); } - Kohana::log("debug", "Received response\n" . print_r($response, 1)); + Kohana_Log::add("debug", "Received response\n" . print_r($response, 1)); return $response; } diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 13532c4e..1a9f0e6a 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -110,7 +110,7 @@ class Admin_Comments_Controller extends Admin_Controller { $comment = ORM::factory("comment", $id); $orig = clone $comment; - if ($comment->loaded) { + if ($comment->loaded()) { $comment->state = $state; $comment->save(); } diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index bb9b8833..59b85233 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -59,7 +59,7 @@ class Comment_Model extends ORM { public function save() { if (!empty($this->changed)) { $this->updated = time(); - if (!$this->loaded && empty($this->created)) { + if (!$this->loaded() && empty($this->created)) { $this->created = $this->updated; $created = true; } diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php index f650cabf..ff7f1c26 100644 --- a/modules/comment/tests/Comment_Event_Test.php +++ b/modules/comment/tests/Comment_Event_Test.php @@ -27,6 +27,6 @@ class Comment_Event_Test extends Unit_Test_Case { $album->delete(); $deleted_comment = ORM::factory("comment", $comment->id); - $this->assert_false($deleted_comment->loaded); + $this->assert_false($deleted_comment->loaded()); } } diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 1bb2691b..cef42b2d 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -81,7 +81,7 @@ class Digibug_Controller extends Controller { } $proxy = ORM::factory("digibug_proxy", array("uuid" => $id)); - if (!$proxy->loaded || !$proxy->item->loaded) { + if (!$proxy->loaded() || !$proxy->item->loaded()) { Kohana::show_404(); } diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index 5ddd09d4..b6a55679 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -74,7 +74,7 @@ class exif_Core { $item->save(); $record = ORM::factory("exif_record")->where("item_id", $item->id)->find(); - if (!$record->loaded) { + if (!$record->loaded()) { $record->item_id = $item->id; } $record->data = serialize($keys); @@ -88,7 +88,7 @@ class exif_Core { $record = ORM::factory("exif_record") ->where("item_id", $item->id) ->find(); - if (!$record->loaded) { + if (!$record->loaded()) { return array(); } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 202a0e92..1e835a59 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -458,7 +458,7 @@ class g2_import_Core { switch ($g2_type) { case "GalleryPhotoItem": if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) { - Kohana::log("alert", "$g2_path is an unsupported image type; using a placeholder gif"); + Kohana_Log::add("alert", "$g2_path is an unsupported image type; using a placeholder gif"); $message[] = t("'%path' is an unsupported image type, using a placeholder", array("path" => $g2_path)); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; @@ -473,7 +473,7 @@ class g2_import_Core { self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { - Kohana::log( + Kohana_Log::add( "alert", "Corrupt image $g2_path\n" . $e->__toString()); $message[] = t("Corrupt image '%path'", array("path" => $g2_path)); $message[] = $e->__toString(); @@ -493,13 +493,13 @@ class g2_import_Core { self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { - Kohana::log("alert", "Corrupt movie $g2_path\n" . $e->__toString()); + Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . $e->__toString()); $message[] = t("Corrupt movie '%path'", array("path" => $g2_path)); $message[] = $e->__toString(); $corrupt = 1; } } else { - Kohana::log("alert", "$g2_path is an unsupported movie type"); + Kohana_Log::add("alert", "$g2_path is an unsupported movie type"); $message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path)); $corrupt = 1; } @@ -868,7 +868,7 @@ class g2_import_Core { static function map($g2_id) { if (!array_key_exists($g2_id, self::$map)) { $g2_map = ORM::factory("g2_map")->where("g2_id", $g2_id)->find(); - self::$map[$g2_id] = $g2_map->loaded ? $g2_map->g3_id : null; + self::$map[$g2_id] = $g2_map->loaded() ? $g2_map->g3_id : null; } return self::$map[$g2_id]; @@ -887,7 +887,7 @@ class g2_import_Core { static function log($msg) { message::warning($msg); - Kohana::log("alert", $msg); + Kohana_Log::add("alert", $msg); } } @@ -906,7 +906,7 @@ function g2() { $args = func_get_arg(0); $ret = array_shift($args); if ($ret) { - Kohana::log("error", "Gallery 2 call failed with: " . $ret->getAsText()); + Kohana_Log::add("error", "Gallery 2 call failed with: " . $ret->getAsText()); throw new Exception("@todo G2_FUNCTION_FAILED"); } if (count($args) == 1) { diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index 47a205bd..fef0d186 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -66,7 +66,7 @@ class g2_import_task_Core { $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId()); $root = ORM::factory("g2_map")->where("g2_id", $root_g2_id)->find(); - if (!$root->loaded) { + if (!$root->loaded()) { $root->g2_id = $root_g2_id; $root->g3_id = 1; $root->save(); diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 66bcce55..fe5059e7 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -75,7 +75,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } $view = new View("admin_maintenance_task.html"); @@ -97,7 +97,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } $view = new View("admin_maintenance_show_log.html"); @@ -114,7 +114,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } @@ -184,7 +184,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { try { $task = task::run($task_id); } catch (Exception $e) { - Kohana::log( + Kohana_Log::add( "error", sprintf( "%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(), diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index e67df6f6..cc63d43f 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -66,6 +66,7 @@ class Albums_Controller extends Items_Controller { $template = new Theme_View("page.html", "collection", "album"); $template->set_global("page", $page); + $template->set_global("page_title", null); $template->set_global("max_pages", $max_pages); $template->set_global("page_size", $page_size); $template->set_global("item", $album); @@ -76,7 +77,7 @@ class Albums_Controller extends Items_Controller { // We can't use math in ORM or the query builder, so do this by hand. It's important // that we do this with math, otherwise concurrent accesses will damage accuracy. - Database::instance()->query( + db::query( "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id"); print $template; diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index acfd6eb9..11d858c0 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -58,7 +58,7 @@ class File_Proxy_Controller extends Controller { // We now have the relative path to the item. Search for it in the path cache $item = ORM::factory("item")->where("relative_path_cache", $path)->find(); - if (!$item->loaded) { + if (!$item->loaded()) { // We didn't turn it up. It's possible that the relative_path_cache is out of date here. // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be // necessary, it's easily resurrected. @@ -70,14 +70,14 @@ class File_Proxy_Controller extends Controller { foreach (array("flv", "mp4") as $ext) { $movie_path = preg_replace('/.jpg$/', ".$ext", $path); $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find(); - if ($item->loaded) { + if ($item->loaded()) { break; } } } } - if (!$item->loaded) { + if (!$item->loaded()) { kohana::show_404(); } diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 3801e6aa..2eda741c 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -33,7 +33,7 @@ class L10n_Client_Controller extends Controller { "locale" => "root")) ->find(); - if (!$root_message->loaded) { + if (!$root_message->loaded()) { throw new Exception("@todo bad request data / illegal state"); } $is_plural = Gallery_I18n::is_plural_message(unserialize($root_message->message)); @@ -60,7 +60,7 @@ class L10n_Client_Controller extends Controller { "locale" => $locale)) ->find(); - if (!$entry->loaded) { + if (!$entry->loaded()) { $entry->key = $key; $entry->locale = $locale; $entry->message = $root_message->message; @@ -74,7 +74,7 @@ class L10n_Client_Controller extends Controller { "locale" => $locale)) ->find(); - if (!$entry_from_incoming->loaded) { + if (!$entry_from_incoming->loaded()) { $entry->base_revision = $entry_from_incoming->revision; } diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 99943fbb..e03f41a9 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -57,7 +57,7 @@ class Permissions_Controller extends Controller { access::required("view", $item); access::required("edit", $item); - if (!empty($group) && $perm->loaded && $item->loaded) { + if (!empty($group) && $perm->loaded() && $item->loaded()) { switch($command) { case "allow": access::allow($group, $perm->name, $item); diff --git a/modules/gallery/controllers/rest.php b/modules/gallery/controllers/rest.php index 2edf079f..087f2c29 100644 --- a/modules/gallery/controllers/rest.php +++ b/modules/gallery/controllers/rest.php @@ -82,7 +82,7 @@ class REST_Controller extends Controller { } $resource = ORM::factory($this->resource_type, (int)$function); - if (!$resource->loaded && $request_method != "post") { + if (!$resource->loaded() && $request_method != "post") { return Kohana::show_404(); } @@ -111,7 +111,7 @@ class REST_Controller extends Controller { } $resource = ORM::factory($this->resource_type, $resource_id); - if (!$resource->loaded) { + if (!$resource->loaded()) { return Kohana::show_404(); } diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php index 37753ff3..5d32e35f 100644 --- a/modules/gallery/controllers/simple_uploader.php +++ b/modules/gallery/controllers/simple_uploader.php @@ -72,7 +72,7 @@ class Simple_Uploader_Controller extends Controller { module::event("add_photos_form_completed", $item, $form); } } catch (Exception $e) { - Kohana::log("alert", $e->__toString()); + Kohana_Log::add("alert", $e->__toString()); if (file_exists($temp_filename)) { unlink($temp_filename); } diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index 368c947e..e5eefad7 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -32,7 +32,7 @@ class url extends url_Core { } $item = self::get_item_from_uri(Router::$current_uri); - if ($item && $item->loaded) { + if ($item && $item->loaded()) { Router::$controller = "{$item->type}s"; Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php"; Router::$method = $item->id; @@ -51,7 +51,7 @@ class url extends url_Core { // but failing that, walk down the tree until we find it. The fallback code will fix caches // as it goes, so it'll never be run frequently. $item = ORM::factory("item")->where("relative_url_cache", $current_uri)->find(); - if (!$item->loaded) { + if (!$item->loaded()) { $count = count(Router::$segments); foreach (ORM::factory("item") ->where("slug", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index c1c1f9d1..9d27181a 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -91,7 +91,7 @@ class access_Core { * @return boolean */ static function user_can($user, $perm_name, $item) { - if (!$item->loaded) { + if (!$item->loaded()) { return false; } @@ -101,7 +101,7 @@ class access_Core { $resource = $perm_name == "view" ? $item : model_cache::get("access_cache", $item->id, "item_id"); - foreach ($user->groups as $group) { + foreach ($user->groups->find_all() as $group) { if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) { return true; } @@ -175,7 +175,7 @@ class access_Core { ->limit(1) ->find(); - if ($lock->loaded) { + if ($lock->loaded()) { return $lock; } else { return null; @@ -201,7 +201,7 @@ class access_Core { if (!($group instanceof Group_Definition)) { throw new Exception("@todo PERMISSIONS_ONLY_WORK_ON_GROUPS"); } - if (!$album->loaded) { + if (!$album->loaded()) { throw new Exception("@todo INVALID_ALBUM $album->id"); } if (!$album->is_album()) { @@ -282,7 +282,7 @@ class access_Core { */ static function register_permission($name, $display_name) { $permission = ORM::factory("permission", $name); - if ($permission->loaded) { + if ($permission->loaded()) { throw new Exception("@todo PERMISSION_ALREADY_EXISTS $name"); } $permission->name = $name; @@ -305,7 +305,7 @@ class access_Core { self::_drop_columns($name, $group); } $permission = ORM::factory("permission")->where("name", $name)->find(); - if ($permission->loaded) { + if ($permission->loaded()) { $permission->delete(); } } @@ -342,7 +342,7 @@ class access_Core { */ static function add_item($item) { $access_intent = ORM::factory("access_intent", $item->id); - if ($access_intent->loaded) { + if ($access_intent->loaded()) { throw new Exception("@todo ITEM_ALREADY_ADDED $item->id"); } $access_intent = ORM::factory("access_intent"); @@ -497,7 +497,7 @@ class access_Core { ->orderby("left_ptr", "DESC") ->limit(1) ->find(); - if ($tmp_item->loaded) { + if ($tmp_item->loaded()) { $item = $tmp_item; } } @@ -568,7 +568,7 @@ class access_Core { ->orderby("left_ptr", "DESC") ->limit(1) ->find(); - if ($tmp_item->loaded) { + if ($tmp_item->loaded()) { $item = $tmp_item; } } diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 72a79a75..c82a5509 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -34,7 +34,7 @@ class album_Core { * @return Item_Model */ static function create($parent, $name, $title, $description=null, $owner_id=null, $slug=null) { - if (!$parent->loaded || !$parent->is_album()) { + if (!$parent->loaded() || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php index 9c69cecd..21a39bfb 100644 --- a/modules/gallery/helpers/auth.php +++ b/modules/gallery/helpers/auth.php @@ -46,7 +46,7 @@ class auth_Core { try { Session::instance()->destroy(); } catch (Exception $e) { - Kohana::log("error", $e); + Kohana_Log::add("error", $e); } module::event("user_logout", $user); } diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php index c24d2bde..ce08bbd7 100644 --- a/modules/gallery/helpers/gallery_graphics.php +++ b/modules/gallery/helpers/gallery_graphics.php @@ -123,7 +123,7 @@ class gallery_graphics_Core { module::event("graphics_composite_completed", $input_file, $output_file, $options); } catch (ErrorException $e) { - Kohana::log("error", $e->get_message()); + Kohana_Log::add("error", $e->get_message()); } } } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index e0b03682..4d6de3ba 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -66,7 +66,7 @@ class gallery_task_Core { } $item = ORM::factory("item", $row->id); - if ($item->loaded) { + if ($item->loaded()) { try { graphics::generate($item); $completed++; diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index d6a2f00c..a78cadd0 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -171,7 +171,7 @@ class graphics_Core { } catch (Exception $e) { // Something went wrong rebuilding the image. Leave it dirty and move on. // @todo we should handle this better. - Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" . + Kohana_Log::add("error", "Caught exception rebuilding image: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); throw $e; } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php index 72e3312d..05614559 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -75,14 +75,14 @@ class identity_Core { if (!$session->get("group_ids")) { $ids = array(); - foreach ($user->groups as $group) { + foreach ($user->groups->find_all() as $group) { $ids[] = $group->id; } $session->set("group_ids", $ids); } } catch (Exception $e) { // Log it, so we at least have so notification that we swallowed the exception. - Kohana::log("error", "Load_user Exception: " . $e->__toString()); + Kohana_Log::add("error", "Load_user Exception: " . $e->__toString()); try { Session::instance()->destroy(); } catch (Exception $e) { diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 8f96c3d9..109fa6f8 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -156,13 +156,7 @@ class item_Core { $view_restrictions = array(); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { - // Separate the first restriction from the rest to make it easier for us to formulate - // our where clause below - if (empty($view_restrictions)) { - $view_restrictions[0] = "items.view_$id"; - } else { - $view_restrictions[1]["items.view_$id"] = access::ALLOW; - } + $view_restrictions[] = "items.view_$id"; } } switch (count($view_restrictions)) { @@ -170,14 +164,14 @@ class item_Core { break; case 1: - $model->where($view_restrictions[0], access::ALLOW); + $model->where($view_restrictions[0], "=", access::ALLOW); break; default: - $model->open_paren(); - $model->where($view_restrictions[0], access::ALLOW); - $model->orwhere($view_restrictions[1]); - $model->close_paren(); + $model + ->and_open() + ->or_where($view_restrictions, "=", access::ALLOW) + ->close(); break; } diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 3460cc65..aaf6ff46 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -136,7 +136,7 @@ class l10n_client_Core { $entry = ORM::factory("incoming_translation") ->where(array("key" => $key, "locale" => $locale)) ->find(); - if (!$entry->loaded) { + if (!$entry->loaded()) { // @todo Load a message key -> message (text) dict into memory outside of this loop $root_entry = ORM::factory("incoming_translation") ->where(array("key" => $key, "locale" => "root")) diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index e36d419d..6c09a686 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -43,7 +43,7 @@ class l10n_scanner_Core { } $entry = ORM::factory("incoming_translation", array("key" => $key)); - if (!$entry->loaded) { + if (!$entry->loaded()) { $entry->key = $key; $entry->message = serialize($message); $entry->locale = "root"; diff --git a/modules/gallery/helpers/model_cache.php b/modules/gallery/helpers/model_cache.php index a3e09862..302e42d9 100644 --- a/modules/gallery/helpers/model_cache.php +++ b/modules/gallery/helpers/model_cache.php @@ -22,8 +22,8 @@ class model_cache_Core { static function get($model_name, $id, $field_name="id") { if (TEST_MODE || empty(self::$cache->$model_name->$field_name->$id)) { - $model = ORM::factory($model_name)->where($field_name, $id)->find(); - if (!$model->loaded) { + $model = ORM::factory($model_name)->where($field_name, "=", $id)->find(); + if (!$model->loaded()) { throw new Exception("@todo MISSING_MODEL $model_name:$id"); } self::$cache->$model_name->$field_name->$id = $model; diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index e6c196ce..e54a4352 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -36,13 +36,13 @@ class module_Core { */ static function set_version($module_name, $version) { $module = self::get($module_name); - if (!$module->loaded) { + if (!$module->loaded()) { $module->name = $module_name; $module->active = $module_name == "gallery"; // only gallery is active by default } $module->version = $version; $module->save(); - Kohana::log("debug", "$module_name: version is now $version"); + Kohana_Log::add("debug", "$module_name: version is now $version"); } /** @@ -126,9 +126,10 @@ class module_Core { * @param string $module_name */ static function install($module_name) { - $kohana_modules = Kohana::config("core.modules"); + $config = Kohana_Config::instance(); + $kohana_modules = $config->get("core.modules"); array_unshift($kohana_modules, MODPATH . $module_name); - Kohana::config_set("core.modules", $kohana_modules); + $config->set("core.modules", $kohana_modules); // Rebuild the include path so the module installer can benefit from auto loading Kohana::include_paths(true); @@ -142,7 +143,7 @@ class module_Core { // Now the module is installed but inactive, so don't leave it in the active path array_shift($kohana_modules); - Kohana::config_set("core.modules", $kohana_modules); + $config->set("core.modules", $kohana_modules); log::success( "module", t("Installed module %module_name", array("module_name" => $module_name))); @@ -193,9 +194,10 @@ class module_Core { * @param string $module_name */ static function activate($module_name) { - $kohana_modules = Kohana::config("core.modules"); + $config = Kohana_Config::instance(); + $kohana_modules = $config->get("core.modules"); array_unshift($kohana_modules, MODPATH . $module_name); - Kohana::config_set("core.modules", $kohana_modules); + $config->set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "activate")) { @@ -203,7 +205,7 @@ class module_Core { } $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->active = true; $module->save(); } @@ -230,7 +232,7 @@ class module_Core { } $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->active = false; $module->save(); } @@ -257,7 +259,7 @@ class module_Core { graphics::remove_rules($module_name); $module = self::get($module_name); - if ($module->loaded) { + if ($module->loaded()) { $module->delete(); } module::load_modules(); @@ -290,8 +292,9 @@ class module_Core { } } self::$active[] = $gallery; // put gallery last in the module list to match core.modules - Kohana::config_set( - "core.modules", array_merge($kohana_modules, Kohana::config("core.modules"))); + $config = Kohana_Config::instance(); + $config->set( + "core.modules", array_merge($kohana_modules, $config->get("core.modules"))); } /** @@ -348,11 +351,11 @@ class module_Core { // We cache all vars in gallery._cache so that we can load all vars at once for // performance. if (empty(self::$var_cache)) { - $row = Database::instance() + $row = db::build() ->select("value") ->from("vars") ->where(array("module_name" => "gallery", "name" => "_cache")) - ->get() + ->execute() ->current(); if ($row) { self::$var_cache = unserialize($row->value); @@ -395,7 +398,7 @@ class module_Core { ->where("module_name", $module_name) ->where("name", $name) ->find(); - if (!$var->loaded) { + if (!$var->loaded()) { $var->module_name = $module_name; $var->name = $name; } @@ -432,7 +435,7 @@ class module_Core { ->where("module_name", $module_name) ->where("name", $name) ->find(); - if ($var->loaded) { + if ($var->loaded()) { $var->delete(); } diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index e84e8ea6..a319471d 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -36,7 +36,7 @@ class movie_Core { */ static function create($parent, $filename, $name, $title, $description=null, $owner_id=null, $slug=null) { - if (!$parent->loaded || !$parent->is_album()) { + if (!$parent->loaded() || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 01cf5278..90cb108f 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -36,7 +36,7 @@ class photo_Core { */ static function create($parent, $filename, $name, $title, $description=null, $owner_id=null, $slug=null) { - if (!$parent->loaded || !$parent->is_album()) { + if (!$parent->loaded() || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index 2b090776..d58b935d 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -69,7 +69,7 @@ class site_status_Core { $message = ORM::factory("message") ->where("key", $permanent_key) ->find(); - if (!$message->loaded) { + if (!$message->loaded()) { $message->key = $permanent_key; } $message->severity = $severity; @@ -83,7 +83,7 @@ class site_status_Core { */ static function clear($permanent_key) { $message = ORM::factory("message")->where("key", $permanent_key)->find(); - if ($message->loaded) { + if ($message->loaded()) { $message->delete(); } } diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index dac5f9d3..4aa95f33 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -51,7 +51,7 @@ class task_Core { static function cancel($task_id) { $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } $task->done = 1; @@ -65,14 +65,14 @@ class task_Core { static function remove($task_id) { $task = ORM::factory("task", $task_id); - if ($task->loaded) { + if ($task->loaded()) { $task->delete(); } } static function run($task_id) { $task = ORM::factory("task", $task_id); - if (!$task->loaded) { + if (!$task->loaded()) { throw new Exception("@todo MISSING_TASK"); } @@ -84,7 +84,7 @@ class task_Core { } $task->save(); } catch (Exception $e) { - Kohana::log("error", $e->__toString()); + Kohana_Log::add("error", $e->__toString()); $task->log($e->__toString()); $task->state = "error"; $task->done = true; diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 16ed104e..c7a9b49a 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -43,7 +43,7 @@ class theme_Core { } $modules = Kohana::config("core.modules"); array_unshift($modules, THEMEPATH . $theme_name); - Kohana::config_set("core.modules", $modules); + Kohana_Config::instance()->set("core.modules", $modules); } static function get_edit_form_admin() { diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index cbb781a1..c190f110 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -31,7 +31,7 @@ class Admin_View_Core extends Gallery_View { if (!file_exists(THEMEPATH . $theme_name)) { module::set_var("gallery", "active_admin_theme", "admin_wind"); theme::load_themes(); - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); + Kohana_Log::add("error", "Unable to locate theme '$theme_name', switching to default theme."); } parent::__construct($name); diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php index 0571fe58..42fae266 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -128,21 +128,21 @@ class Gallery_I18n_Core { if (!isset($this->_cache[$locale])) { $this->_cache[$locale] = array(); // TODO: Load data from locale file instead of the DB. - foreach (Database::instance() + foreach (db::build() ->select("key", "translation") ->from("incoming_translations") ->where(array("locale" => $locale)) - ->get() + ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); } // Override incoming with outgoing... - foreach (Database::instance() + foreach (db::build() ->select("key", "translation") ->from("outgoing_translations") ->where(array("locale" => $locale)) - ->get() + ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); } diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 3bf56d0f..940c5321 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -32,7 +32,7 @@ class Gallery_View_Core extends View { if (($path = gallery::find_file("js", $file, false))) { $this->scripts[$path] = 1; } else { - Kohana::log("error", "Can't find script file: $file"); + Kohana_Log::add("error", "Can't find script file: $file"); } } @@ -55,7 +55,7 @@ class Gallery_View_Core extends View { if (($path = gallery::find_file("css", $file, false))) { $this->css[$path] = 1; } else { - Kohana::log("error", "Can't find css file: $file"); + Kohana_Log::add("error", "Can't find css file: $file"); } } @@ -130,7 +130,7 @@ class Gallery_View_Core extends View { $search[] = $match[0]; $replace[] = "url('" . url::abs_file($relative) . "')"; } else { - Kohana::log("error", "Missing URL reference '{$match[1]}' in CSS file '$css_file'"); + Kohana_Log::add("error", "Missing URL reference '{$match[1]}' in CSS file '$css_file'"); } } $replace = str_replace(DIRECTORY_SEPARATOR, "/", $replace); diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index e213ae97..bcb3056a 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -54,7 +54,7 @@ class IdentityProvider_Core { */ static function reset() { self::$instance = null; - Kohana::config_clear("identity"); + Kohana_Config::instance()->clear("identity"); } /** @@ -90,7 +90,7 @@ class IdentityProvider_Core { get_class($this), "IdentityProvider_Driver"); } - Kohana::log("debug", "Identity Library initialized"); + Kohana_Log::add("debug", "Identity Library initialized"); } /** diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 2c9ad1d7..56c776aa 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -21,16 +21,6 @@ class ORM extends ORM_Core { // Track the original value of this ORM so that we can look it up in ORM::original() protected $original = null; - public function open_paren() { - $this->db->open_paren(); - return $this; - } - - public function close_paren() { - $this->db->close_paren(); - return $this; - } - public function save() { model_cache::clear(); $result = parent::save(); diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index eb55aca6..0311f2dd 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -18,6 +18,31 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class View extends View_Core { + static $global_data; + + /** + * Reimplement Kohana 2.3's View::set_global() functionality. + */ + public function set_global($key, $value) { + View::$global_data->$key = $value; + $this->$key = $value; + } + + public function __isset($key) { + if (isset(View::$global_data->$key)) { + return true; + } + return parent::__isset($key); + } + + public function &__get($key) { + Kohana_Log::add("error",print_r("__get($key)",1)); + if (isset(View::$global_data->$key)) { + return View::$global_data->$key; + } + return parent::__get($key); + } + /** * Override View_Core::__construct so that we can set the csrf value into all views. * @@ -38,7 +63,7 @@ class View extends View_Core { try { return parent::render($print, $renderer); } catch (Exception $e) { - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); return ""; } } diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 83d2445c..01b2d7b7 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -133,10 +133,10 @@ class ORM_MPTT_Core extends ORM { */ function parents() { return $this - ->where("`left_ptr` <= {$this->left_ptr}") - ->where("`right_ptr` >= {$this->right_ptr}") - ->where("id <> {$this->id}") - ->orderby("left_ptr", "ASC") + ->where("left_ptr", "<=", $this->left_ptr) + ->where("right_ptr", ">=", $this->right_ptr) + ->where("id", "<>", $this->id) + ->order_by("left_ptr", "ASC") ->find_all(); } @@ -147,14 +147,17 @@ class ORM_MPTT_Core extends ORM { * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses - * @param array orderby + * @param array order_by * @return array ORM */ - function children($limit=null, $offset=0, $where=array(), $orderby=array("id" => "ASC")) { + function children($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + if ($where) { + $this->where($where); + } + return $this - ->where("parent_id", $this->id) - ->where($where) - ->orderby($orderby) + ->where("parent_id", "=", $this->id) + ->order_by($order_by) ->find_all($limit, $offset); } @@ -165,10 +168,13 @@ class ORM_MPTT_Core extends ORM { * @param array additional where clauses * @return array ORM */ - function children_count($where=array()) { + function children_count($where=null) { + if ($where) { + $this->where($where); + } + return $this - ->where($where) - ->where("parent_id", $this->id) + ->where("parent_id", "=", $this->id) ->count_all(); } @@ -178,15 +184,18 @@ class ORM_MPTT_Core extends ORM { * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses - * @param array orderby + * @param array order_by * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=array(), $orderby=array("id" => "ASC")) { + function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + if ($where) { + $this->where($where); + } + return $this - ->where("left_ptr >", $this->left_ptr) - ->where("right_ptr <=", $this->right_ptr) - ->where($where) - ->orderby($orderby) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<=", $this->right_ptr) + ->order_by($order_by) ->find_all($limit, $offset); } @@ -196,11 +205,14 @@ class ORM_MPTT_Core extends ORM { * @param array additional where clauses * @return integer child count */ - function descendants_count($where=array()) { + function descendants_count($where=null) { + if ($where) { + $this->where($where); + } + return $this - ->where("left_ptr >", $this->left_ptr) - ->where("right_ptr <=", $this->right_ptr) - ->where($where) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<=", $this->right_ptr) ->count_all(); } diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php index ba3a8ffd..cc63f3a7 100644 --- a/modules/gallery/libraries/SafeString.php +++ b/modules/gallery/libraries/SafeString.php @@ -146,7 +146,7 @@ class SafeString_Core { * Escape special HTML chars ("<", ">", "&", etc.) to HTML entities. */ private static function _escape_for_html($dirty_html) { - return html::specialchars($dirty_html); + return html::chars($dirty_html); } /** diff --git a/modules/gallery/libraries/Sendmail.php b/modules/gallery/libraries/Sendmail.php index 7bc21a67..aa2b51a9 100644 --- a/modules/gallery/libraries/Sendmail.php +++ b/modules/gallery/libraries/Sendmail.php @@ -52,7 +52,7 @@ class Sendmail_Core { break; case "header": if (count($value) != 2) { - Kohana::log("error", wordwrap("Invalid header parameters\n" . Kohana::debug($value))); + Kohana_Log::add("error", wordwrap("Invalid header parameters\n" . Kohana::debug($value))); throw new Exception("@todo INVALID_HEADER_PARAMETERS"); } $this->headers[$value[0]] = $value[1]; @@ -71,7 +71,7 @@ class Sendmail_Core { public function send() { if (empty($this->to)) { - Kohana::log("error", wordwrap("Sending mail failed:\nNo to address specified")); + Kohana_Log::add("error", wordwrap("Sending mail failed:\nNo to address specified")); throw new Exception("@todo TO_IS_REQUIRED_FOR_MAIL"); } $to = implode(", ", $this->to); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index b64deab9..03f67671 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -33,7 +33,7 @@ class Theme_View_Core extends Gallery_View { if (!file_exists(THEMEPATH . $theme_name)) { module::set_var("gallery", "active_site_theme", "wind"); theme::load_themes(); - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); + Kohana_Log::add("error", "Unable to locate theme '$theme_name', switching to default theme."); } parent::__construct($name); diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 7e2aeabc..d27bcc32 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -20,22 +20,10 @@ /* * Based on the Cache_Sqlite_Driver developed by the Kohana Team */ -class Cache_Database_Driver implements Cache_Driver { +class Cache_Database_Driver extends Cache_Driver { // Kohana database instance protected $db; - /** - * Tests that the storage location is a directory and is writable. - */ - public function __construct() { - // Open up an instance of the database - $this->db = Database::instance(); - - if (!$this->db->table_exists("caches")) { - throw new Exception("@todo Cache table is not defined"); - } - } - /** * Checks if a cache id is already set. * @@ -43,20 +31,22 @@ class Cache_Database_Driver implements Cache_Driver { * @return boolean */ public function exists($id) { - $count = $this->db->count_records("caches", array("key" => $id, "expiration >=" => time())); + $count = db::build() + ->where("key", "=", $id) + ->where("expiration", ">=", "time()") + ->count_records("caches"); return $count > 0; } /** * Sets a cache item to the given data, tags, and lifetime. * - * @param string cache id to set - * @param string data in the cache + * @param array assoc array of key => value pairs * @param array cache tags * @param integer lifetime * @return bool */ - public function set($id, $data, array $tags = NULL, $lifetime) { + public function set($items, $tags=null, $lifetime=null) { if (!empty($tags)) { // Escape the tags, adding brackets so the tag can be explicitly matched $tags = "<" . implode(">,<", $tags) . ">"; @@ -69,46 +59,46 @@ class Cache_Database_Driver implements Cache_Driver { $lifetime += time(); } - if ($this->exists($id)) { - $status = $this->db->update( - "caches", - array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), array("key" => $id)); - } else { - $status = $this->db->insert( - "caches", - array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data))); + foreach ($items as $id => $data) { + if ($this->exists($id)) { + $status = db::build()->update( + "caches", + array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), + array("key", "=", $id)); + } else { + $status = db::build()->insert( + "caches", + array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data))); + } } - return count($status) > 0; + return true; } /** - * Finds an array of ids for a given tag. - * - * @param string tag name - * @return array of ids that match the tag + * Get cache items by tag + * @param array cache tags + * @return array cached data */ - public function find($tag) { - $db_result = $this->db->from("caches") - ->like("tags", "<$tag>") - ->get() - ->result(true); + public function get_tag($tags) { + $db = db::build()->from("caches"); + foreach ($tags as $tag) { + $db->where("tags", "like", "<$tag>"); + } + $db_result = $db->execute()->as_array(); // An array will always be returned $result = array(); + // Disable notices for unserializing + $ER = error_reporting(~E_NOTICE); if ($db_result->count() > 0) { - // Disable notices for unserializing - $ER = error_reporting(~E_NOTICE); - foreach ($db_result as $row) { // Add each cache to the array $result[$row->key] = unserialize($row->cache); } - - // Turn notices back on - error_reporting($ER); } + error_reporting($ER); return $result; } @@ -120,9 +110,13 @@ class Cache_Database_Driver implements Cache_Driver { * @param string cache id * @return mixed|NULL */ - public function get($id) { + public function get($keys, $single=false) { $data = null; - $result = $this->db->getwhere("caches", array("key" => $id)); + $result = db::build() + ->from("caches") + ->where("key", "IN", $keys) + ->select() + ->execute(); if (count($result) > 0) { $cache = $result->current(); @@ -168,6 +162,13 @@ class Cache_Database_Driver implements Cache_Driver { return count($status) > 0; } + /** + * Delete cache items by tag + */ + public function delete_tag($tags) { + return $this->delete($tags, true); + } + /** * Deletes all cache files that are older than the current time. */ @@ -180,4 +181,10 @@ class Cache_Database_Driver implements Cache_Driver { return count($status) > 0; } -} // End Cache Database Driver \ No newline at end of file + /** + * Empty the cache + */ + public function delete_all() { + db::build()->query("TRUNCATE {caches}"); + } +} \ No newline at end of file diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index d27e331b..bd1f9af5 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -309,7 +309,7 @@ class Item_Model extends ORM_MPTT { * @return string */ public function relative_path() { - if (!$this->loaded) { + if (!$this->loaded()) { return; } @@ -324,7 +324,7 @@ class Item_Model extends ORM_MPTT { * @return string */ public function relative_url() { - if (!$this->loaded) { + if (!$this->loaded()) { return; } @@ -383,7 +383,7 @@ class Item_Model extends ORM_MPTT { if (!empty($this->changed) && $significant_changes) { $this->updated = time(); - if (!$this->loaded) { + if (!$this->loaded()) { $this->created = $this->updated; $this->weight = item::get_max_weight(); } else { diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php index c816a4a7..a2044325 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -28,7 +28,7 @@ class Log_Model extends ORM { try { return identity::lookup_user($this->user_id); } catch (Exception $e) { - Kohana::log("alert", "Unable to load user with id $this->user_id"); + Kohana_Log::add("alert", "Unable to load user with id $this->user_id"); return null; } } else { diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index e9e5cb26..d90d7ed6 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -106,15 +106,15 @@ class Access_Helper_Test extends Unit_Test_Case { $item = album::create($root, rand(), "test album"); // New rows exist - $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded); - $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded); + $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); + $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); // Delete the item $item->delete(); // Rows are gone - $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded); - $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded); + $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); + $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); } public function new_photos_inherit_parent_permissions_test() { diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php index 0d8801e5..b9fdcc19 100644 --- a/modules/gallery/views/kohana_error_page.php +++ b/modules/gallery/views/kohana_error_page.php @@ -120,7 +120,7 @@ getTraceAsString(); ?> - + diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 9a40b0b9..d525e03e 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -38,7 +38,7 @@ class notification { ->where("item_id", $item->id) ->where("user_id", $user->id) ->find() - ->loaded; + ->loaded(); } static function add_watch($item, $user=null) { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 6b2df574..e6d09d74 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -25,8 +25,8 @@ class notification_event_Core { try { notification::send_item_updated($new); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::item_updated() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::item_updated() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -34,8 +34,8 @@ class notification_event_Core { try { notification::send_item_add($item); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::item_created() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::item_created() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -47,8 +47,8 @@ class notification_event_Core { notification::remove_watch($item); } } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::item_deleted() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::item_deleted() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -69,8 +69,8 @@ class notification_event_Core { notification::send_comment_published($comment); } } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::comment_created() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::comment_created() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -80,8 +80,8 @@ class notification_event_Core { notification::send_comment_published($new); } } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::comment_updated() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::comment_updated() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -91,8 +91,8 @@ class notification_event_Core { ->where("user_id", $user->id) ->delete_all(); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::user_before_delete() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::user_before_delete() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -100,8 +100,8 @@ class notification_event_Core { try { notification::send_pending_notifications(); } catch (Exception $e) { - Kohana::log("error", "@todo notification_event::batch_complete() failed"); - Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + Kohana_Log::add("error", "@todo notification_event::batch_complete() failed"); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 8c3bd3ab..9d732c11 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -61,7 +61,7 @@ class search_Core { static function update($item) { $data = new ArrayObject(); $record = ORM::factory("search_record")->where("item_id", $item->id)->find(); - if (!$record->loaded) { + if (!$record->loaded()) { $record->item_id = $item->id; } diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 53a3d091..25961129 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -103,7 +103,7 @@ class Server_Add_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded || $task->owner_id != identity::active_user()->id) { + if (!$task->loaded() || $task->owner_id != identity::active_user()->id) { access::forbidden(); } @@ -216,7 +216,7 @@ class Server_Add_Controller extends Admin_Controller { // Look up the parent item for this entry. By now it should exist, but if none was // specified, then this belongs as a child of the current item. $parent_entry = ORM::factory("server_add_file", $entry->parent_id); - if (!$parent_entry->loaded) { + if (!$parent_entry->loaded()) { $parent = ORM::factory("item", $task->get("item_id")); } else { $parent = ORM::factory("item", $parent_entry->item_id); diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 67587c2e..93b51814 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -35,7 +35,7 @@ class Admin_Tags_Controller extends Admin_Controller { public function form_delete($id) { $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if ($tag->loaded()) { print tag::get_delete_form($tag); } } @@ -44,7 +44,7 @@ class Admin_Tags_Controller extends Admin_Controller { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { kohana::show_404(); } @@ -68,7 +68,7 @@ class Admin_Tags_Controller extends Admin_Controller { public function form_rename($id) { $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if ($tag->loaded()) { print InPlaceEdit::factory($tag->name) ->action("admin/tags/rename/$id") ->render(); @@ -79,7 +79,7 @@ class Admin_Tags_Controller extends Admin_Controller { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { kohana::show_404(); } diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index feaf40c5..6ce18625 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -34,7 +34,7 @@ class tag_Core { } $tag = ORM::factory("tag")->where("name", $tag_name)->find(); - if (!$tag->loaded) { + if (!$tag->loaded()) { $tag->name = $tag_name; $tag->count = 0; $tag->save(); diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index a857a99d..6ee8e708 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -51,7 +51,7 @@ class tag_event_Core { try { tag::add($photo, $tag); } catch (Exception $e) { - Kohana::log("error", "Error adding tag: $tag\n" . + Kohana_Log::add("error", "Error adding tag: $tag\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); } } diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index de5d6c72..03017dc3 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -31,7 +31,7 @@ class tag_rss_Core { static function feed($feed_id, $offset, $limit, $id) { if ($feed_id == "tag") { $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { + if (!$tag->loaded()) { Kohana::show_404(); } $feed->children = $tag->items($limit, $offset, "photo"); diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index b3284385..619e6e18 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -265,7 +265,7 @@ class Admin_Users_Controller extends Admin_Controller { if ($valid) { $new_name = $form->edit_group->inputs["name"]->value; $group = group::lookup_by_name($name); - if ($group->loaded) { + if ($group->loaded()) { $form->edit_group->inputs["name"]->add_error("in_use", 1); $valid = false; } diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index e18e76b6..8309d2cc 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -47,7 +47,7 @@ class Password_Controller extends Controller { $valid = $form->validate(); if ($valid) { $user = user::lookup_by_name($form->reset->inputs["name"]->value); - if (!$user->loaded || empty($user->email)) { + if (!$user->loaded() || empty($user->email)) { $form->reset->inputs["name"]->add_error("no_email", 1); $valid = false; } diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 3aaf1b11..1beaa1c2 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -32,7 +32,7 @@ class group_Core { */ static function create($name) { $group = ORM::factory("group")->where("name", $name)->find(); - if ($group->loaded) { + if ($group->loaded()) { throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); } @@ -86,7 +86,7 @@ class group_Core { private static function _lookup_by_field($field_name, $value) { try { $user = model_cache::get("group", $value, $field_name); - if ($user->loaded) { + if ($user->loaded()) { return $user; } } catch (Exception $e) { diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index f9f16da5..4ed9daee 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -45,7 +45,7 @@ class user_Core { */ static function create($name, $full_name, $password) { $user = ORM::factory("user")->where("name", $name)->find(); - if ($user->loaded) { + if ($user->loaded()) { throw new Exception("@todo USER_ALREADY_EXISTS $name"); } @@ -163,7 +163,7 @@ class user_Core { private static function _lookup_user_by_field($field_name, $value) { try { $user = model_cache::get("user", $value, $field_name); - if ($user->loaded) { + if ($user->loaded()) { return $user; } } catch (Exception $e) { diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 4432fc69..81f779cf 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -34,7 +34,7 @@ class Group_Model extends ORM implements Group_Definition { } public function save() { - if (!$this->loaded) { + if (!$this->loaded()) { $created = 1; } parent::save(); diff --git a/modules/user/models/user.php b/modules/user/models/user.php index bd61def8..0d5a2bcd 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -62,7 +62,7 @@ class User_Model extends ORM implements User_Definition { } public function save() { - if (!$this->loaded) { + if (!$this->loaded()) { $created = 1; } parent::save(); diff --git a/modules/user/tests/User_Groups_Test.php b/modules/user/tests/User_Groups_Test.php index 3da8dd34..6aedfde5 100644 --- a/modules/user/tests/User_Groups_Test.php +++ b/modules/user/tests/User_Groups_Test.php @@ -22,14 +22,14 @@ class User_Groups_Test extends Unit_Test_Case { public function teardown() { try { $group = ORM::factory("group")->where("name", "user_groups_test")->find(); - if ($group->loaded) { + if ($group->loaded()) { $group->delete(); } } catch (Exception $e) { } try { $user = ORM::factory("user")->where("name", "user_groups_test")->find(); - if ($user->loaded) { + if ($user->loaded()) { $user->delete(); } } catch (Exception $e) { } -- cgit v1.2.3 From 33b1d4b7efa8c6b825908f48c7e744578e7f9ae6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 13:41:53 -0800 Subject: Convert one more instance of ORM::$loaded to ORM::loaded() --- modules/gallery/controllers/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/controllers/items.php b/modules/gallery/controllers/items.php index ec3681a3..bf1f80d4 100644 --- a/modules/gallery/controllers/items.php +++ b/modules/gallery/controllers/items.php @@ -20,7 +20,7 @@ class Items_Controller extends Controller { public function __call($function, $args) { $item = ORM::factory("item", (int)$function); - if (!$item->loaded) { + if (!$item->loaded()) { return Kohana::show_404(); } // Redirect to the more specific resource type, since it will render -- cgit v1.2.3 From 4a417708f00b1ebd5865c8075bb36b7fc0f14756 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 13:49:40 -0800 Subject: Kohana::show_404() -> throw new Kohana_404_Exception() --- modules/digibug/controllers/digibug.php | 6 +++--- modules/gallery/controllers/combined.php | 4 ++-- modules/gallery/controllers/items.php | 2 +- modules/gallery_unit_test/controllers/gallery_unit_test.php | 2 +- modules/rss/controllers/rss.php | 2 +- modules/tag/helpers/tag_rss.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index cef42b2d..25f1ca3e 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -61,7 +61,7 @@ class Digibug_Controller extends Controller { if ($type == "full") { $remote_addr = ip2long($this->input->server("REMOTE_ADDR")); if ($remote_addr === false) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } $config = Kohana::config("digibug"); @@ -76,13 +76,13 @@ class Digibug_Controller extends Controller { } } if (!$authorized) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } } $proxy = ORM::factory("digibug_proxy", array("uuid" => $id)); if (!$proxy->loaded() || !$proxy->item->loaded()) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } $file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path(); diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index c1f42bfe..8132fc41 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -56,7 +56,7 @@ class Combined_Controller extends Controller { } if (empty($key)) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } $cache = Cache::instance(); @@ -71,7 +71,7 @@ class Combined_Controller extends Controller { $content = $cache->get($key); } if (empty($content)) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } // $type is either 'javascript' or 'css' diff --git a/modules/gallery/controllers/items.php b/modules/gallery/controllers/items.php index bf1f80d4..86782469 100644 --- a/modules/gallery/controllers/items.php +++ b/modules/gallery/controllers/items.php @@ -21,7 +21,7 @@ class Items_Controller extends Controller { public function __call($function, $args) { $item = ORM::factory("item", (int)$function); if (!$item->loaded()) { - return Kohana::show_404(); + throw new Kohana_404_Exception(); } // Redirect to the more specific resource type, since it will render // differently. We could also just delegate here, but it feels more appropriate diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 58e0d9c5..391ad029 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -20,7 +20,7 @@ class Gallery_Unit_Test_Controller extends Controller { function Index() { if (!TEST_MODE) { - print Kohana::show_404(); + print throw new Kohana_404_Exception(); } // Jump through some hoops to satisfy the way that we check for the site_domain in diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php index ed2acef8..a963a1dc 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -39,7 +39,7 @@ class Rss_Controller extends Controller { } } if (empty($feed)) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } if ($feed->max_pages && $page > $feed->max_pages) { diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index 03017dc3..f09a4530 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -32,7 +32,7 @@ class tag_rss_Core { if ($feed_id == "tag") { $tag = ORM::factory("tag", $id); if (!$tag->loaded()) { - Kohana::show_404(); + throw new Kohana_404_Exception(); } $feed->children = $tag->items($limit, $offset, "photo"); $feed->max_pages = ceil($tag->count / $limit); -- cgit v1.2.3 From 7c9bd9e8e8c4d2e57c4f08f526e5464236fa90e3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 13:59:01 -0800 Subject: Call execute() after upate() and insert(). --- modules/gallery/libraries/drivers/Cache/Database.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index d27bcc32..eda445b6 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -64,11 +64,14 @@ class Cache_Database_Driver extends Cache_Driver { $status = db::build()->update( "caches", array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), - array("key", "=", $id)); + array("key", "=", $id)) + ->execute(); } else { $status = db::build()->insert( "caches", - array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data))); + array("key" => $id, "tags" => $tags, + "expiration" => $lifetime, "cache" => serialize($data))) + ->execute(); } } @@ -185,6 +188,6 @@ class Cache_Database_Driver extends Cache_Driver { * Empty the cache */ public function delete_all() { - db::build()->query("TRUNCATE {caches}"); + db::build()->query("TRUNCATE {caches}")->execute(); } } \ No newline at end of file -- cgit v1.2.3 From daedadda751a188c20f032b09c1ca32e39279360 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 14:27:06 -0800 Subject: Switch from stdClass to arrays for global data. --- modules/gallery/libraries/MY_View.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index 0311f2dd..d1ec6684 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -18,27 +18,26 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class View extends View_Core { - static $global_data; + static $global_data = array(); /** * Reimplement Kohana 2.3's View::set_global() functionality. */ public function set_global($key, $value) { - View::$global_data->$key = $value; + View::$global_data[$key] = $value; $this->$key = $value; } public function __isset($key) { - if (isset(View::$global_data->$key)) { + if (array_key_exists($key, View::$global_data)) { return true; } return parent::__isset($key); } public function &__get($key) { - Kohana_Log::add("error",print_r("__get($key)",1)); - if (isset(View::$global_data->$key)) { - return View::$global_data->$key; + if (array_key_exists($key, View::$global_data)) { + return View::$global_data[$key]; } return parent::__get($key); } -- cgit v1.2.3 From 7eacc465d53d08ced85114b0a4ddc26b3fed848e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 14:50:29 -0800 Subject: Fix set_global() to be more elegant and preserve local trumping --- modules/gallery/libraries/MY_View.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index d1ec6684..45aae188 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -25,21 +25,6 @@ class View extends View_Core { */ public function set_global($key, $value) { View::$global_data[$key] = $value; - $this->$key = $value; - } - - public function __isset($key) { - if (array_key_exists($key, View::$global_data)) { - return true; - } - return parent::__isset($key); - } - - public function &__get($key) { - if (array_key_exists($key, View::$global_data)) { - return View::$global_data[$key]; - } - return parent::__get($key); } /** @@ -58,9 +43,10 @@ class View extends View_Core { * * @see View_Core::render */ - public function render($print=false, $renderer=false) { + public function render($print=false, $renderer=false, $modifier=false) { try { - return parent::render($print, $renderer); + $this->kohana_local_data = array_merge(View::$global_data, $this->kohana_local_data); + return parent::render($print, $renderer, $modifier); } catch (Exception $e) { Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); return ""; -- cgit v1.2.3 From 60c20b0045ade2ceeff648c6b97180df5b3a1dbc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 16:26:10 -0800 Subject: The html helpers no longer forces .js and .css suffixes to urls it generates (yay!) --- modules/gallery/controllers/combined.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index 8132fc41..e90a2f1a 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -22,7 +22,6 @@ class Combined_Controller extends Controller { * Return the combined Javascript bundle associated with the given key. */ public function javascript($key) { - $key = substr($key, 0, strlen($key) - 3); // strip off the trailing .js return $this->_emit("javascript", $key); } @@ -30,7 +29,6 @@ class Combined_Controller extends Controller { * Return the combined CSS bundle associated with the given key. */ public function css($key) { - $key = substr($key, 0, strlen($key) - 4); // strip off the trailing .css return $this->_emit("css", $key); } -- cgit v1.2.3 From 5f521014f68803bb0bbab5fe30e1e2c5f61d1b37 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 19:24:30 -0800 Subject: form::close() went away in Kohana 2.4 --- modules/forge/libraries/Forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/forge/libraries/Forge.php b/modules/forge/libraries/Forge.php index d9da4c7d..e607ec29 100644 --- a/modules/forge/libraries/Forge.php +++ b/modules/forge/libraries/Forge.php @@ -299,7 +299,7 @@ class Forge_Core { // Set the form open and close $form->open = form::$form_type(arr::remove('action', $this->attr), $this->attr, $hidden); - $form->close = form::close(); + $form->close = ""; // Set the inputs $form->inputs = $this->inputs; -- cgit v1.2.3 From ccb0ea3d30a114c069240453d7d85f18328db6e5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 19:24:50 -0800 Subject: Make globals work if you access the the variables directly with $v->foo instead of doing it in a rendered template. --- modules/gallery/libraries/MY_View.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index 45aae188..cec59ec1 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -27,6 +27,26 @@ class View extends View_Core { View::$global_data[$key] = $value; } + public function is_set($key) { + return parent::is_set($key) ? true : array_key_exists($key, View::$global_data); + } + + /** + * Completely replace View_Core::__get() so that local data trumps global data, trumps members. + * This simulates the Kohana 2.3 behavior. + */ + public function &__get($key) { + if (isset($this->kohana_local_data[$key])) { + return $this->kohana_local_data[$key]; + } else if (isset(View::$global_data[$key])) { + return View::$global_data[$key]; + } else if (isset($this->$key)) { + return $this->$key; + } else { + throw new Kohana_Exception('Undefined view variable: :var', array(':var' => $key)); + } + } + /** * Override View_Core::__construct so that we can set the csrf value into all views. * -- cgit v1.2.3 From 0ef6994f23300f3c6bfb83193b4101202dbc16f8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 19:25:34 -0800 Subject: ORM::orderby -> ORM::order_by --- modules/image_block/helpers/image_block_block.php | 12 ++++++------ modules/tag/helpers/tag.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php index 79bd92ba..f591e8d1 100644 --- a/modules/image_block/helpers/image_block_block.php +++ b/modules/image_block/helpers/image_block_block.php @@ -35,18 +35,18 @@ class image_block_block_Core { $items = ORM::factory("item") ->viewable() - ->where("type !=", "album") - ->where("rand_key < ", $random) - ->orderby(array("rand_key" => "DESC")) + ->where("type", "!=", "album") + ->where("rand_key", "<", $random) + ->order_by(array("rand_key" => "DESC")) ->find_all(1); if ($items->count() == 0) { // Try once more. If this fails, just ditch the block altogether $items = ORM::factory("item") ->viewable() - ->where("type !=", "album") - ->where("rand_key >= ", $random) - ->orderby(array("rand_key" => "DESC")) + ->where("type", "!=", "album") + ->where("rand_key", ">=", $random) + ->order_by(array("rand_key" => "DESC")) ->find_all(1); } diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 8558ac30..8694bcec 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -57,7 +57,7 @@ class tag_Core { */ static function popular_tags($count) { return ORM::factory("tag") - ->orderby("count", "DESC") + ->order_by("count", "DESC") ->limit($count) ->find_all(); } -- cgit v1.2.3 From 0121bfd5850bdc59bf0cd656c61c953421a85890 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 19:26:52 -0800 Subject: ORM::orderby -> ORM::order_by --- modules/comment/controllers/admin_comments.php | 2 +- modules/comment/helpers/comment_block.php | 2 +- modules/comment/helpers/comment_rss.php | 2 +- modules/comment/helpers/comment_theme.php | 2 +- .../controllers/admin_advanced_settings.php | 2 +- modules/gallery/controllers/admin_maintenance.php | 4 +-- modules/gallery/helpers/access.php | 10 +++---- modules/gallery/helpers/gallery_block.php | 4 +-- modules/gallery/helpers/gallery_rss.php | 4 +-- modules/gallery/helpers/graphics.php | 2 +- modules/gallery/helpers/item.php | 2 +- modules/gallery/helpers/module.php | 2 +- modules/gallery/models/item.php | 32 +++++++++++----------- modules/server_add/controllers/server_add.php | 2 +- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/controllers/tags.php | 2 +- modules/user/controllers/admin_users.php | 4 +-- 17 files changed, 40 insertions(+), 40 deletions(-) (limited to 'modules') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 1a9f0e6a..039956d7 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -48,7 +48,7 @@ class Admin_Comments_Controller extends Admin_Controller { $view->content->menu = $this->_menu($view->content->counts); $view->content->state = $state; $view->content->comments = ORM::factory("comment") - ->orderby("created", "DESC") + ->order_by("created", "DESC") ->where("state", $state) ->limit(self::$items_per_page, ($page - 1) * self::$items_per_page) ->find_all(); diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php index 7cd5d429..ab86b90a 100644 --- a/modules/comment/helpers/comment_block.php +++ b/modules/comment/helpers/comment_block.php @@ -30,7 +30,7 @@ class comment_block_Core { $block->title = t("Recent comments"); $block->content = new View("admin_block_recent_comments.html"); $block->content->comments = - ORM::factory("comment")->orderby("created", "DESC")->limit(5)->find_all(); + ORM::factory("comment")->order_by("created", "DESC")->limit(5)->find_all(); break; } diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 3692a30d..d0bb7859 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -36,7 +36,7 @@ class comment_rss_Core { $comments = ORM::factory("comment") ->viewable() ->where("state", "published") - ->orderby("created", "DESC"); + ->order_by("created", "DESC"); if ($feed_id == "item") { $comments->where("item_id", $id); diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index af0e1ca4..2f12192b 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -39,7 +39,7 @@ class comment_theme_Core { $view->comments = ORM::factory("comment") ->where("item_id", $theme->item()->id) ->where("state", "published") - ->orderby("created", "ASC") + ->order_by("created", "ASC") ->find_all(); $block->content = $view; diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index 79bc1183..c9de7e57 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -22,7 +22,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_advanced_settings.html"); $view->content->vars = ORM::factory("var") - ->orderby("module_name", "name") + ->order_by("module_name", "name") ->find_all(); print $view; } diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index fe5059e7..3b896553 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -41,9 +41,9 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view->content = new View("admin_maintenance.html"); $view->content->task_definitions = task::get_definitions(); $view->content->running_tasks = ORM::factory("task") - ->where("done", 0)->orderby("updated", "DESC")->find_all(); + ->where("done", 0)->order_by("updated", "DESC")->find_all(); $view->content->finished_tasks = ORM::factory("task") - ->where("done", 1)->orderby("updated", "DESC")->find_all(); + ->where("done", 1)->order_by("updated", "DESC")->find_all(); print $view; } diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 9d27181a..d0200a73 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -171,7 +171,7 @@ class access_Core { ->where("items.id <> $item->id") ->join("access_intents", "items.id", "access_intents.item_id") ->where("access_intents.view_$group->id", self::DENY) - ->orderby("level", "DESC") + ->order_by("level", "DESC") ->limit(1) ->find(); @@ -494,7 +494,7 @@ class access_Core { ->where("right_ptr >", $item->right_ptr) ->join("access_intents", "access_intents.item_id", "items.id") ->where("access_intents.$field", self::DENY) - ->orderby("left_ptr", "DESC") + ->order_by("left_ptr", "DESC") ->limit(1) ->find(); if ($tmp_item->loaded()) { @@ -516,7 +516,7 @@ class access_Core { ->where("right_ptr <=", $item->right_ptr) ->where("type", "album") ->where("access_intents.$field IS NOT", self::INHERIT) - ->orderby("level", "DESC") + ->order_by("level", "DESC") ->find_all(); foreach ($query as $row) { if ($row->$field == self::ALLOW) { @@ -565,7 +565,7 @@ class access_Core { ->where("left_ptr <", $item->left_ptr) ->where("right_ptr >", $item->right_ptr) ->where("$field IS NOT", self::UNKNOWN) - ->orderby("left_ptr", "DESC") + ->order_by("left_ptr", "DESC") ->limit(1) ->find(); if ($tmp_item->loaded()) { @@ -581,7 +581,7 @@ class access_Core { ->where("left_ptr >=", $item->left_ptr) ->where("right_ptr <=", $item->right_ptr) ->where("$field IS NOT", self::INHERIT) - ->orderby("level", "ASC") + ->order_by("level", "ASC") ->find_all(); foreach ($query as $row) { $value = ($row->$field === self::ALLOW) ? "TRUE" : "FALSE"; diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index b5c32ad2..d09f1c80 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -46,7 +46,7 @@ class gallery_block_Core { $block->title = t("Photo stream"); $block->content = new View("admin_block_photo_stream.html"); $block->content->photos = - ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10); + ORM::factory("item")->where("type", "photo")->order_by("created", "DESC")->find_all(10); break; case "log_entries": @@ -54,7 +54,7 @@ class gallery_block_Core { $block->title = t("Log entries"); $block->content = new View("admin_block_log_entries.html"); $block->content->entries = ORM::factory("log") - ->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); + ->order_by(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); break; case "stats": diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 155edfb5..e195be8d 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -30,13 +30,13 @@ class gallery_rss_Core { $feed->children = ORM::factory("item") ->viewable() ->where("type !=", "album") - ->orderby("created", "DESC") + ->order_by("created", "DESC") ->find_all($limit, $offset); $all_children = ORM::factory("item") ->viewable() ->where("type !=", "album") - ->orderby("created", "DESC"); + ->order_by("created", "DESC"); $feed->max_pages = ceil($all_children->find_all()->count() / $limit); $feed->title = t("Recent updates"); diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index a78cadd0..aef09003 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -183,7 +183,7 @@ class graphics_Core { foreach (ORM::factory("graphics_rule") ->where("target", $target) ->where("active", true) - ->orderby("priority", "asc") + ->order_by("priority", "asc") ->find_all() as $rule) { $rules[] = (object)$rule->as_array(); } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 109fa6f8..7496d368 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -142,7 +142,7 @@ class item_Core { // @todo: figure out a better way to bootstrap the weight. $result = Database::instance() ->select("weight")->from("items") - ->orderby("weight", "desc")->limit(1) + ->order_by("weight", "desc")->limit(1) ->get()->current(); return ($result ? $result->weight : 0) + 1; } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index e54a4352..b7e13b9a 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -364,7 +364,7 @@ class module_Core { foreach (Database::instance() ->select("module_name", "name", "value") ->from("vars") - ->orderby("module_name", "name") + ->order_by("module_name", "name") ->get() as $row) { if ($row->module_name == "gallery" && $row->name == "_cache") { // This could happen if there's a race condition diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index bd1f9af5..1efac37f 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -291,7 +291,7 @@ class Item_Model extends ORM_MPTT { ->where("left_ptr <=", $this->left_ptr) ->where("right_ptr >=", $this->right_ptr) ->where("id <>", 1) - ->orderby("left_ptr", "ASC") + ->order_by("left_ptr", "ASC") ->get() as $row) { // Don't encode the names segment $names[] = rawurlencode($row->name); @@ -460,7 +460,7 @@ class Item_Model extends ORM_MPTT { ->where("parent_id", $this->id) ->where($sort_column, $child->$sort_column) ->where($where) - ->orderby(array("id" => "ASC")) + ->order_by(array("id" => "ASC")) ->get() as $row) { $position++; if ($row->id == $child->id) { @@ -475,10 +475,10 @@ class Item_Model extends ORM_MPTT { // // Reproduce the children() functionality here using Database directly to avoid loading the // whole ORM for each row. - $orderby = array($this->sort_column => $this->sort_order); + $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { - $orderby["id"] = "ASC"; + $order_by["id"] = "ASC"; } $position = 0; @@ -486,7 +486,7 @@ class Item_Model extends ORM_MPTT { ->from("items") ->where("parent_id", $this->id) ->where($where) - ->orderby($orderby) + ->order_by($order_by) ->get() as $row) { $position++; if ($row->id == $child->id) { @@ -592,18 +592,18 @@ class Item_Model extends ORM_MPTT { * @param integer SQL limit * @param integer SQL offset * @param array additional where clauses - * @param array orderby + * @param array order_by * @return array ORM */ - function children($limit=null, $offset=0, $where=array(), $orderby=null) { - if (empty($orderby)) { - $orderby = array($this->sort_column => $this->sort_order); + function children($limit=null, $offset=0, $where=array(), $order_by=null) { + if (empty($order_by)) { + $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { - $orderby["id"] = "ASC"; + $order_by["id"] = "ASC"; } } - return parent::children($limit, $offset, $where, $orderby); + return parent::children($limit, $offset, $where, $order_by); } /** @@ -617,14 +617,14 @@ class Item_Model extends ORM_MPTT { * @param array additional where clauses * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=array(), $orderby=null) { - if (empty($orderby)) { - $orderby = array($this->sort_column => $this->sort_order); + function descendants($limit=null, $offset=0, $where=array(), $order_by=null) { + if (empty($order_by)) { + $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker if ($this->sort_column != "id") { - $orderby["id"] = "ASC"; + $order_by["id"] = "ASC"; } } - return parent::descendants($limit, $offset, $where, $orderby); + return parent::descendants($limit, $offset, $where, $order_by); } } diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 25961129..053a1891 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -199,7 +199,7 @@ class Server_Add_Controller extends Admin_Controller { $entries = ORM::factory("server_add_file") ->where("task_id", $task->id) ->where("item_id", null) - ->orderby("id", "ASC") + ->order_by("id", "ASC") ->limit(10) ->find_all(); if ($entries->count() == 0) { diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 93b51814..aff44803 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -29,7 +29,7 @@ class Admin_Tags_Controller extends Admin_Controller { if ($filter) { $query->like("name", $filter); } - $view->content->tags = $query->orderby("name", "ASC")->find_all(); + $view->content->tags = $query->order_by("name", "ASC")->find_all(); print $view; } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 9f9e45d9..dfa3a9b3 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -84,7 +84,7 @@ class Tags_Controller extends Controller { $tag_part = end($tag_parts); $tag_list = ORM::factory("tag") ->like("name", "{$tag_part}%", false) - ->orderby("name", "ASC") + ->order_by("name", "ASC") ->limit($limit) ->find_all(); foreach ($tag_list as $tag) { diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 619e6e18..ee65efd2 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -22,10 +22,10 @@ class Admin_Users_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_users.html"); $view->content->users = ORM::factory("user") - ->orderby("name", "ASC") + ->order_by("name", "ASC") ->find_all(); $view->content->groups = ORM::factory("group") - ->orderby("name", "ASC") + ->order_by("name", "ASC") ->find_all(); print $view; } -- cgit v1.2.3 From 9d9e4bdb675154c1046b25dcb3777be61b410e4e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 20:05:12 -0800 Subject: Update hidden field format to match Kohana 2.4's form::open() API. --- modules/forge/libraries/Forge.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/forge/libraries/Forge.php b/modules/forge/libraries/Forge.php index e607ec29..5807c849 100644 --- a/modules/forge/libraries/Forge.php +++ b/modules/forge/libraries/Forge.php @@ -277,7 +277,8 @@ class Forge_Core { { foreach ($this->hidden as $input) { - $hidden[$input->name] = $input->value; + $hidden['name'] = $input->name; + $hidden['value'] = $input->value; } } -- cgit v1.2.3 From 4b2e1344b4e4d110a9f61d09b8756d9948de24ac Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 25 Nov 2009 20:05:38 -0800 Subject: Move the CSRF initialization into the constructor, I don't see why we need it also in render(). --- modules/gallery/libraries/MY_Forge.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Forge.php b/modules/gallery/libraries/MY_Forge.php index b40d067d..6bdadea3 100644 --- a/modules/gallery/libraries/MY_Forge.php +++ b/modules/gallery/libraries/MY_Forge.php @@ -24,14 +24,13 @@ class Forge extends Forge_Core { */ public function __construct($action=null, $title='', $method=null, $attr=array()) { parent::__construct($action, $title, $method, $attr); - $this->hidden("csrf")->value(""); + $this->hidden("csrf")->value(access::csrf_token()); } /** * Use our own template */ public function render($template="form.html", $custom=false) { - $this->hidden["csrf"]->value(access::csrf_token()); return parent::render($template, $custom); } -- cgit v1.2.3 From 2ee38b3d8e7c2789c776c6665e2595bb6561acc6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 11:36:09 -0800 Subject: ORM::$rules now has a special meaning. Use $form_rules for our internal rules code. --- modules/gallery/libraries/MY_Forge.php | 4 ++-- modules/gallery/models/item.php | 2 +- modules/user/models/group.php | 2 +- modules/user/models/user.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Forge.php b/modules/gallery/libraries/MY_Forge.php index 6bdadea3..9564f941 100644 --- a/modules/gallery/libraries/MY_Forge.php +++ b/modules/gallery/libraries/MY_Forge.php @@ -42,8 +42,8 @@ class Forge extends Forge_Core { if (isset($input->inputs)) { $input->add_rules_from($model); } - if (isset($model->rules[$name])) { - $input->rules($model->rules[$name]); + if (isset($model->form_rules[$name])) { + $input->rules($model->form_rules[$name]); } } } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 1efac37f..c8386b1c 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -21,7 +21,7 @@ class Item_Model extends ORM_MPTT { protected $children = 'items'; protected $sorting = array(); - var $rules = array( + var $form_rules = array( "name" => "required|length[0,255]", "title" => "required|length[0,255]", "description" => "length[0,65535]", diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 81f779cf..3a084684 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -20,7 +20,7 @@ class Group_Model extends ORM implements Group_Definition { protected $has_and_belongs_to_many = array("users"); - var $rules = array( + var $form_rules = array( "name" => "required|length[4,255]"); /** diff --git a/modules/user/models/user.php b/modules/user/models/user.php index 0d5a2bcd..e14d9b31 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -20,7 +20,7 @@ class User_Model extends ORM implements User_Definition { protected $has_and_belongs_to_many = array("groups"); - var $rules = array( + var $form_rules = array( "name" => "required|length[1,32]", "full_name" => "length[0,255]", "email" => "required|valid_email|length[1,255]", -- cgit v1.2.3 From 22823df22098ed1a69d88c2e5fdc30cd90f72c30 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 11:43:20 -0800 Subject: Update ORM::where() calls to take 3 args. --- modules/notification/helpers/notification.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index d525e03e..7e935614 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -24,8 +24,8 @@ class notification { } return ORM::factory("subscription") - ->where("item_id", $item_id) - ->where("user_id", $user->id) + ->where("item_id", "=", $item_id) + ->where("user_id", "=", $user->id) ->find(); } @@ -35,8 +35,8 @@ class notification { } return ORM::factory("subscription") - ->where("item_id", $item->id) - ->where("user_id", $user->id) + ->where("item_id", "=", $item->id) + ->where("user_id", "=", $user->id) ->find() ->loaded(); } @@ -60,8 +60,8 @@ class notification { } $subscription = ORM::factory("subscription") - ->where("item_id", $item->id) - ->where("user_id", $user->id) + ->where("item_id", "=", $item->id) + ->where("user_id", "=", $user->id) ->find()->delete(); } } @@ -71,8 +71,8 @@ class notification { foreach (ORM::factory("subscription") ->select("user_id") ->join("items", "subscriptions.item_id", "items.id") - ->where("items.left_ptr <=", $item->left_ptr) - ->where("items.right_ptr >", $item->right_ptr) + ->where("items.left_ptr", "<=", $item->left_ptr) + ->where("items.right_ptr", ">", $item->right_ptr) ->find_all() ->as_array() as $subscriber) { $subscriber_ids[] = $subscriber->user_id; @@ -176,7 +176,7 @@ class notification { ->get() as $row) { $email = $row->email; $result = ORM::factory("pending_notification") - ->where("email", $email) + ->where("email", "=", $email) ->find_all(); if ($result->count() == 1) { $pending = $result->current(); -- cgit v1.2.3 From 1fd0e14359a7c7164573e4aa897c07680339e713 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 12:09:04 -0800 Subject: Convert all DB where() calls to take 3 arguments. Convert all open_paren() calls to and_open() or or_open() as appropriate. --- modules/comment/controllers/admin_comments.php | 4 +- modules/comment/helpers/comment_event.php | 6 +-- modules/comment/helpers/comment_rss.php | 4 +- modules/comment/helpers/comment_theme.php | 4 +- modules/comment/tests/Comment_Model_Test.php | 4 +- modules/exif/helpers/exif.php | 14 +++---- modules/exif/helpers/exif_task.php | 10 ++--- modules/exif/helpers/exif_theme.php | 2 +- modules/g2_import/helpers/g2_import.php | 2 +- modules/g2_import/helpers/g2_import_task.php | 2 +- modules/gallery/controllers/admin_maintenance.php | 6 +-- modules/gallery/controllers/albums.php | 12 +++--- modules/gallery/controllers/file_proxy.php | 4 +- modules/gallery/controllers/l10n_client.php | 6 +-- modules/gallery/controllers/move.php | 4 +- modules/gallery/controllers/movies.php | 10 ++--- modules/gallery/controllers/photos.php | 12 +++--- modules/gallery/helpers/MY_url.php | 6 +-- modules/gallery/helpers/access.php | 46 ++++++++++---------- modules/gallery/helpers/album.php | 10 ++--- modules/gallery/helpers/gallery_block.php | 8 ++-- modules/gallery/helpers/gallery_event.php | 12 +++--- modules/gallery/helpers/gallery_rss.php | 4 +- modules/gallery/helpers/graphics.php | 10 ++--- modules/gallery/helpers/l10n_client.php | 6 ++- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/module.php | 11 ++--- modules/gallery/helpers/movie.php | 10 ++--- modules/gallery/helpers/photo.php | 10 ++--- modules/gallery/helpers/site_status.php | 4 +- modules/gallery/libraries/Gallery_I18n.php | 4 +- .../gallery/libraries/drivers/Cache/Database.php | 9 ++-- modules/gallery/models/item.php | 20 ++++----- modules/gallery/tests/Access_Helper_Test.php | 16 +++---- modules/gallery/tests/Cache_Test.php | 2 +- modules/gallery/tests/Database_Test.php | 49 +++++++++++----------- modules/gallery/tests/Gallery_Installer_Test.php | 2 +- modules/gallery/tests/I18n_Test.php | 4 +- modules/gallery/tests/Item_Helper_Test.php | 4 +- .../notification/helpers/notification_event.php | 4 +- modules/search/helpers/search.php | 10 ++--- modules/search/helpers/search_event.php | 2 +- modules/search/helpers/search_task.php | 4 +- modules/server_add/controllers/server_add.php | 8 ++-- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/helpers/tag.php | 4 +- modules/tag/models/tag.php | 8 ++-- modules/tag/tests/Tag_Test.php | 6 +-- modules/user/helpers/group.php | 2 +- modules/user/helpers/user.php | 2 +- modules/user/tests/User_Groups_Test.php | 4 +- 51 files changed, 208 insertions(+), 203 deletions(-) (limited to 'modules') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 039956d7..271c7d51 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -49,7 +49,7 @@ class Admin_Comments_Controller extends Admin_Controller { $view->content->state = $state; $view->content->comments = ORM::factory("comment") ->order_by("created", "DESC") - ->where("state", $state) + ->where("state", "=", $state) ->limit(self::$items_per_page, ($page - 1) * self::$items_per_page) ->find_all(); $view->content->pager = new Pagination(); @@ -120,7 +120,7 @@ class Admin_Comments_Controller extends Admin_Controller { access::verify_csrf(); ORM::factory("comment") - ->where("state", "spam") + ->where("state", "=", "spam") ->delete_all(); url::redirect("admin/comments/queue/spam"); } diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index a72102b9..cf5d0a60 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -29,7 +29,7 @@ class comment_event_Core { "guest_email" => null, "guest_name" => "guest", "guest_url" => null)) - ->where(array("author_id" => $user->id)) + ->where("author_id", "=", $user->id) ->update(); } @@ -40,7 +40,7 @@ class comment_event_Core { "guest_email" => null, "guest_name" => "guest", "guest_url" => null)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo: why do we do this? ->update(); } @@ -65,7 +65,7 @@ class comment_event_Core { foreach (Database::instance() ->select("text") ->from("comments") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->get() ->as_array() as $row) { $data[] = $row->text; diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index d0bb7859..77044884 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -35,11 +35,11 @@ class comment_rss_Core { $comments = ORM::factory("comment") ->viewable() - ->where("state", "published") + ->where("state", "=", "published") ->order_by("created", "DESC"); if ($feed_id == "item") { - $comments->where("item_id", $id); + $comments->where("item_id", "=", $id); } $feed->view = "comment.mrss"; diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index 2f12192b..ebcc1c42 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -37,8 +37,8 @@ class comment_theme_Core { $view = new View("comments.html"); $view->comments = ORM::factory("comment") - ->where("item_id", $theme->item()->id) - ->where("state", "published") + ->where("item_id", "=", $theme->item()->id) + ->where("state", "=", "published") ->order_by("created", "ASC") ->find_all(); diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php index de19648d..aa91d6f2 100644 --- a/modules/comment/tests/Comment_Model_Test.php +++ b/modules/comment/tests/Comment_Model_Test.php @@ -29,12 +29,12 @@ class Comment_Model_Test extends Unit_Test_Case { access::allow(identity::everybody(), "view", $album); $this->assert_equal( 1, - ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all()); + ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all()); // We can't see the comment when permissions are denied on the album access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, - ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all()); + ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all()); } } diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index b6a55679..b4241e89 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -73,7 +73,7 @@ class exif_Core { } $item->save(); - $record = ORM::factory("exif_record")->where("item_id", $item->id)->find(); + $record = ORM::factory("exif_record")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { $record->item_id = $item->id; } @@ -86,7 +86,7 @@ class exif_Core { static function get($item) { $exif = array(); $record = ORM::factory("exif_record") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->find(); if (!$record->loaded()) { return array(); @@ -143,11 +143,11 @@ class exif_Core { ->select("items.id") ->from("items") ->join("exif_records", "items.id", "exif_records.item_id", "left") - ->where("type", "photo") - ->open_paren() - ->where("exif_records.item_id", null) - ->orwhere("exif_records.dirty", 1) - ->close_paren() + ->where("type", "=", "photo") + ->and_open() + ->where("exif_records.item_id", "=", null) + ->orwhere("exif_records.dirty", "=", 1) + ->close() ->get() ->count(); diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 7c4c97c4..1a449fc7 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -44,11 +44,11 @@ class exif_task_Core { $start = microtime(true); foreach (ORM::factory("item") ->join("exif_records", "items.id", "exif_records.item_id", "left") - ->where("type", "photo") - ->open_paren() - ->where("exif_records.item_id", null) - ->orwhere("exif_records.dirty", 1) - ->close_paren() + ->where("type", "=", "photo") + ->and_open() + ->where("exif_records.item_id", "=", null) + ->orwhere("exif_records.dirty", "=", 1) + ->close() ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. diff --git a/modules/exif/helpers/exif_theme.php b/modules/exif/helpers/exif_theme.php index bb6926d3..db51f305 100644 --- a/modules/exif/helpers/exif_theme.php +++ b/modules/exif/helpers/exif_theme.php @@ -24,7 +24,7 @@ class exif_theme_Core { $record = Database::instance() ->select("key_count") ->from("exif_records") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->get() ->current(); if ($record && $record->key_count) { diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 1e835a59..3cf7eb80 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -867,7 +867,7 @@ class g2_import_Core { */ static function map($g2_id) { if (!array_key_exists($g2_id, self::$map)) { - $g2_map = ORM::factory("g2_map")->where("g2_id", $g2_id)->find(); + $g2_map = ORM::factory("g2_map")->where("g2_id", "=", $g2_id)->find(); self::$map[$g2_id] = $g2_map->loaded() ? $g2_map->g3_id : null; } diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index fef0d186..e80b88b9 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -65,7 +65,7 @@ class g2_import_task_Core { $task->set("done", $done); $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId()); - $root = ORM::factory("g2_map")->where("g2_id", $root_g2_id)->find(); + $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find(); if (!$root->loaded()) { $root->g2_id = $root_g2_id; $root->g3_id = 1; diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 3b896553..6377f40f 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -41,9 +41,9 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view->content = new View("admin_maintenance.html"); $view->content->task_definitions = task::get_definitions(); $view->content->running_tasks = ORM::factory("task") - ->where("done", 0)->order_by("updated", "DESC")->find_all(); + ->where("done", "=", 0)->order_by("updated", "DESC")->find_all(); $view->content->finished_tasks = ORM::factory("task") - ->where("done", 1)->order_by("updated", "DESC")->find_all(); + ->where("done", "=", 1)->order_by("updated", "DESC")->find_all(); print $view; } @@ -164,7 +164,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { // Do it the long way so we can call delete and remove the cache. $finished = ORM::factory("task") - ->where(array("done" => 1)) + ->where("done", "=", 1) ->find_all(); foreach ($finished as $task) { task::remove($task->id); diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 19140891..431d98a0 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -126,12 +126,12 @@ class Albums_Controller extends Items_Controller { if ($row = Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("parent_id", $album->parent_id) - ->where("id <>", $album->id) - ->open_paren() - ->where("name", $form->edit_item->dirname->value) - ->orwhere("slug", $form->edit_item->slug->value) - ->close_paren() + ->where("parent_id", "=", $album->parent_id) + ->where("id", "<>", $album->id) + ->and_open() + ->where("name", "=", $form->edit_item->dirname->value) + ->orwhere("slug", "=", $form->edit_item->slug->value) + ->close() ->get() ->current()) { if ($row->name == $form->edit_item->dirname->value) { diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index 11d858c0..53afe0e4 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -57,7 +57,7 @@ class File_Proxy_Controller extends Controller { $path = preg_replace("|/.album.jpg$|", "", $path); // We now have the relative path to the item. Search for it in the path cache - $item = ORM::factory("item")->where("relative_path_cache", $path)->find(); + $item = ORM::factory("item")->where("relative_path_cache", "=", $path)->find(); if (!$item->loaded()) { // We didn't turn it up. It's possible that the relative_path_cache is out of date here. // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be @@ -69,7 +69,7 @@ class File_Proxy_Controller extends Controller { if (preg_match('/.jpg$/', $path)) { foreach (array("flv", "mp4") as $ext) { $movie_path = preg_replace('/.jpg$/', ".$ext", $path); - $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find(); + $item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find(); if ($item->loaded()) { break; } diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 2eda741c..30a18631 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -116,7 +116,7 @@ class L10n_Client_Controller extends Controller { foreach (Database::instance() ->select("key", "message") ->from("incoming_translations") - ->where(array("locale" => 'root')) + ->where("locale", "=", "root")) ->get() ->as_array() as $row) { $calls[$row->key] = array(unserialize($row->message), array()); @@ -131,7 +131,7 @@ class L10n_Client_Controller extends Controller { foreach (Database::instance() ->select("key", "translation") ->from("incoming_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->get() ->as_array() as $row) { $translations[$row->key] = unserialize($row->translation); @@ -140,7 +140,7 @@ class L10n_Client_Controller extends Controller { foreach (Database::instance() ->select("key", "translation") ->from("outgoing_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->get() ->as_array() as $row) { $translations[$row->key] = unserialize($row->translation); diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index 87b73436..863b13bb 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -64,8 +64,8 @@ class Move_Controller extends Controller { $view->parent = $target; $view->children = ORM::factory("item") ->viewable() - ->where("type", "album") - ->where("parent_id", $target->id) + ->where("type", "=", "album") + ->where("parent_id", "=", $target->id) ->find_all(); return $view; } diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 3d5eac32..7ceeefdf 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -74,12 +74,12 @@ class Movies_Controller extends Items_Controller { if ($row = Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("parent_id", $movie->parent_id) + ->where("parent_id", "=", $movie->parent_id) ->where("id <>", $movie->id) - ->open_paren() - ->where("name", $form->edit_item->filename->value) - ->orwhere("slug", $form->edit_item->slug->value) - ->close_paren() + ->and_open() + ->where("name", "=", $form->edit_item->filename->value) + ->orwhere("slug", "=", $form->edit_item->slug->value) + ->close() ->get() ->current()) { if ($row->name == $form->edit_item->filename->value) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index f052eccd..0d7daac4 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -74,12 +74,12 @@ class Photos_Controller extends Items_Controller { if ($row = Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("parent_id", $photo->parent_id) - ->where("id <>", $photo->id) - ->open_paren() - ->where("name", $form->edit_item->filename->value) - ->orwhere("slug", $form->edit_item->slug->value) - ->close_paren() + ->where("parent_id", "=", $photo->parent_id) + ->where("id", "<>", $photo->id) + ->and_open() + ->where("name", "=", $form->edit_item->filename->value) + ->orwhere("slug", "=", $form->edit_item->slug->value) + ->close() ->get() ->current()) { if ($row->name == $form->edit_item->filename->value) { diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index e5eefad7..a2b2e461 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -50,12 +50,12 @@ class url extends url_Core { // In most cases, we'll have an exact match in the relative_url_cache item field. // but failing that, walk down the tree until we find it. The fallback code will fix caches // as it goes, so it'll never be run frequently. - $item = ORM::factory("item")->where("relative_url_cache", $current_uri)->find(); + $item = ORM::factory("item")->where("relative_url_cache", "=", $current_uri)->find(); if (!$item->loaded()) { $count = count(Router::$segments); foreach (ORM::factory("item") - ->where("slug", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) - ->where("level", $count + 1) + ->where("slug", "=", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES)) + ->where("level", "=", $count + 1) ->find_all() as $match) { if ($match->relative_url() == $current_uri) { $item = $match; diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index d0200a73..445f9b86 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -166,11 +166,11 @@ class access_Core { // For view permissions, if any parent is self::DENY, then those parents lock this one. // Return $lock = ORM::factory("item") - ->where("`left_ptr` <= $item->left_ptr") - ->where("`right_ptr` >= $item->right_ptr") - ->where("items.id <> $item->id") + ->where("left_ptr", "<=", $item->left_ptr) + ->where("right_ptr", ">=", $item->right_ptr) + ->where("items.id", "<>", $item->id) ->join("access_intents", "items.id", "access_intents.item_id") - ->where("access_intents.view_$group->id", self::DENY) + ->where("access_intents.view_$group->id", "=", self::DENY) ->order_by("level", "DESC") ->limit(1) ->find(); @@ -304,7 +304,7 @@ class access_Core { foreach (self::_get_all_groups() as $group) { self::_drop_columns($name, $group); } - $permission = ORM::factory("permission")->where("name", $name)->find(); + $permission = ORM::factory("permission")->where("name", "=", $name)->find(); if ($permission->loaded()) { $permission->delete(); } @@ -354,7 +354,7 @@ class access_Core { $access_cache->item_id = $item->id; if ($item->id != 1) { $parent_access_cache = - ORM::factory("access_cache")->where("item_id", $item->parent()->id)->find(); + ORM::factory("access_cache")->where("item_id", "=", $item->parent()->id)->find(); foreach (self::_get_all_groups() as $group) { foreach (ORM::factory("permission")->find_all() as $perm) { $field = "{$perm->name}_{$group->id}"; @@ -377,8 +377,8 @@ class access_Core { * @return void */ static function delete_item($item) { - ORM::factory("access_intent")->where("item_id", $item->id)->find()->delete(); - ORM::factory("access_cache")->where("item_id", $item->id)->find()->delete(); + ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->delete(); + ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->delete(); } /** @@ -475,7 +475,7 @@ class access_Core { * @return void */ private static function _update_access_view_cache($group, $item) { - $access = ORM::factory("access_intent")->where("item_id", $item->id)->find(); + $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find(); $db = Database::instance(); $field = "view_{$group->id}"; @@ -490,10 +490,10 @@ class access_Core { // item, then its safe to propagate from here. if ($access->$field !== self::DENY) { $tmp_item = ORM::factory("item") - ->where("left_ptr <", $item->left_ptr) - ->where("right_ptr >", $item->right_ptr) + ->where("left_ptr", "<", $item->left_ptr) + ->where("right_ptr", ">", $item->right_ptr) ->join("access_intents", "access_intents.item_id", "items.id") - ->where("access_intents.$field", self::DENY) + ->where("access_intents.$field", "=", self::DENY) ->order_by("left_ptr", "DESC") ->limit(1) ->find(); @@ -512,10 +512,10 @@ class access_Core { $query = ORM::factory("access_intent") ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr", "items.id")) ->join("items", "items.id", "access_intents.item_id") - ->where("left_ptr >=", $item->left_ptr) - ->where("right_ptr <=", $item->right_ptr) - ->where("type", "album") - ->where("access_intents.$field IS NOT", self::INHERIT) + ->where("left_ptr", ">=", $item->left_ptr) + ->where("right_ptr", "<=", $item->right_ptr) + ->where("type", "=", "album") + ->where("access_intents.$field", "IS NOT", self::INHERIT) ->order_by("level", "DESC") ->find_all(); foreach ($query as $row) { @@ -549,7 +549,7 @@ class access_Core { * @return void */ private static function _update_access_non_view_cache($group, $perm_name, $item) { - $access = ORM::factory("access_intent")->where("item_id", $item->id)->find(); + $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find(); $db = Database::instance(); $field = "{$perm_name}_{$group->id}"; @@ -562,9 +562,9 @@ class access_Core { if ($access->$field === self::INHERIT) { $tmp_item = ORM::factory("item") ->join("access_intents", "items.id", "access_intents.item_id") - ->where("left_ptr <", $item->left_ptr) - ->where("right_ptr >", $item->right_ptr) - ->where("$field IS NOT", self::UNKNOWN) + ->where("left_ptr", "<", $item->left_ptr) + ->where("right_ptr", ">", $item->right_ptr) + ->where($field, "IS NOT", self::UNKNOWN) ->order_by("left_ptr", "DESC") ->limit(1) ->find(); @@ -578,9 +578,9 @@ class access_Core { $query = ORM::factory("access_intent") ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr")) ->join("items", "items.id", "access_intents.item_id") - ->where("left_ptr >=", $item->left_ptr) - ->where("right_ptr <=", $item->right_ptr) - ->where("$field IS NOT", self::INHERIT) + ->where("left_ptr", ">=", $item->left_ptr) + ->where("right_ptr", "<=", $item->right_ptr) + ->where($field, "IS NOT", self::INHERIT) ->order_by("level", "ASC") ->find_all(); foreach ($query as $row) { diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 84a60f83..cd8777e2 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -68,11 +68,11 @@ class album_Core { // Randomize the name or slug if there's a conflict // @todo Improve this. Random numbers are not user friendly while (ORM::factory("item") - ->where("parent_id", $parent->id) - ->open_paren() - ->where("name", $album->name) - ->orwhere("slug", $album->slug) - ->close_paren() + ->where("parent_id", "=", $parent->id) + ->and_open() + ->where("name", "=", $album->name) + ->orwhere("slug", "=", $album->slug) + ->close() ->find()->id) { $rand = rand(); $album->name = "{$name}-$rand"; diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index d09f1c80..40660874 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -45,8 +45,8 @@ class gallery_block_Core { $block->css_id = "g-photo-stream"; $block->title = t("Photo stream"); $block->content = new View("admin_block_photo_stream.html"); - $block->content->photos = - ORM::factory("item")->where("type", "photo")->order_by("created", "DESC")->find_all(10); + $block->content->photos = ORM::factory("item") + ->where("type", "=", "photo")->order_by("created", "DESC")->find_all(10); break; case "log_entries": @@ -62,8 +62,8 @@ class gallery_block_Core { $block->title = t("Gallery stats"); $block->content = new View("admin_block_stats.html"); $block->content->album_count = - ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all(); - $block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all(); + ORM::factory("item")->where("type", "=", "album")->where("id", "<>", 1)->count_all(); + $block->content->photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all(); break; case "platform_info": diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 02bfdf28..fa4db317 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -33,15 +33,15 @@ class gallery_event_Core { $db = Database::instance(); $db->from("tasks") ->set(array("owner_id" => $admin->id)) - ->where(array("owner_id" => $user->id)) + ->where("owner_id", "=", $user->id) ->update(); $db->from("items") ->set(array("owner_id" => $admin->id)) - ->where(array("owner_id" => $user->id)) + ->where("owner_id", "=", $user->id) ->update(); $db->from("logs") ->set(array("user_id" => $admin->id)) - ->where(array("user_id" => $user->id)) + ->where("user_id", "=", $user->id) ->update(); } @@ -50,15 +50,15 @@ class gallery_event_Core { $db = Database::instance(); $db->from("tasks") ->set(array("owner_id" => $admin->id)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo why do we need this? ->update(); $db->from("items") ->set(array("owner_id" => $admin->id)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo why do we need this? ->update(); $db->from("logs") ->set(array("user_id" => $admin->id)) - ->where("1 = 1") + ->where("1", "=", "1") // @todo why do we need this? ->update(); } diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index e195be8d..93ace10b 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -29,13 +29,13 @@ class gallery_rss_Core { case "latest": $feed->children = ORM::factory("item") ->viewable() - ->where("type !=", "album") + ->where("type", "<>", "album") ->order_by("created", "DESC") ->find_all($limit, $offset); $all_children = ORM::factory("item") ->viewable() - ->where("type !=", "album") + ->where("type", "<>", "album") ->order_by("created", "DESC"); $feed->max_pages = ceil($all_children->find_all()->count() / $limit); diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index aef09003..e45a5125 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -61,9 +61,9 @@ class graphics_Core { */ static function remove_rule($module_name, $target, $operation) { ORM::factory("graphics_rule") - ->where("module_name", $module_name) - ->where("target", $target) - ->where("operation", $operation) + ->where("module_name", "=", $module_name) + ->where("target", "=", $target) + ->where("operation", "=", $operation) ->delete_all(); self::mark_dirty($target == "thumb", $target == "resize"); @@ -181,8 +181,8 @@ class graphics_Core { if (empty(self::$_rules_cache[$target])) { $rules = array(); foreach (ORM::factory("graphics_rule") - ->where("target", $target) - ->where("active", true) + ->where("target", "=", $target) + ->where("active", "=", true) ->order_by("priority", "asc") ->find_all() as $rule) { $rules[] = (object)$rule->as_array(); diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index aaf6ff46..14ab5a85 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -134,12 +134,14 @@ class l10n_client_Core { // incoming_translations.message to be NULL? $locale = $message_data->locale; $entry = ORM::factory("incoming_translation") - ->where(array("key" => $key, "locale" => $locale)) + ->where("key", "=", $key) + ->where("locale", "=", $locale) ->find(); if (!$entry->loaded()) { // @todo Load a message key -> message (text) dict into memory outside of this loop $root_entry = ORM::factory("incoming_translation") - ->where(array("key" => $key, "locale" => "root")) + ->where("key", "=", $key) + ->where("locale", "=", "root") ->find(); $entry->key = $key; $entry->message = $root_entry->message; diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index 6c09a686..a7ce2c59 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -31,7 +31,7 @@ class l10n_scanner_Core { foreach (Database::instance() ->select("key") ->from("incoming_translations") - ->where("locale", "root") + ->where("locale", "=", "root") ->get() as $row) { $cache[$row->key] = true; } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index b7e13b9a..d89b8401 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -354,7 +354,8 @@ class module_Core { $row = db::build() ->select("value") ->from("vars") - ->where(array("module_name" => "gallery", "name" => "_cache")) + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") ->execute() ->current(); if ($row) { @@ -395,8 +396,8 @@ class module_Core { */ static function set_var($module_name, $name, $value) { $var = ORM::factory("var") - ->where("module_name", $module_name) - ->where("name", $name) + ->where("module_name", "=", $module_name) + ->where("name", "=", $name) ->find(); if (!$var->loaded()) { $var->module_name = $module_name; @@ -432,8 +433,8 @@ class module_Core { */ static function clear_var($module_name, $name) { $var = ORM::factory("var") - ->where("module_name", $module_name) - ->where("name", $name) + ->where("module_name", "=", $module_name) + ->where("name", "=", $name) ->find(); if ($var->loaded()) { $var->delete(); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index ff86403a..82247eb0 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -90,11 +90,11 @@ class movie_Core { // Randomize the name if there's a conflict // @todo Improve this. Random numbers are not user friendly while (ORM::factory("item") - ->where("parent_id", $parent->id) - ->open_paren() - ->where("name", $movie->name) - ->orwhere("slug", $movie->slug) - ->close_paren() + ->where("parent_id", "=", $parent->id) + ->and_open() + ->where("name", "=", $movie->name) + ->orwhere("slug", "=", $movie->slug) + ->close() ->find()->id) { $rand = rand(); $movie->name = "{$name}.$rand.{$pi['extension']}"; diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 21cb13a0..2a563043 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -89,11 +89,11 @@ class photo_Core { // Randomize the name or slug if there's a conflict // @todo Improve this. Random numbers are not user friendly while (ORM::factory("item") - ->where("parent_id", $parent->id) - ->open_paren() - ->where("name", $photo->name) - ->orwhere("slug", $photo->slug) - ->close_paren() + ->where("parent_id", "=", $parent->id) + ->and_open() + ->where("name", "=", $photo->name) + ->orwhere("slug", "=", $photo->slug) + ->close() ->find()->id) { $rand = rand(); $photo->name = "{$name}.$rand.{$pi['extension']}"; diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index d58b935d..04316fff 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -67,7 +67,7 @@ class site_status_Core { */ private static function _add($msg, $severity, $permanent_key) { $message = ORM::factory("message") - ->where("key", $permanent_key) + ->where("key", "=", $permanent_key) ->find(); if (!$message->loaded()) { $message->key = $permanent_key; @@ -82,7 +82,7 @@ class site_status_Core { * @param string $permanent_key */ static function clear($permanent_key) { - $message = ORM::factory("message")->where("key", $permanent_key)->find(); + $message = ORM::factory("message")->where("key", "=", $permanent_key)->find(); if ($message->loaded()) { $message->delete(); } diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php index 42fae266..9a5e7dc1 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -131,7 +131,7 @@ class Gallery_I18n_Core { foreach (db::build() ->select("key", "translation") ->from("incoming_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); @@ -141,7 +141,7 @@ class Gallery_I18n_Core { foreach (db::build() ->select("key", "translation") ->from("outgoing_translations") - ->where(array("locale" => $locale)) + ->where("locale", "=", $locale) ->execute() ->as_array() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index eda445b6..a317798e 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -86,7 +86,7 @@ class Cache_Database_Driver extends Cache_Driver { public function get_tag($tags) { $db = db::build()->from("caches"); foreach ($tags as $tag) { - $db->where("tags", "like", "<$tag>"); + $db->where("tags", "LIKE", "<$tag>"); } $db_result = $db->execute()->as_array(); @@ -152,12 +152,12 @@ class Cache_Database_Driver extends Cache_Driver { public function delete($id, $tag = false) { $this->db->from("caches"); if ($id === true) { - $this->db->where(1); // Delete all caches + $this->db->where("1", "=", "1"); } else if ($tag === true) { $this->db->like("tags", "<$id>"); } else { - $this->db->where("key", $id); + $this->db->where("key", "=", $id); } $status = $this->db->delete(); @@ -178,7 +178,8 @@ class Cache_Database_Driver extends Cache_Driver { public function delete_expired() { // Delete all expired caches $status = $this->db->from("caches") - ->where(array("expiration !=" => 0, "expiration <=" => time())) + ->where("expiration", "<>", 0) + ->where("expiration", "<=", time()) ->delete(); return count($status) > 0; diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index c8386b1c..c8d25cc5 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -288,9 +288,9 @@ class Item_Model extends ORM_MPTT { foreach (Database::instance() ->select(array("name", "slug")) ->from("items") - ->where("left_ptr <=", $this->left_ptr) - ->where("right_ptr >=", $this->right_ptr) - ->where("id <>", 1) + ->where("left_ptr", "<=", $this->left_ptr) + ->where("right_ptr", ">=", $this->right_ptr) + ->where("id", "<>", 1) ->order_by("left_ptr", "ASC") ->get() as $row) { // Don't encode the names segment @@ -433,8 +433,8 @@ class Item_Model extends ORM_MPTT { // If the comparison column has NULLs in it, we can't use comparators on it and will have to // deal with it the hard way. $count = $db->from("items") - ->where("parent_id", $this->id) - ->where($this->sort_column, NULL) + ->where("parent_id", "=", $this->id) + ->where($this->sort_column, "=", NULL) ->where($where) ->count_records(); @@ -443,8 +443,8 @@ class Item_Model extends ORM_MPTT { $sort_column = $this->sort_column; $position = $db->from("items") - ->where("parent_id", $this->id) - ->where("$sort_column $comp ", $child->$sort_column) + ->where("parent_id", "=", $this->id) + ->where($sort_column, $comp, $child->$sort_column) ->where($where) ->count_records(); @@ -457,8 +457,8 @@ class Item_Model extends ORM_MPTT { // Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to // our base value. foreach ($db->from("items") - ->where("parent_id", $this->id) - ->where($sort_column, $child->$sort_column) + ->where("parent_id", "=", $this->id) + ->where($sort_column, "=", $child->$sort_column) ->where($where) ->order_by(array("id" => "ASC")) ->get() as $row) { @@ -484,7 +484,7 @@ class Item_Model extends ORM_MPTT { $position = 0; foreach ($db->select("id") ->from("items") - ->where("parent_id", $this->id) + ->where("parent_id", "=", $this->id) ->where($where) ->order_by($order_by) ->get() as $row) { diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index d90d7ed6..771c6a85 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -106,15 +106,15 @@ class Access_Helper_Test extends Unit_Test_Case { $item = album::create($root, rand(), "test album"); // New rows exist - $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); - $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); + $this->assert_true(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded()); + $this->assert_true(ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->loaded()); // Delete the item $item->delete(); // Rows are gone - $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded()); - $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded()); + $this->assert_false(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded()); + $this->assert_false(ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->loaded()); } public function new_photos_inherit_parent_permissions_test() { @@ -131,7 +131,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function can_allow_deny_and_reset_intent_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - $intent = ORM::factory("access_intent")->where("item_id", $album)->find(); + $intent = ORM::factory("access_intent")->where("item_id", "=", $album)->find(); // Allow access::allow(identity::everybody(), "view", $album); @@ -141,19 +141,19 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::everybody(), "view", $album); $this->assert_same( access::DENY, - ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); // Allow again. If the initial value was allow, then the first Allow clause above may not // have actually changed any values. access::allow(identity::everybody(), "view", $album); $this->assert_same( access::ALLOW, - ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); access::reset(identity::everybody(), "view", $album); $this->assert_same( null, - ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); } public function cant_reset_root_item_test() { diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index 6b525265..776c6625 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -20,7 +20,7 @@ class Cache_Test extends Unit_Test_Case { private $_driver; public function setup() { - Database::instance()->from("caches")->where(1)->delete(); + Database::instance()->from("caches")->where("1", "=", "1")->delete(); $this->_driver = new Cache_Database_Driver(); } diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 98bd4046..4f5a1da2 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -20,8 +20,8 @@ class Database_Test extends Unit_Test_Case { function simple_where_test() { $sql = Database::instance() - ->where("a", 1) - ->where("b", 2) + ->where("a", "=", 1) + ->where("b", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same("SELECT * WHERE `a` = 1 AND `b` = 2", $sql); @@ -29,12 +29,12 @@ class Database_Test extends Unit_Test_Case { function compound_where_test() { $sql = Database::instance() - ->where("outer1", 1) - ->open_paren() - ->where("inner1", 1) - ->orwhere("inner2", 2) - ->close_paren() - ->where("outer2", 2) + ->where("outer1", "=", 1) + ->and_open() + ->where("inner1", "=", 1) + ->orwhere("inner2", "=", 2) + ->close() + ->where("outer2", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -44,12 +44,12 @@ class Database_Test extends Unit_Test_Case { function group_first_test() { $sql = Database::instance() - ->open_paren() - ->where("inner1", 1) - ->orwhere("inner2", 2) - ->close_paren() - ->where("outer1", 1) - ->where("outer2", 2) + ->and_open() + ->where("inner1", "=", 1) + ->orwhere("inner2", "=", 2) + ->close() + ->where("outer1", "=", 1) + ->where("outer2", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -59,11 +59,12 @@ class Database_Test extends Unit_Test_Case { function where_array_test() { $sql = Database::instance() - ->where("outer1", 1) - ->open_paren() - ->where("inner1", 1) - ->orwhere(array("inner2" => 2, "inner3" => 3)) - ->close_paren() + ->where("outer1", "=", 1) + ->and_open() + ->where("inner1", "=", 1) + ->orwhere("inner2", "=", 2) + ->orwhere("inner3", "=", 3)) + ->close() ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -73,10 +74,10 @@ class Database_Test extends Unit_Test_Case { function notlike_test() { $sql = Database::instance() - ->where("outer1", 1) - ->open_paren() - ->ornotlike("inner1", 1) - ->close_paren() + ->where("outer1", "=", 1) + ->or_open() + ->where("inner1", "NOT LIKE", 1) + ->close() ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( @@ -118,7 +119,7 @@ class Database_Test extends Unit_Test_Case { function prefix_no_replacement_test() { $update = Database_For_Test::instance()->from("test_tables") - ->where("1 = 1") + ->where("1", "=", "1") ->set(array("name" => "Test Name")) ->update(); diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php index 36ced2bb..f36f638f 100644 --- a/modules/gallery/tests/Gallery_Installer_Test.php +++ b/modules/gallery/tests/Gallery_Installer_Test.php @@ -29,7 +29,7 @@ class Gallery_Installer_Test extends Unit_Test_Case { } public function install_registers_gallery_module_test() { - $gallery = ORM::factory("module")->where("name", "gallery")->find(); + $gallery = ORM::factory("module")->where("name", "=", "gallery")->find(); $this->assert_equal("gallery", $gallery->name); } diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php index d0555cbf..895e3051 100644 --- a/modules/gallery/tests/I18n_Test.php +++ b/modules/gallery/tests/I18n_Test.php @@ -29,7 +29,7 @@ class Gallery_I18n_Test extends Unit_Test_Case { $this->i18n = Gallery_I18n::instance($config); ORM::factory("incoming_translation") - ->where("locale", "te_ST") + ->where("locale", "=", "te_ST") ->delete_all(); $messages_te_ST = array( @@ -62,7 +62,7 @@ class Gallery_I18n_Test extends Unit_Test_Case { $locale = $this->i18n->locale(); $this->assert_equal("de_DE", $locale); } - + public function translate_simple_test() { $result = $this->i18n->translate('Hello world'); $this->assert_equal('Hallo Welt', $result); diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index a364423a..f0c653c0 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -29,13 +29,13 @@ class Item_Helper_Test extends Unit_Test_Case { access::allow(identity::everybody(), "view", $album); $this->assert_equal( 1, - ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); + ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); // We can't see the item when permissions are denied access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, - ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); + ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); } public function validate_url_safe_test() { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index e6d09d74..951e6e52 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -54,7 +54,7 @@ class notification_event_Core { static function user_deleted($user) { ORM::factory("subscriptions") - ->where(array("user_id", $user->id)) + ->where("user_id", "=", $user->id) ->delete_all(); } @@ -88,7 +88,7 @@ class notification_event_Core { static function user_before_delete($user) { try { ORM::factory("subscription") - ->where("user_id", $user->id) + ->where("user_id", "=", $user->id) ->delete_all(); } catch (Exception $e) { Kohana_Log::add("error", "@todo notification_event::user_before_delete() failed"); diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 9d732c11..c0bb1b32 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -60,7 +60,7 @@ class search_Core { static function update($item) { $data = new ArrayObject(); - $record = ORM::factory("search_record")->where("item_id", $item->id)->find(); + $record = ORM::factory("search_record")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { $record->item_id = $item->id; } @@ -76,10 +76,10 @@ class search_Core { ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") - ->open_paren() - ->where("search_records.item_id", null) - ->orwhere("search_records.dirty", 1) - ->close_paren() + ->and_open() + ->where("search_records.item_id", "=", null) + ->orwhere("search_records.dirty", "=", 1) + ->close() ->get() ->count(); diff --git a/modules/search/helpers/search_event.php b/modules/search/helpers/search_event.php index 836bbe15..1add6e5f 100644 --- a/modules/search/helpers/search_event.php +++ b/modules/search/helpers/search_event.php @@ -28,7 +28,7 @@ class search_event_Core { static function item_deleted($item) { ORM::factory("search_record") - ->where("item_id", $item->id) + ->where("item_id", "=", $item->id) ->delete_all(); } diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 9508f420..061f4084 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -45,8 +45,8 @@ class search_task_Core { $start = microtime(true); foreach (ORM::factory("item") ->join("search_records", "items.id", "search_records.item_id", "left") - ->where("search_records.item_id", null) - ->orwhere("search_records.dirty", 1) + ->where("search_records.item_id", "=", null) + ->orwhere("search_records.dirty", "=", 1) ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 053a1891..3c3a6c2b 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -177,7 +177,7 @@ class Server_Add_Controller extends Admin_Controller { $task->percent_complete = min($task->percent_complete + 0.1, 10); $task->status = t2("Found one file", "Found %count files", Database::instance() - ->where("task_id", $task->id) + ->where("task_id", "=", $task->id) ->count_records("server_add_files")); if (!$queue) { @@ -197,8 +197,8 @@ class Server_Add_Controller extends Admin_Controller { // will create albums first. Ignore entries which already have an Item_Model attached, // they're done. $entries = ORM::factory("server_add_file") - ->where("task_id", $task->id) - ->where("item_id", null) + ->where("task_id", "=", $task->id) + ->where("item_id", "=", null) ->order_by("id", "ASC") ->limit(10) ->find_all(); @@ -265,7 +265,7 @@ class Server_Add_Controller extends Admin_Controller { $task->done = true; $task->state = "success"; $task->percent_complete = 100; - ORM::factory("server_add_file")->where("task_id", $task->id)->delete_all(); + ORM::factory("server_add_file")->where("task_id", "=", $task->id)->delete_all(); message::info(t2("Successfully added one photo / album", "Successfully added %count photos / albums", $task->get("completed_files"))); diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index aff44803..6cd2f337 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -106,7 +106,7 @@ class Admin_Tags_Controller extends Admin_Controller { } public function check_for_duplicate(Validation $post_data, $field) { - $tag_exists = ORM::factory("tag")->where("name", $post_data[$field])->count_all(); + $tag_exists = ORM::factory("tag")->where("name", "=", $post_data[$field])->count_all(); if ($tag_exists) { $post_data->add_error($field, "in_use"); } diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 8694bcec..c4c4ba15 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -33,7 +33,7 @@ class tag_Core { throw new exception("@todo MISSING_TAG_NAME"); } - $tag = ORM::factory("tag")->where("name", $tag_name)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag_name)->find(); if (!$tag->loaded()) { $tag->name = $tag_name; $tag->count = 0; @@ -93,7 +93,7 @@ class tag_Core { ->select("name") ->from("tags") ->join("items_tags", "tags.id", "items_tags.tag_id", "left") - ->where("items_tags.item_id", $item->id) + ->where("items_tags.item_id", "=", $item->id) ->get() as $row) { $tags[] = $row->name; } diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index be020f5f..f9a453be 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -31,9 +31,9 @@ class Tag_Model extends ORM { $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id); + ->where("items_tags.tag_id", "=", $this->id); if ($type) { - $model->where("items.type", $type); + $model->where("items.type", "=", $type); } return $model->find_all($limit, $offset); } @@ -47,10 +47,10 @@ class Tag_Model extends ORM { $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id); + ->where("items_tags.tag_id", "=", $this->id); if ($type) { - $model->where("items.type", $type); + $model->where("items.type", "=", $type); } return $model->count_all(); } diff --git a/modules/tag/tests/Tag_Test.php b/modules/tag/tests/Tag_Test.php index c9a96286..c96e7f2b 100644 --- a/modules/tag/tests/Tag_Test.php +++ b/modules/tag/tests/Tag_Test.php @@ -25,18 +25,18 @@ class Tag_Test extends Unit_Test_Case { $tag1 = "tag1"; tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(1, $tag->count); // Make sure adding the tag again doesn't increase the count tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(1, $tag->count); $rand = rand(); $album = album::create($root, $rand, $rand, $rand); tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(2, $tag->count); } } \ No newline at end of file diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 1beaa1c2..2ada0ac1 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -31,7 +31,7 @@ class group_Core { * @return Group_Definition the group object */ static function create($name) { - $group = ORM::factory("group")->where("name", $name)->find(); + $group = ORM::factory("group")->where("name", "=", $name)->find(); if ($group->loaded()) { throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); } diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 4ed9daee..5027580c 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -44,7 +44,7 @@ class user_Core { * @return User_Model */ static function create($name, $full_name, $password) { - $user = ORM::factory("user")->where("name", $name)->find(); + $user = ORM::factory("user")->where("name", "=", $name)->find(); if ($user->loaded()) { throw new Exception("@todo USER_ALREADY_EXISTS $name"); } diff --git a/modules/user/tests/User_Groups_Test.php b/modules/user/tests/User_Groups_Test.php index 6aedfde5..163b7d79 100644 --- a/modules/user/tests/User_Groups_Test.php +++ b/modules/user/tests/User_Groups_Test.php @@ -21,14 +21,14 @@ class User_Groups_Test extends Unit_Test_Case { public function teardown() { try { - $group = ORM::factory("group")->where("name", "user_groups_test")->find(); + $group = ORM::factory("group")->where("name", "=", "user_groups_test")->find(); if ($group->loaded()) { $group->delete(); } } catch (Exception $e) { } try { - $user = ORM::factory("user")->where("name", "user_groups_test")->find(); + $user = ORM::factory("user")->where("name", "=", "user_groups_test")->find(); if ($user->loaded()) { $user->delete(); } -- cgit v1.2.3 From dd2bca022479f5971ca3afd3d8284474c6c5e87a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 12:54:07 -0800 Subject: Modify the expiration code to work with db::build() --- modules/comment/controllers/admin_comments.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index 271c7d51..c67fc4a4 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -22,10 +22,11 @@ class Admin_Comments_Controller extends Admin_Controller { public function index() { // Get rid of old deleted/spam comments once in a while - Database::instance()->query( - "DELETE FROM {comments} " . - "WHERE state IN ('deleted', 'spam') " . - "AND unix_timestamp(now()) - updated > 86400 * 7"); + db::build() + ->delete("comments") + ->where("state", "IN", array("deleted", "spam")) + ->where("updated", "<", "UNIX_TIMESTAMP() - 86400 * 7") + ->execute(); // Redirect to the appropriate queue url::redirect("admin/comments/queue/unpublished"); -- cgit v1.2.3 From d036e2fc49a41771fb16decb0ce699245d40cff0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 13:18:10 -0800 Subject: Convert another Database::instance() query over to using db::build() --- modules/comment/controllers/admin_comments.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index c67fc4a4..880c33a7 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -96,11 +96,12 @@ class Admin_Comments_Controller extends Admin_Controller { $counts->published = 0; $counts->spam = 0; $counts->deleted = 0; - foreach (Database::instance() - ->select("state", "count(*) as c") + foreach (db::build() + ->select("state") + ->select(array("c" => 'COUNT("*")')) ->from("comments") - ->groupby("state") - ->get() as $row) { + ->group_by("state") + ->execute() as $row) { $counts->{$row->state} = $row->c; } return $counts; -- cgit v1.2.3 From f77b26e988048bfd31d1e59695fe7ca015696a24 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 14:38:01 -0800 Subject: Add kohana23_compat module to bring along functionality that got deleted, but we still want. Start off with the Pagination library. --- application/config/config.php | 1 + modules/kohana23_compat/config/pagination.php | 25 +++ modules/kohana23_compat/libraries/Pagination.php | 234 +++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 modules/kohana23_compat/config/pagination.php create mode 100644 modules/kohana23_compat/libraries/Pagination.php (limited to 'modules') diff --git a/application/config/config.php b/application/config/config.php index ad485266..aecc400c 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -142,6 +142,7 @@ $config['config_drivers'] = array(); */ $config["modules"] = array( MODPATH . "forge", + MODPATH . "kohana23_compat", MODPATH . "gallery", // gallery must be *last* in the order ); diff --git a/modules/kohana23_compat/config/pagination.php b/modules/kohana23_compat/config/pagination.php new file mode 100644 index 00000000..808fc315 --- /dev/null +++ b/modules/kohana23_compat/config/pagination.php @@ -0,0 +1,25 @@ + 'pagination', + 'style' => 'classic', + 'uri_segment' => 3, + 'query_string' => '', + 'items_per_page' => 20, + 'auto_hide' => FALSE, +); diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php new file mode 100644 index 00000000..8ff8bf94 --- /dev/null +++ b/modules/kohana23_compat/libraries/Pagination.php @@ -0,0 +1,234 @@ +initialize($config); + } + + /** + * Sets config values. + * + * @throws Kohana_Exception + * @param array configuration settings + * @return void + */ + public function initialize($config = array()) + { + // Load config group + if (isset($config['group'])) + { + // Load and validate config group + if ( ! is_array($group_config = Kohana::config('pagination.'.$config['group']))) + throw new Kohana_Exception('pagination.undefined_group: ' . $config['group']); + + // All pagination config groups inherit default config group + if ($config['group'] !== 'default') + { + // Load and validate default config group + if ( ! is_array($default_config = Kohana::config('pagination.default'))) + throw new Kohana_Exception('pagination.undefined_group: default'); + + // Merge config group with default config group + $group_config += $default_config; + } + + // Merge custom config items with config group + $config += $group_config; + } + + // Assign config values to the object + foreach ($config as $key => $value) + { + if (property_exists($this, $key)) + { + $this->$key = $value; + } + } + + // Clean view directory + $this->directory = trim($this->directory, '/').'/'; + + // Build generic URL with page in query string + if ($this->query_string !== '') + { + // Extract current page + $this->current_page = isset($_GET[$this->query_string]) ? (int) $_GET[$this->query_string] : 1; + + // Insert {page} placeholder + $_GET[$this->query_string] = '{page}'; + + // Create full URL + $base_url = ($this->base_url === '') ? Router::$current_uri : $this->base_url; + $this->url = url::site($base_url).'?'.str_replace('%7Bpage%7D', '{page}', http_build_query($_GET)); + + // Reset page number + $_GET[$this->query_string] = $this->current_page; + } + + // Build generic URL with page as URI segment + else + { + // Use current URI if no base_url set + $this->url = ($this->base_url === '') ? Router::$segments : explode('/', trim($this->base_url, '/')); + + // Convert uri 'label' to corresponding integer if needed + if (is_string($this->uri_segment)) + { + if (($key = array_search($this->uri_segment, $this->url)) === FALSE) + { + // If uri 'label' is not found, auto add it to base_url + $this->url[] = $this->uri_segment; + $this->uri_segment = count($this->url) + 1; + } + else + { + $this->uri_segment = $key + 2; + } + } + + // Insert {page} placeholder + $this->url[$this->uri_segment - 1] = '{page}'; + + // Create full URL + $this->url = url::site(implode('/', $this->url)).Router::$query_string; + + // Extract current page + $this->current_page = URI::instance()->segment($this->uri_segment); + } + + // Core pagination values + $this->total_items = (int) max(0, $this->total_items); + $this->items_per_page = (int) max(1, $this->items_per_page); + $this->total_pages = (int) ceil($this->total_items / $this->items_per_page); + $this->current_page = (int) min(max(1, $this->current_page), max(1, $this->total_pages)); + $this->current_first_item = (int) min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items); + $this->current_last_item = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items); + + // If there is no first/last/previous/next page, relative to the + // current page, value is set to FALSE. Valid page number otherwise. + $this->first_page = ($this->current_page === 1) ? FALSE : 1; + $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages; + $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE; + $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE; + + // SQL values + $this->sql_offset = (int) ($this->current_page - 1) * $this->items_per_page; + $this->sql_limit = sprintf(' LIMIT %d OFFSET %d ', $this->items_per_page, $this->sql_offset); + } + + /** + * Generates the HTML for the chosen pagination style. + * + * @param string pagination style + * @return string pagination html + */ + public function render($style = NULL) + { + // Hide single page pagination + if ($this->auto_hide === TRUE AND $this->total_pages <= 1) + return ''; + + if ($style === NULL) + { + // Use default style + $style = $this->style; + } + + // Return rendered pagination view + return View::factory($this->directory.$style, get_object_vars($this))->render(); + } + + /** + * Magically converts Pagination object to string. + * + * @return string pagination html + */ + public function __toString() + { + return $this->render(); + } + + /** + * Magically gets a pagination variable. + * + * @param string variable key + * @return mixed variable value if the key is found + * @return void if the key is not found + */ + public function __get($key) + { + if (isset($this->$key)) + return $this->$key; + } + + /** + * Adds a secondary interface for accessing properties, e.g. $pagination->total_pages(). + * Note that $pagination->total_pages is the recommended way to access properties. + * + * @param string function name + * @return string + */ + public function __call($func, $args = NULL) + { + return $this->__get($func); + } + +} // End Pagination Class \ No newline at end of file -- cgit v1.2.3 From 54be15191b983e72b4643f3559303b35b7c48795 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 18:47:40 -0800 Subject: Overload Database_Builder to add merge_where() which takes predefined where clauses and adds them to the existing query. Update all existing queries that take an additional where clause to use it. --- modules/gallery/controllers/movies.php | 2 +- modules/gallery/controllers/photos.php | 2 +- modules/gallery/libraries/ORM_MPTT.php | 8 +++--- modules/gallery/models/item.php | 16 ++++++----- .../libraries/MY_Database_Builder.php | 31 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 modules/kohana23_compat/libraries/MY_Database_Builder.php (limited to 'modules') diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 7ceeefdf..157c388f 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -21,7 +21,7 @@ class Movies_Controller extends Items_Controller { public function _show($movie) { access::required("view", $movie); - $where = array("type != " => "album"); + $where = array(array("type", "!=", "album")); $position = $movie->parent()->get_position($movie, $where); if ($position > 1) { list ($previous_item, $ignore, $next_item) = diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 0d7daac4..478447b1 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -21,7 +21,7 @@ class Photos_Controller extends Items_Controller { public function _show($photo) { access::required("view", $photo); - $where = array("type != " => "album"); + $where = array(array("type", "!=", "album")); $position = $photo->parent()->get_position($photo, $where); if ($position > 1) { list ($previous_item, $ignore, $next_item) = diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 01b2d7b7..90b9d38a 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -152,7 +152,7 @@ class ORM_MPTT_Core extends ORM { */ function children($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { if ($where) { - $this->where($where); + $this->merge_where($where); } return $this @@ -170,7 +170,7 @@ class ORM_MPTT_Core extends ORM { */ function children_count($where=null) { if ($where) { - $this->where($where); + $this->merge_where($where); } return $this @@ -189,7 +189,7 @@ class ORM_MPTT_Core extends ORM { */ function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { if ($where) { - $this->where($where); + $this->merge_where($where); } return $this @@ -207,7 +207,7 @@ class ORM_MPTT_Core extends ORM { */ function descendants_count($where=null) { if ($where) { - $this->where($where); + $this->merge_where($where); } return $this diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index c8d25cc5..acc4e96f 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -428,14 +428,14 @@ class Item_Model extends ORM_MPTT { } else { $comp = "<"; } - $db = Database::instance(); + $db = db::build(); // If the comparison column has NULLs in it, we can't use comparators on it and will have to // deal with it the hard way. $count = $db->from("items") ->where("parent_id", "=", $this->id) ->where($this->sort_column, "=", NULL) - ->where($where) + ->merge_where($where) ->count_records(); if (empty($count)) { @@ -445,7 +445,7 @@ class Item_Model extends ORM_MPTT { $position = $db->from("items") ->where("parent_id", "=", $this->id) ->where($sort_column, $comp, $child->$sort_column) - ->where($where) + ->merge_where($where) ->count_records(); // We stopped short of our target value in the sort (notice that we're using a < comparator @@ -456,12 +456,14 @@ class Item_Model extends ORM_MPTT { // // Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to // our base value. - foreach ($db->from("items") + foreach ($db + ->select("id") + ->from("items") ->where("parent_id", "=", $this->id) ->where($sort_column, "=", $child->$sort_column) - ->where($where) + ->merge_where($where) ->order_by(array("id" => "ASC")) - ->get() as $row) { + ->execute() as $row) { $position++; if ($row->id == $child->id) { break; @@ -485,7 +487,7 @@ class Item_Model extends ORM_MPTT { foreach ($db->select("id") ->from("items") ->where("parent_id", "=", $this->id) - ->where($where) + ->merge_where($where) ->order_by($order_by) ->get() as $row) { $position++; diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php new file mode 100644 index 00000000..974f9c6d --- /dev/null +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -0,0 +1,31 @@ +where($tuple[0], $tuple[1], $tuple[2]); + } + return $this; + } +} \ No newline at end of file -- cgit v1.2.3 From 9fd6a0a63e95f1fd73e0ebb224c1c1dd30686858 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 19:23:36 -0800 Subject: Convert Database::instance() -> db::build() --- modules/exif/helpers/exif_theme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/exif/helpers/exif_theme.php b/modules/exif/helpers/exif_theme.php index db51f305..23dc95c2 100644 --- a/modules/exif/helpers/exif_theme.php +++ b/modules/exif/helpers/exif_theme.php @@ -21,11 +21,11 @@ class exif_theme_Core { static function sidebar_bottom($theme) { $item = $theme->item(); if ($item && $item->is_photo()) { - $record = Database::instance() + $record = db::build() ->select("key_count") ->from("exif_records") ->where("item_id", "=", $item->id) - ->get() + ->execute() ->current(); if ($record && $record->key_count) { $view = new View("exif_sidebar.html"); -- cgit v1.2.3 From e0e882baabe9d4436c12bd57f903159c3b0274d9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 19:25:09 -0800 Subject: Fix the arguments to Item_Model::descendants_count() --- modules/slideshow/helpers/slideshow_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index 0afe8126..9b77dd42 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -32,7 +32,7 @@ class slideshow_event_Core { static function album_menu($menu, $theme) { $descendants_count = ORM::factory("item", $theme->item()->id) - ->descendants_count(array("type" => "photo")); + ->descendants_count(array(array("type", "=", "photo"))); if ($descendants_count > 1) { $menu->append(Menu::factory("link") ->id("slideshow") -- cgit v1.2.3 From e8fb773b68335e955602c0d912e13c0f5ba23d58 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 19:33:03 -0800 Subject: Update all portable where clauses to the new Kohana 2.4 format. --- modules/gallery/helpers/gallery_rss.php | 4 ++-- modules/gallery/tests/ORM_MPTT_Test.php | 4 ++-- modules/organize/views/organize_tree.html.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 93ace10b..4aef27ad 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -49,9 +49,9 @@ class gallery_rss_Core { $feed->children = $item ->viewable() - ->descendants($limit, $offset, array("type" => "photo")); + ->descendants($limit, $offset, array(array("type", "=", "photo"))); $feed->max_pages = ceil( - $item->viewable()->descendants_count(array("type" => "photo")) / $limit); + $item->viewable()->descendants_count(array("type", "=", "photo")) / $limit); $feed->title = html::purify($item->title); $feed->description = nl2br(html::purify($item->description)); diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index a749542b..36a81d2c 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -228,7 +228,7 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent->reload(); $this->assert_equal(3, $parent->descendants_count()); - $this->assert_equal(2, $parent->descendants_count(array("type" => "photo"))); - $this->assert_equal(1, $parent->descendants_count(array("type" => "album"))); + $this->assert_equal(2, $parent->descendants_count(array(array("type", "=", "photo")))); + $this->assert_equal(1, $parent->descendants_count(array(array("type", "=", "album")))); } } diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 740c2521..1ccb942c 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -8,7 +8,7 @@ title) ?>
    - children(null, 0, array("type" => "album")) as $child): ?> + children(null, 0, array(array("type", "=", "album"))) as $child): ?> contains($selected)): ?> $selected, "album" => $child)); ?> -- cgit v1.2.3 From a3d904bcbab7cb153c2b617fc4389175ed00a4fc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 19:36:57 -0800 Subject: ORM::find_all() now uses null as the default value for offset. --- modules/gallery/libraries/ORM_MPTT.php | 2 +- modules/gallery/models/item.php | 2 +- modules/organize/views/organize_tree.html.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 90b9d38a..a67f05be 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -150,7 +150,7 @@ class ORM_MPTT_Core extends ORM { * @param array order_by * @return array ORM */ - function children($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + function children($limit=null, $offset=null, $where=null, $order_by=array("id" => "ASC")) { if ($where) { $this->merge_where($where); } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index acc4e96f..16c57dbc 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -597,7 +597,7 @@ class Item_Model extends ORM_MPTT { * @param array order_by * @return array ORM */ - function children($limit=null, $offset=0, $where=array(), $order_by=null) { + function children($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 1ccb942c..c5257956 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -8,7 +8,7 @@ title) ?>
      - children(null, 0, array(array("type", "=", "album"))) as $child): ?> + children(null, null, array(array("type", "=", "album"))) as $child): ?> contains($selected)): ?> $selected, "album" => $child)); ?> -- cgit v1.2.3 From 3dd8bf245ea16fe1b9f1c27c4ad42d11d3cde1ee Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 20:24:16 -0800 Subject: Kohana::$user_agent moved to the request helper and is protected, so instead set the user agent into $_SERVER. --- modules/gallery/hooks/init_gallery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/hooks/init_gallery.php b/modules/gallery/hooks/init_gallery.php index 4ce9bab4..c7355260 100644 --- a/modules/gallery/hooks/init_gallery.php +++ b/modules/gallery/hooks/init_gallery.php @@ -42,5 +42,5 @@ if ($g3sid = $input->post("g3sid", $input->get("g3sid"))) { } if ($user_agent = $input->post("user_agent", $input->get("user_agent"))) { - Kohana::$user_agent = $user_agent; + $_SERVER["HTTP_USER_AGENT"] = $user_agent; } -- cgit v1.2.3 From dee3ee81e2013f0b38e0f84123dec2ce12574bd7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 20:25:32 -0800 Subject: Database::orwhere() is now Database_Builder::or_where() --- modules/exif/helpers/exif.php | 2 +- modules/exif/helpers/exif_task.php | 2 +- modules/gallery/controllers/albums.php | 2 +- modules/gallery/controllers/movies.php | 2 +- modules/gallery/controllers/photos.php | 2 +- modules/gallery/helpers/album.php | 2 +- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/tests/Database_Test.php | 8 ++++---- modules/search/helpers/search.php | 2 +- modules/search/helpers/search_task.php | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) (limited to 'modules') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index b4241e89..a8b12a8b 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -146,7 +146,7 @@ class exif_Core { ->where("type", "=", "photo") ->and_open() ->where("exif_records.item_id", "=", null) - ->orwhere("exif_records.dirty", "=", 1) + ->or_where("exif_records.dirty", "=", 1) ->close() ->get() ->count(); diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 1a449fc7..66f69790 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -47,7 +47,7 @@ class exif_task_Core { ->where("type", "=", "photo") ->and_open() ->where("exif_records.item_id", "=", null) - ->orwhere("exif_records.dirty", "=", 1) + ->or_where("exif_records.dirty", "=", 1) ->close() ->find_all() as $item) { // The query above can take a long time, so start the timer after its done diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 431d98a0..32db48d4 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -130,7 +130,7 @@ class Albums_Controller extends Items_Controller { ->where("id", "<>", $album->id) ->and_open() ->where("name", "=", $form->edit_item->dirname->value) - ->orwhere("slug", "=", $form->edit_item->slug->value) + ->or_where("slug", "=", $form->edit_item->slug->value) ->close() ->get() ->current()) { diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 157c388f..e017b8c8 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -78,7 +78,7 @@ class Movies_Controller extends Items_Controller { ->where("id <>", $movie->id) ->and_open() ->where("name", "=", $form->edit_item->filename->value) - ->orwhere("slug", "=", $form->edit_item->slug->value) + ->or_where("slug", "=", $form->edit_item->slug->value) ->close() ->get() ->current()) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 478447b1..5431fcfe 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -78,7 +78,7 @@ class Photos_Controller extends Items_Controller { ->where("id", "<>", $photo->id) ->and_open() ->where("name", "=", $form->edit_item->filename->value) - ->orwhere("slug", "=", $form->edit_item->slug->value) + ->or_where("slug", "=", $form->edit_item->slug->value) ->close() ->get() ->current()) { diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index cd8777e2..0ffb0fc6 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -71,7 +71,7 @@ class album_Core { ->where("parent_id", "=", $parent->id) ->and_open() ->where("name", "=", $album->name) - ->orwhere("slug", "=", $album->slug) + ->or_where("slug", "=", $album->slug) ->close() ->find()->id) { $rand = rand(); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 82247eb0..96dafe11 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -93,7 +93,7 @@ class movie_Core { ->where("parent_id", "=", $parent->id) ->and_open() ->where("name", "=", $movie->name) - ->orwhere("slug", "=", $movie->slug) + ->or_where("slug", "=", $movie->slug) ->close() ->find()->id) { $rand = rand(); diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 2a563043..cc309e28 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -92,7 +92,7 @@ class photo_Core { ->where("parent_id", "=", $parent->id) ->and_open() ->where("name", "=", $photo->name) - ->orwhere("slug", "=", $photo->slug) + ->or_where("slug", "=", $photo->slug) ->close() ->find()->id) { $rand = rand(); diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 4f5a1da2..9b428379 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -32,7 +32,7 @@ class Database_Test extends Unit_Test_Case { ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) - ->orwhere("inner2", "=", 2) + ->or_where("inner2", "=", 2) ->close() ->where("outer2", "=", 2) ->compile(); @@ -46,7 +46,7 @@ class Database_Test extends Unit_Test_Case { $sql = Database::instance() ->and_open() ->where("inner1", "=", 1) - ->orwhere("inner2", "=", 2) + ->or_where("inner2", "=", 2) ->close() ->where("outer1", "=", 1) ->where("outer2", "=", 2) @@ -62,8 +62,8 @@ class Database_Test extends Unit_Test_Case { ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) - ->orwhere("inner2", "=", 2) - ->orwhere("inner3", "=", 3)) + ->or_where("inner2", "=", 2) + ->or_where("inner3", "=", 3)) ->close() ->compile(); $sql = str_replace("\n", " ", $sql); diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index c0bb1b32..1fd5175f 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -78,7 +78,7 @@ class search_Core { ->join("search_records", "items.id", "search_records.item_id", "left") ->and_open() ->where("search_records.item_id", "=", null) - ->orwhere("search_records.dirty", "=", 1) + ->or_where("search_records.dirty", "=", 1) ->close() ->get() ->count(); diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 061f4084..6b35cabc 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -46,7 +46,7 @@ class search_task_Core { foreach (ORM::factory("item") ->join("search_records", "items.id", "search_records.item_id", "left") ->where("search_records.item_id", "=", null) - ->orwhere("search_records.dirty", "=", 1) + ->or_where("search_records.dirty", "=", 1) ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. -- cgit v1.2.3 From ddf668d43958e060f5aa4a14a4ef8dc8d2b51d2b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 21:14:17 -0800 Subject: utf8::clean() is now Input::clean() --- modules/exif/helpers/exif.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index a8b12a8b..d3a8c103 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -39,7 +39,7 @@ class exif_Core { if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($value); } - $keys[$field] = utf8::clean($value); + $keys[$field] = Input::clean($value); if ($field == "DateTime") { $time = strtotime($value); @@ -62,7 +62,7 @@ class exif_Core { if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($value); } - $keys[$keyword] = utf8::clean($value); + $keys[$keyword] = Input::clean($value); if ($keyword == "Caption" && !$item->description) { $item->description = $value; -- cgit v1.2.3 From b9a0e0963746420d82ad3107135aa7a9256825be Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 21:14:43 -0800 Subject: Kohana::config_xxx() is now Kohana_Config::instance()->xxx --- modules/gallery/helpers/graphics.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index e45a5125..c93cc304 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -371,18 +371,18 @@ class graphics_Core { } switch(module::get_var("gallery", "graphics_toolkit")) { case "gd": - Kohana::config_set("image.driver", "GD"); + Kohana_Config::instance()->set("image.driver", "GD"); break; case "imagemagick": - Kohana::config_set("image.driver", "ImageMagick"); - Kohana::config_set( + Kohana_Config::instance()->set("image.driver", "ImageMagick"); + Kohana_Config::instance()->set( "image.params.directory", module::get_var("gallery", "graphics_toolkit_path")); break; case "graphicsmagick": - Kohana::config_set("image.driver", "GraphicsMagick"); - Kohana::config_set( + Kohana_Config::instance()->set("image.driver", "GraphicsMagick"); + Kohana_Config::instance()->set( "image.params.directory", module::get_var("gallery", "graphics_toolkit_path")); break; } -- cgit v1.2.3 From 96b00d6cfe437e376d5547a10aa8d1cf7def8c13 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 26 Nov 2009 21:14:54 -0800 Subject: Convert some more Database::instance() calls to db::build() form. --- modules/comment/helpers/comment_event.php | 5 +- modules/gallery/helpers/item.php | 4 +- modules/gallery/libraries/ORM_MPTT.php | 90 +++++++++++++++++---------- modules/gallery/models/item.php | 6 +- modules/notification/helpers/notification.php | 4 +- modules/tag/helpers/tag.php | 4 +- 6 files changed, 69 insertions(+), 44 deletions(-) (limited to 'modules') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index cf5d0a60..c90f7663 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -62,12 +62,11 @@ class comment_event_Core { } static function item_index_data($item, $data) { - foreach (Database::instance() + foreach (db::build() ->select("text") ->from("comments") ->where("item_id", "=", $item->id) - ->get() - ->as_array() as $row) { + ->execute() as $row) { $data[] = $row->text; } } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 7496d368..c3126435 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -140,10 +140,10 @@ class item_Core { // Guard against an empty result when we create the first item. It's unfortunate that we // have to check this every time. // @todo: figure out a better way to bootstrap the weight. - $result = Database::instance() + $result = db::build() ->select("weight")->from("items") ->order_by("weight", "desc")->limit(1) - ->get()->current(); + ->execute()->current(); return ($result ? $result->weight : 0) + 1; } diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index a67f05be..0ec0a848 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -51,10 +51,16 @@ class ORM_MPTT_Core extends ORM { try { // Make a hole in the parent for this new item - $this->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + 2 WHERE `left_ptr` >= {$parent->right_ptr}"); - $this->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + 2 WHERE `right_ptr` >= {$parent->right_ptr}"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + 2")) + ->where("left_ptr", ">=", $parent->right_ptr) + ->execute(); + $this->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` + 2")) + ->where("right_ptr", ">=", $parent->right_ptr) + ->execute(); $parent->right_ptr += 2; // Insert this item into the hole @@ -92,10 +98,16 @@ class ORM_MPTT_Core extends ORM { $this->lock(); try { - $this->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - 2 WHERE `left_ptr` > {$this->right_ptr}"); - $this->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - 2 WHERE `right_ptr` > {$this->right_ptr}"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` - 2")) + ->where("left_ptr", ">", $this->right_ptr) + ->execute(); + $this->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` - 2")) + ->where("right_ptr", ">", $this->right_ptr) + ->execute(); } catch (Exception $e) { $this->unlock(); throw $e; @@ -239,23 +251,32 @@ class ORM_MPTT_Core extends ORM { try { if ($level_delta) { // Update the levels for the to-be-moved items - $this->db->query( - "UPDATE {{$this->table_name}} SET `level` = `level` + $level_delta" . - " WHERE `left_ptr` >= $original_left_ptr AND `right_ptr` <= $original_right_ptr"); + $this->db_builder + ->update($this->table_name) + ->set("level", new Database_Expression("`level` + $level_delta")) + ->where("left_ptr", ">=", $original_left_ptr) + ->where("right_ptr", "<=", $original_right_ptr) + ->execute(); } // Make a hole in the target for the move - $target->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + $size_of_hole" . - " WHERE `left_ptr` >= $target_right_ptr"); - $target->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + $size_of_hole" . - " WHERE `right_ptr` >= $target_right_ptr"); + $target->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole")) + ->where("left_ptr", ">=", $target_right_ptr) + ->execute(); + $target->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole")) + ->where("right_ptr", ">=", $target_right_ptr) + ->execute(); // Change the parent. - $this->db->query( - "UPDATE {{$this->table_name}} SET `parent_id` = {$target->id}" . - " WHERE `id` = {$this->id}"); + $this->db_builder + ->update($this->table_name) + ->set("parent_id", $target->id) + ->where("id", "=", $this->id) + ->execute(); // If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above. $left_ptr = $original_left_ptr; @@ -266,20 +287,25 @@ class ORM_MPTT_Core extends ORM { } $new_offset = $target->right_ptr - $left_ptr; - $this->db->query( - "UPDATE {{$this->table_name}}" . - " SET `left_ptr` = `left_ptr` + $new_offset," . - " `right_ptr` = `right_ptr` + $new_offset" . - " WHERE `left_ptr` >= $left_ptr" . - " AND `right_ptr` <= $right_ptr"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset")) + ->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset")) + ->where("left_ptr", ">=", $left_ptr) + ->where("right_ptr", "<=", $right_ptr) + ->execute(); // Close the hole in the source's parent after the move - $this->db->query( - "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - $size_of_hole" . - " WHERE `left_ptr` > $right_ptr"); - $this->db->query( - "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - $size_of_hole" . - " WHERE `right_ptr` > $right_ptr"); + $this->db_builder + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole")) + ->where("left_ptr", ">", $right_ptr) + ->execute(); + $this->db_builder + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole")) + ->where("right_ptr", ">", $right_ptr) + ->execute(); } catch (Exception $e) { $this->unlock(); throw $e; diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 16c57dbc..8a42cc1e 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -285,14 +285,14 @@ class Item_Model extends ORM_MPTT { private function _build_relative_caches() { $names = array(); $slugs = array(); - foreach (Database::instance() + foreach (db::build() ->select(array("name", "slug")) ->from("items") ->where("left_ptr", "<=", $this->left_ptr) ->where("right_ptr", ">=", $this->right_ptr) ->where("id", "<>", 1) ->order_by("left_ptr", "ASC") - ->get() as $row) { + ->execute() as $row) { // Don't encode the names segment $names[] = rawurlencode($row->name); $slugs[] = rawurlencode($row->slug); @@ -489,7 +489,7 @@ class Item_Model extends ORM_MPTT { ->where("parent_id", "=", $this->id) ->merge_where($where) ->order_by($order_by) - ->get() as $row) { + ->execute() as $row) { $position++; if ($row->id == $child->id) { break; diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 7e935614..31a56c1f 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -170,10 +170,10 @@ class notification { } static function send_pending_notifications() { - foreach (Database::instance() + foreach (db::build() ->select("DISTINCT email") ->from("pending_notifications") - ->get() as $row) { + ->execute() as $row) { $email = $row->email; $result = ORM::factory("pending_notification") ->where("email", "=", $email) diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index c4c4ba15..3e8a0d20 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -89,12 +89,12 @@ class tag_Core { */ static function item_tags($item) { $tags = array(); - foreach (Database::instance() + foreach (db::build() ->select("name") ->from("tags") ->join("items_tags", "tags.id", "items_tags.tag_id", "left") ->where("items_tags.item_id", "=", $item->id) - ->get() as $row) { + ->execute() as $row) { $tags[] = $row->name; } return $tags; -- cgit v1.2.3 From 53df0df0a4f9d2d5369016a7e2ea983ffe202346 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 29 Nov 2009 02:48:42 -0800 Subject: Update a few more occurrences of ORM/Database -> Database_Builder --- modules/gallery/controllers/admin_advanced_settings.php | 3 ++- modules/gallery/helpers/module.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index c9de7e57..391d2598 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -22,7 +22,8 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_advanced_settings.html"); $view->content->vars = ORM::factory("var") - ->order_by("module_name", "name") + ->order_by("module_name") + ->order_by("name") ->find_all(); print $view; } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 9fe2ec5e..14caa89b 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -377,11 +377,12 @@ class module_Core { self::$var_cache = unserialize($row->value); } else { // gallery._cache doesn't exist. Create it now. - foreach (Database::instance() + foreach (db::build() ->select("module_name", "name", "value") ->from("vars") - ->order_by("module_name", "name") - ->get() as $row) { + ->order_by("module_name") + ->order_by("name") + ->execute() as $row) { if ($row->module_name == "gallery" && $row->name == "_cache") { // This could happen if there's a race condition continue; @@ -421,7 +422,11 @@ class module_Core { $var->value = $value; $var->save(); - Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); + db::build() + ->delete("vars") + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") + ->execute(); self::$var_cache = null; } -- cgit v1.2.3 From d2cb217e20d44d7928a0910ac0375740de163bb3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 2 Dec 2009 00:34:34 -0800 Subject: Convert more database calls over to the new format - admin/maintenance page loads, the rebuild thumbs/resizes task works - Fixed up some conversion bugs in the Cache driver --- modules/exif/helpers/exif.php | 6 +-- modules/exif/helpers/exif_task.php | 9 +++-- modules/gallery/controllers/admin_maintenance.php | 22 ++++++----- modules/gallery/helpers/gallery_task.php | 4 +- modules/gallery/helpers/graphics.php | 33 ++++++++++------ .../gallery/libraries/drivers/Cache/Database.php | 46 ++++++++++++---------- modules/search/helpers/search.php | 4 +- modules/search/helpers/search_task.php | 8 ++-- 8 files changed, 77 insertions(+), 55 deletions(-) (limited to 'modules') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index d3a8c103..3177e7eb 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -139,7 +139,7 @@ class exif_Core { } static function stats() { - $missing_exif = Database::instance() + $missing_exif = db::build() ->select("items.id") ->from("items") ->join("exif_records", "items.id", "exif_records.item_id", "left") @@ -148,10 +148,10 @@ class exif_Core { ->where("exif_records.item_id", "=", null) ->or_where("exif_records.dirty", "=", 1) ->close() - ->get() + ->execute() ->count(); - $total_items = ORM::factory("item")->where("type", "photo")->count_all(); + $total_items = ORM::factory("item")->where("type", "=", "photo")->count_all(); if (!$total_items) { return array(0, 0, 0); } diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 66f69790..e25e2405 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -20,10 +20,11 @@ class exif_task_Core { static function available_tasks() { // Delete extra exif_records - Database::instance()->query( - "DELETE FROM {exif_records} " . - "WHERE {exif_records}.`item_id` NOT IN " . - "(SELECT `id` FROM {items} WHERE {items}.`type` = 'photo')"); + db::build() + ->delete("exif_records") + ->where("item_id", "NOT IN", + db::build()->select("id")->from("items")->where("type", "=", "photo")) + ->execute(); list ($remaining, $total, $percent) = exif::stats(); return array(Task_Definition::factory() diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 6377f40f..213e4fe2 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -22,11 +22,13 @@ class Admin_Maintenance_Controller extends Admin_Controller { * Show a list of all available, running and finished tasks. */ public function index() { - $query = Database::instance()->query( - "UPDATE {tasks} SET `state` = 'stalled' " . - "WHERE done = 0 " . - "AND state <> 'stalled' " . - "AND unix_timestamp(now()) - updated > 15"); + $query = db::build() + ->update("tasks") + ->set("state", "stalled") + ->where("done", "=", 0) + ->where("state", "<>", "stalled") + ->where(new Database_Expression("UNIX_TIMESTAMP(NOW()) - `updated` > 15")) + ->execute(); $stalled_count = $query->count(); if ($stalled_count) { log::warning("tasks", @@ -138,10 +140,12 @@ class Admin_Maintenance_Controller extends Admin_Controller { public function cancel_running_tasks() { access::verify_csrf(); - Database::instance()->update( - "tasks", - array("done" => 1, "state" => "cancelled"), - array("done" => 0)); + db::build() + ->update("tasks") + ->set("done", 1) + ->set("state", "cancelled") + ->where("done", "=", 0) + ->execute(); message::success(t("All running tasks cancelled")); url::redirect("admin/maintenance"); } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 4d6de3ba..3a705027 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -19,7 +19,7 @@ */ class gallery_task_Core { static function available_tasks() { - $dirty_count = graphics::find_dirty_images_query()->count(); + $dirty_count = graphics::find_dirty_images_query()->count_records(); $tasks = array(); $tasks[] = Task_Definition::factory() ->callback("gallery_task::rebuild_dirty_images") @@ -47,7 +47,7 @@ class gallery_task_Core { static function rebuild_dirty_images($task) { $errors = array(); try { - $result = graphics::find_dirty_images_query(); + $result = graphics::find_dirty_images_query()->select("id")->execute(); $total_count = $task->get("total_count", $result->count()); $mode = $task->get("mode", "init"); if ($mode == "init") { diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index c93cc304..6fab0b54 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -197,11 +197,22 @@ class graphics_Core { * @return Database_Result Query result */ static function find_dirty_images_query() { - return Database::instance()->query( - "SELECT `id` FROM {items} " . - "WHERE ((`thumb_dirty` = 1 AND (`type` <> 'album' OR `album_cover_item_id` IS NOT NULL))" . - " OR (`resize_dirty` = 1 AND `type` = 'photo')) " . - " AND `id` != 1"); + return db::build() + ->from("items") + ->and_open() + ->and_open() + ->where("thumb_dirty", "=", 1) + ->and_open() + ->where("type", "<>", "album") + ->or_where("album_cover_item_id", "IS NOT", null) + ->close() + ->or_open() + ->where("resize_dirty", "=", 1) + ->where("type", "=", "photo") + ->close() + ->close() + ->where("id", "<>", 1) + ->close(); } /** @@ -209,18 +220,18 @@ class graphics_Core { */ static function mark_dirty($thumbs, $resizes) { if ($thumbs || $resizes) { - $db = Database::instance(); - $fields = array(); + $db = db::build() + ->update("items"); if ($thumbs) { - $fields["thumb_dirty"] = 1; + $db->set("thumb_dirty", 1); } if ($resizes) { - $fields["resize_dirty"] = 1; + $db->set("resize_dirty", 1); } - $db->update("items", $fields, true); + $db->execute(); } - $count = self::find_dirty_images_query()->count(); + $count = self::find_dirty_images_query()->count_records(); if ($count) { site_status::warning( t2("One of your photos is out of date. Click here to fix it", diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index a317798e..5fa2a72a 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -33,7 +33,7 @@ class Cache_Database_Driver extends Cache_Driver { public function exists($id) { $count = db::build() ->where("key", "=", $id) - ->where("expiration", ">=", "time()") + ->where("expiration", ">=", time()) ->count_records("caches"); return $count > 0; } @@ -61,16 +61,18 @@ class Cache_Database_Driver extends Cache_Driver { foreach ($items as $id => $data) { if ($this->exists($id)) { - $status = db::build()->update( - "caches", - array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), - array("key", "=", $id)) + $status = db::build() + ->update("caches") + ->set("tags", $tags) + ->set("expiration", $lifetime) + ->set("cache", serialize($data)) + ->where("key", "=", $id) ->execute(); } else { - $status = db::build()->insert( - "caches", - array("key" => $id, "tags" => $tags, - "expiration" => $lifetime, "cache" => serialize($data))) + $status = db::build() + ->insert("caches") + ->columns("key", "tags", "expiration", "cache") + ->values($id, $tags, $lifetime, serialize($data)) ->execute(); } } @@ -84,11 +86,13 @@ class Cache_Database_Driver extends Cache_Driver { * @return array cached data */ public function get_tag($tags) { - $db = db::build()->from("caches"); + $db = db::build() + ->select("*") + ->from("caches"); foreach ($tags as $tag) { $db->where("tags", "LIKE", "<$tag>"); } - $db_result = $db->execute()->as_array(); + $db_result = $db->execute(); // An array will always be returned $result = array(); @@ -116,9 +120,9 @@ class Cache_Database_Driver extends Cache_Driver { public function get($keys, $single=false) { $data = null; $result = db::build() + ->select("*") ->from("caches") ->where("key", "IN", $keys) - ->select() ->execute(); if (count($result) > 0) { @@ -150,17 +154,18 @@ class Cache_Database_Driver extends Cache_Driver { * @return bool */ public function delete($id, $tag = false) { - $this->db->from("caches"); + $db = db::build() + ->delete("caches"); if ($id === true) { // Delete all caches - $this->db->where("1", "=", "1"); + $db->where("1", "=", "1"); } else if ($tag === true) { - $this->db->like("tags", "<$id>"); + $db->where("tags", "LIKE", "<$id>"); } else { - $this->db->where("key", "=", $id); + $db->where("key", "=", $id); } - $status = $this->db->delete(); + $status = $db->execute(); return count($status) > 0; } @@ -177,10 +182,11 @@ class Cache_Database_Driver extends Cache_Driver { */ public function delete_expired() { // Delete all expired caches - $status = $this->db->from("caches") + $status = db::build() + ->delete("caches") ->where("expiration", "<>", 0) ->where("expiration", "<=", time()) - ->delete(); + ->execute(); return count($status) > 0; } @@ -189,6 +195,6 @@ class Cache_Database_Driver extends Cache_Driver { * Empty the cache */ public function delete_all() { - db::build()->query("TRUNCATE {caches}")->execute(); + Database::instance()->query("TRUNCATE {caches}"); } } \ No newline at end of file diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 1fd5175f..9123df09 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -72,7 +72,7 @@ class search_Core { } static function stats() { - $remaining = Database::instance() + $remaining = db::build() ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") @@ -80,7 +80,7 @@ class search_Core { ->where("search_records.item_id", "=", null) ->or_where("search_records.dirty", "=", 1) ->close() - ->get() + ->execute() ->count(); $total = ORM::factory("item")->count_all(); diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 6b35cabc..6aa4a0d1 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -20,10 +20,10 @@ class search_task_Core { static function available_tasks() { // Delete extra search_records - Database::instance()->query( - "DELETE FROM {search_records} " . - "WHERE {search_records}.`item_id` NOT IN " . - "(SELECT `id` FROM {items})"); + db::build() + ->delete("search_records") + ->where("item_id", "NOT IN", db::build()->select("id")->from("items")) + ->execute(); list ($remaining, $total, $percent) = search::stats(); return array(Task_Definition::factory() -- cgit v1.2.3 From 94411b36585a5bdf6225b8af6ae4ee5c21d5779d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 2 Dec 2009 10:02:08 -0800 Subject: Fix a bunch of places where we were using "= null" instead of "IS NULL". --- modules/exif/helpers/exif.php | 2 +- modules/exif/helpers/exif_task.php | 2 +- modules/search/helpers/search.php | 6 ++---- modules/search/helpers/search_task.php | 2 +- modules/server_add/controllers/server_add.php | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) (limited to 'modules') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index 3177e7eb..3baed177 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -145,7 +145,7 @@ class exif_Core { ->join("exif_records", "items.id", "exif_records.item_id", "left") ->where("type", "=", "photo") ->and_open() - ->where("exif_records.item_id", "=", null) + ->where("exif_records.item_id", "IS", null) ->or_where("exif_records.dirty", "=", 1) ->close() ->execute() diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index e25e2405..27352643 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -47,7 +47,7 @@ class exif_task_Core { ->join("exif_records", "items.id", "exif_records.item_id", "left") ->where("type", "=", "photo") ->and_open() - ->where("exif_records.item_id", "=", null) + ->where("exif_records.item_id", "IS", null) ->or_where("exif_records.dirty", "=", 1) ->close() ->find_all() as $item) { diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 9123df09..70a39272 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -73,15 +73,13 @@ class search_Core { static function stats() { $remaining = db::build() - ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") ->and_open() - ->where("search_records.item_id", "=", null) + ->where("search_records.item_id", "IS", null) ->or_where("search_records.dirty", "=", 1) ->close() - ->execute() - ->count(); + ->count_records(); $total = ORM::factory("item")->count_all(); $percent = round(100 * ($total - $remaining) / $total); diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 6aa4a0d1..e039e493 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -45,7 +45,7 @@ class search_task_Core { $start = microtime(true); foreach (ORM::factory("item") ->join("search_records", "items.id", "search_records.item_id", "left") - ->where("search_records.item_id", "=", null) + ->where("search_records.item_id", "IS", null) ->or_where("search_records.dirty", "=", 1) ->find_all() as $item) { // The query above can take a long time, so start the timer after its done diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 3c3a6c2b..78e1620c 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -198,7 +198,7 @@ class Server_Add_Controller extends Admin_Controller { // they're done. $entries = ORM::factory("server_add_file") ->where("task_id", "=", $task->id) - ->where("item_id", "=", null) + ->where("item_id", "IS", null) ->order_by("id", "ASC") ->limit(10) ->find_all(); -- cgit v1.2.3 From 87bc32345f6d7cb64c4009ed68a79776ace7ff1b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 2 Dec 2009 10:42:49 -0800 Subject: Use select() instead of select("*") --- modules/gallery/libraries/drivers/Cache/Database.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 5fa2a72a..5c453f28 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -87,7 +87,7 @@ class Cache_Database_Driver extends Cache_Driver { */ public function get_tag($tags) { $db = db::build() - ->select("*") + ->select() ->from("caches"); foreach ($tags as $tag) { $db->where("tags", "LIKE", "<$tag>"); @@ -120,7 +120,7 @@ class Cache_Database_Driver extends Cache_Driver { public function get($keys, $single=false) { $data = null; $result = db::build() - ->select("*") + ->select() ->from("caches") ->where("key", "IN", $keys) ->execute(); -- cgit v1.2.3 From d0874a65acfbb2ed36eb7eae666969fde69ca004 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 2 Dec 2009 10:43:06 -0800 Subject: Use: ->select(new Database_Expression("DISTINCT `email`")) instead of: ->select("DISTINCT email") This is not the perfect API. http://dev.kohanaphp.com/issues/2396 is the upstream tracking ticket for a better API. --- modules/notification/helpers/notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 31a56c1f..e9fc3f33 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -171,7 +171,7 @@ class notification { static function send_pending_notifications() { foreach (db::build() - ->select("DISTINCT email") + ->select(new Database_Expression("DISTINCT `email`")) ->from("pending_notifications") ->execute() as $row) { $email = $row->email; -- cgit v1.2.3 From c7b934bc6daf41af1b6e0b04b9b0e9cb22113db6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 2 Dec 2009 12:20:21 -0800 Subject: Update a couple more queries. --- modules/gallery/helpers/l10n_client.php | 9 ++++----- modules/gallery/helpers/l10n_scanner.php | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 14ab5a85..fe70933d 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -80,11 +80,10 @@ class l10n_client_Core { } // @todo Batch requests (max request size) - foreach (Database::instance() + foreach (db::build() ->select("key", "locale", "revision", "translation") ->from("incoming_translations") - ->get() - ->as_array() as $row) { + ->execute() as $row) { if (!isset($request->messages->{$row->key})) { $request->messages->{$row->key} = 1; } @@ -168,10 +167,10 @@ class l10n_client_Core { // @todo Batch requests (max request size) // @todo include base_revision in submission / how to handle resubmissions / edit fights? - foreach (Database::instance() + foreach (db::build() ->select("key", "message", "locale", "base_revision", "translation") ->from("outgoing_translations") - ->get() as $row) { + ->execute() as $row) { $key = $row->key; if (!isset($request->{$key})) { $request->{$key}->message = json_encode(unserialize($row->message)); diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index a7ce2c59..d76c4d19 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -28,11 +28,11 @@ class l10n_scanner_Core { static function process_message($message, &$cache) { if (empty($cache)) { - foreach (Database::instance() + foreach (db::build() ->select("key") ->from("incoming_translations") ->where("locale", "=", "root") - ->get() as $row) { + ->execute() as $row) { $cache[$row->key] = true; } } -- cgit v1.2.3 From 112aafe5137220181dd74afc509fa6cd39573028 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 19:51:00 -0800 Subject: Oops, removed the overload for query() before, we need this back so that we can prefix table names properly. --- modules/gallery/libraries/MY_Database.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index 0f29c09b..52bc46d6 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -20,6 +20,17 @@ abstract class Database extends Database_Core { protected $_table_names; + /** + * Parse the query string and convert any strings of the form `\([a-zA-Z0-9_]*?)\] + * table prefix . $1 + */ + public function query($sql = '') { + if (!empty($sql)) { + $sql = $this->add_table_prefixes($sql); + } + return parent::query($sql); + } + public function add_table_prefixes($sql) { $prefix = $this->config["table_prefix"]; if (strpos($sql, "SHOW TABLES") === 0) { -- cgit v1.2.3 From 5a7449f31574c7c548abe4244a6ba0993138e013 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 19:51:25 -0800 Subject: Update more database calls. --- modules/gallery/helpers/graphics.php | 19 ++++++++++++++----- modules/gallery/helpers/module.php | 6 +++++- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 6fab0b54..7577d7ac 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -74,7 +74,10 @@ class graphics_Core { * @param string $module_name */ static function remove_rules($module_name) { - $status = Database::instance()->delete("graphics_rules", array("module_name" => $module_name)); + $status = db::build() + ->delete("graphics_rules") + ->where("module_name", "=", $module_name) + ->execute(); if (count($status)) { self::mark_dirty(true, true); } @@ -86,8 +89,11 @@ class graphics_Core { * module it won't cause all of your images to suddenly require a rebuild. */ static function activate_rules($module_name) { - Database::instance() - ->update("graphics_rules",array("active" => true), array("module_name" => $module_name)); + db::build() + ->update("graphics_rules") + ->set("active", true) + ->where("module_name", "=", $module_name) + ->execute(); } /** @@ -96,8 +102,11 @@ class graphics_Core { * module it won't cause all of your images to suddenly require a rebuild. */ static function deactivate_rules($module_name) { - Database::instance() - ->update("graphics_rules",array("active" => false), array("module_name" => $module_name)); + db::build() + ->update("graphics_rules") + ->set("active", false) + ->where("module_name", "=", $module_name) + ->execute(); } /** diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 14caa89b..b8928f7b 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -460,7 +460,11 @@ class module_Core { $var->delete(); } - Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); + db::build() + ->delete("vars") + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") + ->execute(); self::$var_cache = null; } -- cgit v1.2.3 From 2132c9a96d923d48effc3fe8facedff4a4da3b13 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 20:19:54 -0800 Subject: Fix some database calls. --- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/models/tag.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 6cd2f337..ed4a0366 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -51,7 +51,7 @@ class Admin_Tags_Controller extends Admin_Controller { $form = tag::get_delete_form($tag); if ($form->validate()) { $name = $tag->name; - Database::instance()->delete("items_tags", array("tag_id" => "$tag->id")); + db::build()->delete("items_tags")->where("tag_id", "=", $tag->id)->execute(); $tag->delete(); message::success(t("Deleted tag %tag_name", array("tag_name" => $name))); log::success("tags", t("Deleted tag %tag_name", array("tag_name" => $name))); diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index f9a453be..b60f8dfc 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -63,13 +63,21 @@ class Tag_Model extends ORM { public function save() { $db = Database::instance(); $related_item_ids = array(); - foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) { + foreach (db::build() + ->select("item_id") + ->from("items_tags") + ->where("tag_id", "=", $this->id) + ->execute() as $row) { $related_item_ids[$row->item_id] = 1; } $result = parent::save(); - foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) { + foreach (db::build() + ->select("item_id") + ->from("items_tags") + ->where("tag_id", "=", $this->id) + ->execute() as $row) { $related_item_ids[$row->item_id] = 1; } @@ -89,7 +97,12 @@ class Tag_Model extends ORM { public function delete() { $related_item_ids = array(); $db = Database::Instance(); - foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) { + + foreach (db::build() + ->select("item_id") + ->from("items_tags") + ->where("tag_id", "=", $this->id) + ->execute() as $row) { $related_item_ids[$row->item_id] = 1; } -- cgit v1.2.3 From 3d0a7a33ad0c1bbc16ef6156609110e14b6e0ee6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 20:38:57 -0800 Subject: Fix a few more database queries --- modules/tag/controllers/tags.php | 2 +- modules/tag/models/tag.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index dfa3a9b3..a44f6aa3 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -83,7 +83,7 @@ class Tags_Controller extends Controller { $limit = $this->input->get("limit"); $tag_part = end($tag_parts); $tag_list = ORM::factory("tag") - ->like("name", "{$tag_part}%", false) + ->where("name", "LIKE", "{$tag_part}%") ->order_by("name", "ASC") ->limit($limit) ->find_all(); diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index b60f8dfc..f6cc6144 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -82,7 +82,9 @@ class Tag_Model extends ORM { } if ($related_item_ids) { - foreach (ORM::factory("item")->in("id", array_keys($related_item_ids))->find_all() as $item) { + foreach (ORM::factory("item") + ->where("id", "IN", array_keys($related_item_ids)) + ->find_all() as $item) { module::event("item_related_update", $item); } } -- cgit v1.2.3 From 2be72bb1c3c5790e0ce68c2609de141bf9756614 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 20:42:38 -0800 Subject: Overload Kohana_Exception::text() to dump out the complete stack trace so that we have useful data in the logs. --- application/Bootstrap.php | 2 +- modules/gallery/libraries/MY_Kohana_Exception.php | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 modules/gallery/libraries/MY_Kohana_Exception.php (limited to 'modules') diff --git a/application/Bootstrap.php b/application/Bootstrap.php index b15cbfce..f36fac14 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -30,7 +30,7 @@ require SYSPATH.'core/Kohana'.EXT; final class Kohana extends Kohana_Core {} require SYSPATH.'core/Kohana_Exception'.EXT; -class Kohana_Exception extends Kohana_Exception_Core {} +require MODPATH.'gallery/libraries/MY_Kohana_Exception'.EXT; require SYSPATH.'core/Kohana_Config'.EXT; require SYSPATH.'libraries/drivers/Config'.EXT; diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php new file mode 100644 index 00000000..32b4ab93 --- /dev/null +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -0,0 +1,29 @@ +getCode(), strip_tags($e->getMessage()), $e->getTraceAsString()); + } +} \ No newline at end of file -- cgit v1.2.3 From c22bf27cc2b69bc2109b9562cbd1a8f6a9143ef4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:02:30 -0800 Subject: Add the current file/line at the top of the trace. --- modules/gallery/libraries/MY_Kohana_Exception.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php index 32b4ab93..dd5998a1 100644 --- a/modules/gallery/libraries/MY_Kohana_Exception.php +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -23,7 +23,9 @@ class Kohana_Exception extends Kohana_Exception_Core { */ public static function text($e) { return sprintf( - "%s [ %s ]: %s\n%s", - get_class($e), $e->getCode(), strip_tags($e->getMessage()), $e->getTraceAsString()); + "%s [ %s ]: %s\n%s [ %s ]\n%s", + get_class($e), $e->getCode(), strip_tags($e->getMessage()), + $e->getFile(), $e->getLine(), + $e->getTraceAsString()); } } \ No newline at end of file -- cgit v1.2.3 From b9dadb77c3c75c6ba6ead293757df440976b3917 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:21:35 -0800 Subject: Get rid of unused _method param in the item edit form. Fix viewable() to properly OR view restrictions together. --- modules/gallery/helpers/item.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index c3126435..300a6942 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -127,7 +127,6 @@ class item_Core { $page_type = Input::instance()->get("page_type"); $form = new Forge( "quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "g-confirm-delete")); - $form->hidden("_method")->value("put"); $group = $form->group("confirm_delete")->label(t("Confirm Deletion")); $group->submit("")->value(t("Delete")); return $form; @@ -156,7 +155,7 @@ class item_Core { $view_restrictions = array(); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { - $view_restrictions[] = "items.view_$id"; + $view_restrictions["items.view_$id"] = access::ALLOW; } } switch (count($view_restrictions)) { @@ -168,10 +167,7 @@ class item_Core { break; default: - $model - ->and_open() - ->or_where($view_restrictions, "=", access::ALLOW) - ->close(); + $model->and_open()->or_where($view_restrictions)->close(); break; } -- cgit v1.2.3 From fb899c313c9cdf4d6b0529c53d2b647999ad94db Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:28:40 -0800 Subject: Further simplifications to viewable(). Stop trying to optimize for the case where we just have one restriction, it's unnecessary. --- modules/gallery/helpers/item.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 300a6942..b7be23cd 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -158,17 +158,9 @@ class item_Core { $view_restrictions["items.view_$id"] = access::ALLOW; } } - switch (count($view_restrictions)) { - case 0: - break; - case 1: - $model->where($view_restrictions[0], "=", access::ALLOW); - break; - - default: + if (count($view_restrictions)) { $model->and_open()->or_where($view_restrictions)->close(); - break; } return $model; -- cgit v1.2.3 From 2f5c612036984a6f09995e8c692f399fb8c7fb15 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:33:17 -0800 Subject: Update database queries. --- modules/tag/helpers/tag.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 3e8a0d20..8075afe4 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -125,10 +125,16 @@ class tag_Core { * Delete all tags associated with an item */ static function clear_all($item) { - $db = Database::instance(); - $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " . - "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)"); - $db->delete("items_tags", array("item_id" => "$item->id")); + db::build() + ->update("tags") + ->set("count", new Database_Expression("`count` - 1")) + ->where("count", ">", 0) + ->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id)) + ->execute(); + db::build() + ->delete("items_tags") + ->where("item_id", "=", $item->id) + ->execute(); } /** @@ -138,6 +144,6 @@ class tag_Core { // @todo There's a potential race condition here which we can solve by adding a lock around // this and all the cases where we create/update tags. I'm loathe to do that since it's an // extremely rare case. - Database::instance() ->delete("tags", array("count" => 0)); + db::build()->delete("tags")->where("count", "=", 0)->execute(); } } \ No newline at end of file -- cgit v1.2.3 From dec084fe08db1505d272e6a577b8627f57abef16 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:34:09 -0800 Subject: Update database queries. --- modules/gallery/helpers/gallery_event.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index fa4db317..37f39d15 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -30,19 +30,21 @@ class gallery_event_Core { static function user_deleted($user) { $admin = identity::admin_user(); - $db = Database::instance(); - $db->from("tasks") - ->set(array("owner_id" => $admin->id)) + db::build() + ->update("tasks") + ->set("owner_id", $admin->id) ->where("owner_id", "=", $user->id) - ->update(); - $db->from("items") - ->set(array("owner_id" => $admin->id)) + ->execute(); + db::build() + ->update("items") + ->set("owner_id", $admin->id) ->where("owner_id", "=", $user->id) - ->update(); - $db->from("logs") - ->set(array("user_id" => $admin->id)) + ->execute(); + db::build() + ->update("logs") + ->set("user_id", $admin->id) ->where("user_id", "=", $user->id) - ->update(); + ->execute(); } static function identity_provider_changed($old_provider, $new_provider) { -- cgit v1.2.3 From 0a345895b424b74920f27bc60a7f3c6e22695bd1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:34:35 -0800 Subject: Updated for K2.4. This is a fork from the main-line, but we're going to replace this with Formio anyway. --- modules/forge/libraries/Form_Input.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/forge/libraries/Form_Input.php b/modules/forge/libraries/Form_Input.php index 30311941..0c578011 100644 --- a/modules/forge/libraries/Form_Input.php +++ b/modules/forge/libraries/Form_Input.php @@ -317,7 +317,7 @@ class Form_Input_Core { $args = is_array($args) ? $args : array(); // Add the label or name to the beginning of the args - array_unshift($args, $this->label ? utf8::strtolower($this->label) : $this->name); + array_unshift($args, $this->label ? mb_strtolower($this->label) : $this->name); if (isset($this->error_messages[$func])) { @@ -333,7 +333,7 @@ class Form_Input_Core { case 'valid_email': case 'valid_ip': // Fetch an i18n error message - $error = Kohana::lang('validation.'.$func, $args); + $error = 'validation.'.$func; break; case substr($func, 0, 6) === 'valid_': // Strip 'valid_' from func name @@ -343,11 +343,11 @@ class Form_Input_Core { case 'digit': case 'numeric': // i18n strings have to be inserted into valid_type - $args[] = Kohana::lang('validation.'.$func); - $error = Kohana::lang('validation.valid_type', $args); + $args[] = 'validation.'.$func; + $error = 'validation.valid_type'; break; default: - $error = Kohana::lang('validation.'.$func, $args); + $error = 'validation.'.$func; } } } @@ -490,7 +490,7 @@ class Form_Input_Core { if ($this->value != $input->value) { // Field does not match - $this->errors['matches'] = array($input->label ? utf8::strtolower($input->label) : $input->name); + $this->errors['matches'] = array($input->label ? mb_strtolower($input->label) : $input->name); break; } } @@ -529,7 +529,7 @@ class Form_Input_Core { protected function rule_length($min, $max = NULL) { // Get the length, return if zero - if (($length = utf8::strlen($this->value)) === 0) + if (($length = mb_strlen($this->value)) === 0) return; if ($max == NULL) -- cgit v1.2.3 From b129ff7cfa1690c1af602035ebfc0e374b9066f1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:34:48 -0800 Subject: Update database query. --- modules/exif/helpers/exif_event.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/exif/helpers/exif_event.php b/modules/exif/helpers/exif_event.php index 826ec959..6490d11f 100644 --- a/modules/exif/helpers/exif_event.php +++ b/modules/exif/helpers/exif_event.php @@ -25,6 +25,9 @@ class exif_event_Core { } static function item_deleted($item) { - Database::instance()->delete("exif_records", array("item_id" => $item->id)); + db::build() + ->delete("exif_records") + ->where("item_id", "=", $item->id) + ->execute(); } } -- cgit v1.2.3 From 2ff84b092d0b9d8ca61b313d2aa5d7941f3f8711 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:35:04 -0800 Subject: Update database query. --- modules/g2_import/helpers/g2_import_event.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php index 609e1a45..02a2126d 100644 --- a/modules/g2_import/helpers/g2_import_event.php +++ b/modules/g2_import/helpers/g2_import_event.php @@ -19,7 +19,10 @@ */ class g2_import_event_Core { static function item_deleted($item) { - Database::instance()->delete("g2_maps", array("g3_id" => $item->id)); + db::build() + ->delete("g2_maps") + ->where("g3_id", "=", $item->id) + ->execute(); } static function item_created($item) { -- cgit v1.2.3 From a6dbd25cf11e1b5044862eea9bac0ff3cdf6de80 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Dec 2009 21:38:09 -0800 Subject: Update database queries. --- modules/comment/helpers/comment_event.php | 31 ++++++++++++---------- .../notification/helpers/notification_event.php | 10 ++++--- 2 files changed, 23 insertions(+), 18 deletions(-) (limited to 'modules') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index c90f7663..576e041d 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -19,29 +19,32 @@ */ class comment_event_Core { static function item_deleted($item) { - Database::instance()->delete("comments", array("item_id" => $item->id)); + db::build() + ->delete("comments") + ->where("item_id", "=", $item->id); } static function user_deleted($user) { $guest = identity::guest(); - Database::instance()->from("comments") - ->set(array("author_id" => $guest->id, - "guest_email" => null, - "guest_name" => "guest", - "guest_url" => null)) + db::build() + ->update("comments") + ->set("author_id", $guest->id) + ->set("guest_email", null) + ->set("guest_name", "guest") + ->set("guest_url", null) ->where("author_id", "=", $user->id) - ->update(); + ->execute(); } static function identity_provider_changed($old_provider, $new_provider) { $guest = identity::guest(); - Database::instance()->from("comments") - ->set(array("author_id" => $guest->id, - "guest_email" => null, - "guest_name" => "guest", - "guest_url" => null)) - ->where("1", "=", "1") // @todo: why do we do this? - ->update(); + db::build() + ->update("comments") + ->set("author_id", $guest->id) + ->set("guest_email", null) + ->set("guest_name", "guest") + ->set("guest_url", null) + ->execute(); } static function admin_menu($menu, $theme) { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 951e6e52..2c7ede27 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -53,14 +53,16 @@ class notification_event_Core { } static function user_deleted($user) { - ORM::factory("subscriptions") + db::build() + ->delete("subscriptions") ->where("user_id", "=", $user->id) - ->delete_all(); + ->execute(); } static function identity_provider_changed($old_provider, $new_provider) { - ORM::factory("subscriptions") - ->delete_all(); + db::build() + ->delete("subscriptions") + ->execute(); } static function comment_created($comment) { -- cgit v1.2.3 From cb55eea0f3609d802da5fdb0ea1c8b3acb0b8ea9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 13 Dec 2009 17:03:07 -0800 Subject: Convert a database query. --- modules/digibug/controllers/digibug.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 25f1ca3e..03f9e812 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -115,9 +115,10 @@ class Digibug_Controller extends Controller { } private function _clean_expired() { - Database::instance()->query( - "DELETE FROM {digibug_proxies} " . - "WHERE request_date <= (CURDATE() - INTERVAL 10 DAY) " . - "LIMIT 20"); + db::build() + ->delete("digibug_proxies") + ->where("request_date", "<=", new Database_Expression("(CURDATE() - INTERVAL 10 DAY)")) + ->limit(20) + ->execute(); } } \ No newline at end of file -- cgit v1.2.3 From 8c03c7a073df7d210e1e961797cc39fd124ec390 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 13 Dec 2009 17:15:12 -0800 Subject: Convert some database calls. --- modules/gallery/models/item.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 8a42cc1e..b6af0528 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -161,11 +161,13 @@ class Item_Model extends ORM_MPTT { $this->name = $new_name; if ($this->is_album()) { - Database::instance() - ->update("items", - array("relative_path_cache" => null, - "relative_url_cache" => null), - array("left_ptr >" => $this->left_ptr, "right_ptr <" => $this->right_ptr)); + db::build() + ->update("items") + ->set("relative_url_cache", null) + ->set("relative_path_cache", null) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<", $this->right_ptr) + ->execute(); } return $this; @@ -362,10 +364,12 @@ class Item_Model extends ORM_MPTT { // Clear the relative url cache for this item and all children $this->relative_url_cache = null; if ($this->is_album()) { - Database::instance() - ->update("items", - array("relative_url_cache" => null), - array("left_ptr >" => $this->left_ptr, "right_ptr <" => $this->right_ptr)); + db::build() + ->update("items") + ->set("relative_url_cache", null) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<", $this->right_ptr) + ->execute(); } } } -- cgit v1.2.3 From 064a24b897880e4dbf4dafeb756406bbd907bdba Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 13 Dec 2009 17:15:59 -0800 Subject: Convert a database call. --- modules/gallery/controllers/albums.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 76032655..319f1416 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -132,7 +132,7 @@ class Albums_Controller extends Items_Controller { $form->edit_item->dirname->value != $album->name || $form->edit_item->slug->value != $album->slug) { // Make sure that there's not a conflict - if ($row = Database::instance() + if ($row = db::build() ->select(array("name", "slug")) ->from("items") ->where("parent_id", "=", $album->parent_id) @@ -141,7 +141,7 @@ class Albums_Controller extends Items_Controller { ->where("name", "=", $form->edit_item->dirname->value) ->or_where("slug", "=", $form->edit_item->slug->value) ->close() - ->get() + ->execute() ->current()) { if ($row->name == $form->edit_item->dirname->value) { $form->edit_item->dirname->add_error("name_conflict", 1); -- cgit v1.2.3 From 4566c299c1d1756fa78bc873a2266c28e047118a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 16 Dec 2009 09:24:38 -0800 Subject: Convert some database calls. --- modules/gallery/controllers/l10n_client.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 30a18631..71df1cf1 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -113,12 +113,11 @@ class L10n_Client_Controller extends Controller { public static function l10n_form() { if (Input::instance()->get("show_all_l10n_messages")) { $calls = array(); - foreach (Database::instance() + foreach (db::build() ->select("key", "message") ->from("incoming_translations") - ->where("locale", "=", "root")) - ->get() - ->as_array() as $row) { + ->where("locale", "=", "root") + ->execute() as $row) { $calls[$row->key] = array(unserialize($row->message), array()); } } else { @@ -128,21 +127,19 @@ class L10n_Client_Controller extends Controller { if ($calls) { $translations = array(); - foreach (Database::instance() + foreach (db::build() ->select("key", "translation") ->from("incoming_translations") ->where("locale", "=", $locale) - ->get() - ->as_array() as $row) { + ->execute() as $row) { $translations[$row->key] = unserialize($row->translation); } // Override incoming with outgoing... - foreach (Database::instance() + foreach (db::build() ->select("key", "translation") ->from("outgoing_translations") ->where("locale", "=", $locale) - ->get() - ->as_array() as $row) { + ->execute() as $row) { $translations[$row->key] = unserialize($row->translation); } -- cgit v1.2.3 From 86467363c20c6150ee0fccc7901cd34b281be2b1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 16 Dec 2009 18:03:23 -0800 Subject: Convert a database call. --- modules/gallery/controllers/movies.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 6e25e6ea..b5785ecf 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -76,16 +76,16 @@ class Movies_Controller extends Items_Controller { if ($form->edit_item->filename->value != $movie->name || $form->edit_item->slug->value != $movie->slug) { // Make sure that there's not a name or slug conflict - if ($row = Database::instance() + if ($row = db::build() ->select(array("name", "slug")) ->from("items") ->where("parent_id", "=", $movie->parent_id) - ->where("id <>", $movie->id) + ->where("id", "<>", $movie->id) ->and_open() ->where("name", "=", $form->edit_item->filename->value) ->or_where("slug", "=", $form->edit_item->slug->value) ->close() - ->get() + ->execute() ->current()) { if ($row->name == $form->edit_item->filename->value) { $form->edit_item->filename->add_error("name_conflict", 1); -- cgit v1.2.3 From f431d7e12e0be10cfd7ea30543a44cf17a4e8275 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 16 Dec 2009 18:04:44 -0800 Subject: Convert a database call. --- modules/gallery/controllers/photos.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index f7c5039e..ced9da2f 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -76,7 +76,7 @@ class Photos_Controller extends Items_Controller { if ($form->edit_item->filename->value != $photo->name || $form->edit_item->slug->value != $photo->slug) { // Make sure that there's not a name or slug conflict - if ($row = Database::instance() + if ($row = db::build() ->select(array("name", "slug")) ->from("items") ->where("parent_id", "=", $photo->parent_id) @@ -85,7 +85,7 @@ class Photos_Controller extends Items_Controller { ->where("name", "=", $form->edit_item->filename->value) ->or_where("slug", "=", $form->edit_item->slug->value) ->close() - ->get() + ->execute() ->current()) { if ($row->name == $form->edit_item->filename->value) { $form->edit_item->filename->add_error("name_conflict", 1); -- cgit v1.2.3 From c99a75b5d150f14c96697833f08354afd456323a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 09:16:44 -0800 Subject: Improve the exception error message. --- modules/gallery/controllers/packager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 1354a01b..d27adf4d 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -30,7 +30,7 @@ class Packager_Controller extends Controller { $this->_dump_database(); // Dump the database $this->_dump_var(); // Dump the var directory } catch (Exception $e) { - print $e->getTraceAsString(); + print $e->getMessage() . "\n" . $e->getTraceAsString(); return; } -- cgit v1.2.3 From 2aba8c4bffed5fb38689d5ed998c486ab6bde902 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:05:47 -0800 Subject: Simplify add_table_prefixes. In Kohana 2.4, it returns the bare table name, not the prefixed one so this makes our logic easier. --- modules/gallery/libraries/MY_Database.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index 52bc46d6..fd486039 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -25,7 +25,7 @@ abstract class Database extends Database_Core { * table prefix . $1 */ public function query($sql = '') { - if (!empty($sql)) { + if ($this->config["table_prefix"] && !empty($sql)) { $sql = $this->add_table_prefixes($sql); } return parent::query($sql); @@ -49,19 +49,12 @@ abstract class Database extends Database_Core { if (!isset($this->_table_names)) { // This should only run once on the first query - $this->_table_names =array(); - $len = strlen($prefix); + $this->_table_names = array(); foreach($this->list_tables() as $table_name) { - if ($len > 0) { - $naked_name = strpos($table_name, $prefix) !== 0 ? - $table_name : substr($table_name, $len); - } else { - $naked_name = $table_name; - } - $this->_table_names["{{$naked_name}}"] = $table_name; + $this->_table_names["{{$table_name}}"] = $prefix . $table_name; } } - return empty($this->_table_names) ? $sql : strtr($sql, $this->_table_names); + return strtr($sql, $this->_table_names); } } \ No newline at end of file -- cgit v1.2.3 From 9b75b85e71b47fc953773544c930f5cecf6b34a7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:05:58 -0800 Subject: Update all database queries such that we can run "php index.php package" and generate the same SQL as before. --- modules/gallery/controllers/packager.php | 7 +-- modules/gallery/helpers/access.php | 81 ++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 32 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index d27adf4d..4569e166 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -42,7 +42,7 @@ class Packager_Controller extends Controller { // Drop all tables foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE IF EXISTS `$table`"); + $db->query("DROP TABLE IF EXISTS {{$table}}"); } // Clean out data @@ -88,8 +88,9 @@ class Packager_Controller extends Controller { $db->query("TRUNCATE {sessions}"); $db->query("TRUNCATE {logs}"); $db->query("DELETE FROM {vars} WHERE `module_name` = 'gallery' AND `name` = '_cache'"); - $db->update("users", array("password" => ""), array("id" => 1)); - $db->update("users", array("password" => ""), array("id" => 2)); + + db::build()->update("users", array("password" => ""), array("id" => 1))->execute(); + db::build()->update("users", array("password" => ""), array("id" => 2))->execute(); $dbconfig = Kohana::config('database.default'); $conn = $dbconfig["connection"]; diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 0d197597..85410085 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -419,8 +419,8 @@ class access_Core { * @return ORM_Iterator */ private static function _get_all_groups() { - // When we build the gallery package, it's possible that there is no identity provider installed yet. - // This is ok at packaging time, so work around it. + // When we build the gallery package, it's possible that there is no identity provider + // installed yet. This is ok at packaging time, so work around it. if (module::is_active(module::get_var("gallery", "identity_provider", "user"))) { return identity::groups(); } else { @@ -436,11 +436,10 @@ class access_Core { * @return void */ private static function _drop_columns($perm_name, $group) { - $db = Database::instance(); $field = "{$perm_name}_{$group->id}"; $cache_table = $perm_name == "view" ? "items" : "access_caches"; - $db->query("ALTER TABLE {{$cache_table}} DROP `$field`"); - $db->query("ALTER TABLE {access_intents} DROP `$field`"); + Database::instance()->query("ALTER TABLE {{$cache_table}} DROP `$field`"); + Database::instance()->query("ALTER TABLE {access_intents} DROP `$field`"); model_cache::clear(); ORM::factory("access_intent")->clear_cache(); } @@ -453,13 +452,18 @@ class access_Core { * @return void */ private static function _add_columns($perm_name, $group) { - $db = Database::instance(); $field = "{$perm_name}_{$group->id}"; $cache_table = $perm_name == "view" ? "items" : "access_caches"; $not_null = $cache_table == "items" ? "" : "NOT NULL"; - $db->query("ALTER TABLE {{$cache_table}} ADD `$field` BINARY $not_null DEFAULT FALSE"); - $db->query("ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL"); - $db->update("access_intents", array($field => self::DENY), array("item_id" => 1)); + Database::instance()->query( + "ALTER TABLE {{$cache_table}} ADD `$field` BINARY $not_null DEFAULT FALSE"); + Database::instance()->query( + "ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL"); + db::build() + ->update("access_intents") + ->set($field, self::DENY) + ->where("item_id", "=", 1) + ->execute(); model_cache::clear(); ORM::factory("access_intent")->clear_cache(); } @@ -476,8 +480,6 @@ class access_Core { */ private static function _update_access_view_cache($group, $item) { $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find(); - - $db = Database::instance(); $field = "view_{$group->id}"; // With view permissions, deny values in the parent can override allow values in the child, @@ -506,8 +508,12 @@ class access_Core { // access_caches table will already contain DENY values and we won't be able to overwrite // them according the rule above. So mark every permission below this level as UNKNOWN so // that we can tell which permissions have been changed, and which ones need to be updated. - $db->update("items", array($field => self::UNKNOWN), - array("left_ptr >=" => $item->left_ptr, "right_ptr <=" => $item->right_ptr)); + db::build() + ->update("items") + ->set($field, self::UNKNOWN) + ->where("left_ptr", ">=", $item->left_ptr) + ->where("right_ptr", "<=", $item->right_ptr) + ->execute(); $query = ORM::factory("access_intent") ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr", "items.id")) @@ -521,20 +527,34 @@ class access_Core { foreach ($query as $row) { if ($row->$field == self::ALLOW) { // Propagate ALLOW for any row that is still UNKNOWN. - $db->update("items", array($field => $row->$field), - array($field => self::UNKNOWN, "left_ptr >=" => $row->left_ptr, "right_ptr <=" => $row->right_ptr)); + db::build() + ->update("items") + ->set($field, $row->$field) + ->where($field, "IS", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS + ->where("left_ptr", ">=", $row->left_ptr) + ->where("right_ptr", "<=", $row->right_ptr) + ->execute(); } else if ($row->$field == self::DENY) { // DENY overwrites everything below it - $db->update("items", array($field => $row->$field), - array("left_ptr >=" => $row->left_ptr, "right_ptr <=" => $row->right_ptr)); + db::build() + ->update("items") + ->set($field, $row->$field) + ->where("left_ptr", ">=", $row->left_ptr) + ->where("right_ptr", "<=", $row->right_ptr) + ->execute(); } } // Finally, if our intent is DEFAULT at this point it means that we were unable to find a // DENY parent in the hierarchy to propagate from. So we'll still have a UNKNOWN values in // the hierarchy, and all of those are safe to change to ALLOW. - $db->update("items", array($field => self::ALLOW), - array($field => self::UNKNOWN, "left_ptr >=" => $item->left_ptr, "right_ptr <=" => $item->right_ptr)); + db::build() + ->update("items") + ->set($field, self::ALLOW) + ->where($field, "IS", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS + ->where("left_ptr", ">=", $item->left_ptr) + ->where("right_ptr", "<=", $item->right_ptr) + ->execute(); } /** @@ -551,7 +571,6 @@ class access_Core { private static function _update_access_non_view_cache($group, $perm_name, $item) { $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find(); - $db = Database::instance(); $field = "{$perm_name}_{$group->id}"; // If the item's intent is DEFAULT, then we need to back up the chain to find the nearest @@ -564,7 +583,7 @@ class access_Core { ->join("access_intents", "items.id", "access_intents.item_id") ->where("left_ptr", "<", $item->left_ptr) ->where("right_ptr", ">", $item->right_ptr) - ->where($field, "IS NOT", self::UNKNOWN) + ->where($field, "IS NOT", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS NOT ->order_by("left_ptr", "DESC") ->limit(1) ->find(); @@ -583,14 +602,18 @@ class access_Core { ->where($field, "IS NOT", self::INHERIT) ->order_by("level", "ASC") ->find_all(); - foreach ($query as $row) { - $value = ($row->$field === self::ALLOW) ? "TRUE" : "FALSE"; - $db->query( - "UPDATE {access_caches} SET `$field` = $value " . - "WHERE `item_id` IN " . - " (SELECT `id` FROM {items} " . - " WHERE `left_ptr` >= $row->left_ptr " . - " AND `right_ptr` <= $row->right_ptr)"); + foreach ($query as $row) { + $value = ($row->$field === self::ALLOW) ? true : false; + db::build() + ->update("access_caches") + ->set($field, $value) + ->where("item_id", "IN", + db::build() + ->select("id") + ->from("items") + ->where("left_ptr", ">=", $row->left_ptr) + ->where("right_ptr", "<=", $row->right_ptr)) + ->execute(); } } -- cgit v1.2.3 From 8883d1605a12b94fb8f8b5a39ce5b4675b358302 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:16:37 -0800 Subject: Convert some more database queries. --- modules/gallery/controllers/packager.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 4569e166..2592da31 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -38,11 +38,9 @@ class Packager_Controller extends Controller { } private function _reset() { - $db = Database::instance(); - // Drop all tables - foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE IF EXISTS {{$table}}"); + foreach (Database::instance()->list_tables() as $table) { + Database::instance()->query("DROP TABLE IF EXISTS {{$table}}"); } // Clean out data @@ -53,7 +51,7 @@ class Packager_Controller extends Controller { dir::unlink(VARPATH . "modules"); dir::unlink(VARPATH . "tmp"); - $db->clear_cache(); + Database::instance()->clear_cache(); module::$modules = array(); module::$active = array(); @@ -84,11 +82,13 @@ class Packager_Controller extends Controller { module::set_var("gallery", "blocks_{$key}", serialize($blocks)); } - $db = Database::instance(); - $db->query("TRUNCATE {sessions}"); - $db->query("TRUNCATE {logs}"); - $db->query("DELETE FROM {vars} WHERE `module_name` = 'gallery' AND `name` = '_cache'"); - + Database::instance()->query("TRUNCATE {sessions}"); + Database::instance()->query("TRUNCATE {logs}"); + db::build() + ->delete("vars") + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") + ->execute(); db::build()->update("users", array("password" => ""), array("id" => 1))->execute(); db::build()->update("users", array("password" => ""), array("id" => 2))->execute(); -- cgit v1.2.3 From 9d19e272d672ffc224dfed2799f8e480ecb583e4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:16:51 -0800 Subject: Convert some database queries. --- modules/gallery/helpers/gallery_event.php | 25 ++++++++++++------------- modules/gallery/helpers/module.php | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 18 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 37f39d15..301432d4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -49,19 +49,18 @@ class gallery_event_Core { static function identity_provider_changed($old_provider, $new_provider) { $admin = identity::admin_user(); - $db = Database::instance(); - $db->from("tasks") - ->set(array("owner_id" => $admin->id)) - ->where("1", "=", "1") // @todo why do we need this? - ->update(); - $db->from("items") - ->set(array("owner_id" => $admin->id)) - ->where("1", "=", "1") // @todo why do we need this? - ->update(); - $db->from("logs") - ->set(array("user_id" => $admin->id)) - ->where("1", "=", "1") // @todo why do we need this? - ->update(); + db::build() + ->update("tasks") + ->set("owner_id", $admin->id) + ->execute(); + db::build() + ->update("items") + ->set("owner_id", $admin->id) + ->execute(); + db::build() + ->update("logs") + ->set("user_id", $admin->id) + ->execute(); } static function group_created($group) { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index b8928f7b..71c4efa0 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -432,17 +432,30 @@ class module_Core { /** * Increment the value of a variable for this module + * + * Note: Frequently updating counters is very inefficient because it invalidates the cache value + * which has to be rebuilt every time we make a change. + * + * @todo Get rid of this and find an alternate approach for all callers (currently only Akismet) + * + * @deprecated * @param string $module_name * @param string $name * @param string $increment (optional, default is 1) */ static function incr_var($module_name, $name, $increment=1) { - Database::instance()->query( - "UPDATE {vars} SET `value` = `value` + $increment " . - "WHERE `module_name` = '$module_name' " . - "AND `name` = '$name'"); + db::build() + ->update("vars") + ->set("value", new Database_Expression("`value` + $increment")) + ->where("module_name", "=", $module_name) + ->where("name", "=", $name) + ->execute(); - Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); + db::build() + ->delete("vars") + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") + ->execute(); self::$var_cache = null; } -- cgit v1.2.3 From 0736cf203b37534848482e47c3afde9b58d6ce27 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 17 Dec 2009 21:32:53 -0800 Subject: In Kohana 2.4, ORM no longer does the find_all() call for us when we retrieve related ORMs. If we tack a find_all() on the end, it breaks the User_Definition interface so create User_Model::groups() and Groups_Model::users() as glue. --- modules/gallery/helpers/access.php | 2 +- modules/gallery/helpers/identity.php | 2 +- modules/gallery/tests/Access_Helper_Test.php | 6 +++--- modules/user/models/group.php | 4 ++++ modules/user/models/user.php | 4 ++++ 5 files changed, 13 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 85410085..8ce7e436 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -101,7 +101,7 @@ class access_Core { $resource = $perm_name == "view" ? $item : model_cache::get("access_cache", $item->id, "item_id"); - foreach ($user->groups->find_all() as $group) { + foreach ($user->groups() as $group) { if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) { return true; } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php index 707d1830..eae0ea3e 100644 --- a/modules/gallery/helpers/identity.php +++ b/modules/gallery/helpers/identity.php @@ -75,7 +75,7 @@ class identity_Core { if (!$session->get("group_ids")) { $ids = array(); - foreach ($user->groups->find_all() as $group) { + foreach ($user->groups() as $group) { $ids[] = $group->id; } $session->set("group_ids", $ids); diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 771c6a85..799d5e44 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -76,7 +76,7 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::registered_users(), "view", $item); $user = identity::create_user("access_test", "Access Test", ""); - foreach ($user->groups as $group) { + foreach ($user->groups() as $group) { $user->remove($group); } $user->add($access_test); @@ -93,7 +93,7 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::registered_users(), "view", $item); $user = identity::create_user("access_test", "Access Test", ""); - foreach ($user->groups as $group) { + foreach ($user->groups() as $group) { $user->remove($group); } $user->save(); @@ -288,7 +288,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function i_can_edit_test() { // Create a new user that belongs to no groups $user = identity::create_user("access_test", "Access Test", ""); - foreach ($user->groups as $group) { + foreach ($user->groups() as $group) { $user->remove($group); } $user->save(); diff --git a/modules/user/models/group.php b/modules/user/models/group.php index 3a084684..515788a3 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -33,6 +33,10 @@ class Group_Model extends ORM implements Group_Definition { module::event("group_deleted", $old); } + public function users() { + return $this->users->find_all(); + } + public function save() { if (!$this->loaded()) { $created = 1; diff --git a/modules/user/models/user.php b/modules/user/models/user.php index e14d9b31..7d5bf413 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -61,6 +61,10 @@ class User_Model extends ORM implements User_Definition { md5($this->email), $size, $default ? "&d=" . urlencode($default) : ""); } + public function groups() { + return $this->groups->find_all(); + } + public function save() { if (!$this->loaded()) { $created = 1; -- cgit v1.2.3 From c10386fe87f9fe0d659e730d171800f26f809604 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 18 Dec 2009 01:05:02 -0800 Subject: Convert html::specialchars() to html::chars() --- modules/user/helpers/user.php | 2 +- modules/user/libraries/drivers/IdentityProvider/Gallery.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 5027580c..e092aecc 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -86,7 +86,7 @@ class user_Core { } // Passwords with <&"> created by G2 prior to 2.1 were hashed with entities - $sanitizedPassword = html::specialchars($password, false); + $sanitizedPassword = html::chars($password, false); $guess = (strlen($valid) == 32) ? md5($sanitizedPassword) : ($salt . md5($salt . $sanitizedPassword)); if (!strcmp($guess, $valid)) { diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php index f02c53a2..50064287 100644 --- a/modules/user/libraries/drivers/IdentityProvider/Gallery.php +++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php @@ -63,7 +63,7 @@ class IdentityProvider_Gallery_Driver implements IdentityProvider_Driver { } // Passwords with <&"> created by G2 prior to 2.1 were hashed with entities - $sanitizedPassword = html::specialchars($password, false); + $sanitizedPassword = html::chars($password, false); $guess = (strlen($valid) == 32) ? md5($sanitizedPassword) : ($salt . md5($salt . $sanitizedPassword)); if (!strcmp($guess, $valid)) { -- cgit v1.2.3 From ca1f7d0da7495aaa2558ddad134f14164a550ab3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 18 Dec 2009 01:12:16 -0800 Subject: Convert a database query. --- modules/gallery/models/item.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index d7ddcd02..e2208b73 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -120,11 +120,13 @@ class Item_Model extends ORM_MPTT { if ($this->is_album()) { @rename(dirname($original_resize_path), dirname($this->resize_path())); @rename(dirname($original_thumb_path), dirname($this->thumb_path())); - Database::instance() - ->update("items", - array("relative_path_cache" => null, - "relative_url_cache" => null), - array("left_ptr >" => $this->left_ptr, "right_ptr <" => $this->right_ptr)); + db::build() + ->update("items") + ->set("relative_path_cache", null) + ->set("relative_url_cache", null) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<", $this->right_ptr) + ->execute(); } else { @rename($original_resize_path, $this->resize_path()); @rename($original_thumb_path, $this->thumb_path()); -- cgit v1.2.3 From 338af4a722fb08abdf9f5b364418ceb83a329cdc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 18 Dec 2009 01:16:27 -0800 Subject: Database::escape_str() is now Database::escape(). --- modules/search/helpers/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 70a39272..b2497eae 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -20,7 +20,7 @@ class search_Core { static function search($q, $limit, $offset) { $db = Database::instance(); - $q = $db->escape_str($q); + $q = $db->escape($q); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { -- cgit v1.2.3 From 046382c3e7f863e291d000eb2bb549474e475d1b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 18 Dec 2009 11:27:44 -0800 Subject: Remove some unused references to Database::instance() --- modules/tag/models/tag.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'modules') diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index f6cc6144..b2ce9eda 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -61,7 +61,6 @@ class Tag_Model extends ORM { * event for the union of all related items before and after the save. */ public function save() { - $db = Database::instance(); $related_item_ids = array(); foreach (db::build() ->select("item_id") @@ -98,8 +97,6 @@ class Tag_Model extends ORM { */ public function delete() { $related_item_ids = array(); - $db = Database::Instance(); - foreach (db::build() ->select("item_id") ->from("items_tags") -- cgit v1.2.3 From 9af0a4e59c17987137b0ea316b6ccd45c02ca8a8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 18 Dec 2009 13:36:43 -0800 Subject: Convert a database call. --- modules/server_add/controllers/server_add.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 78e1620c..70ad6ea2 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -176,14 +176,13 @@ class Server_Add_Controller extends Admin_Controller { $task->set("queue", $queue); $task->percent_complete = min($task->percent_complete + 0.1, 10); $task->status = t2("Found one file", "Found %count files", - Database::instance() - ->where("task_id", "=", $task->id) - ->count_records("server_add_files")); + db::build()->count_records( + "server_add_files", array("task_id" => $task->id))); if (!$queue) { $task->set("mode", "add-files"); $task->set( - "total_files", database::instance()->count_records( + "total_files", db::build()->count_records( "server_add_files", array("task_id" => $task->id))); $task->percent_complete = 10; } -- cgit v1.2.3 From 91e39f75a2e2954377da1c830388965f030f03be Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 11:29:13 -0800 Subject: Hardcode language translations since K24 now does it totally differently. This forks the code, but it's reached the end of its development path and we should replace it with phpunit anyway --- modules/unit_test/libraries/Unit_Test.php | 96 ++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 27 deletions(-) (limited to 'modules') diff --git a/modules/unit_test/libraries/Unit_Test.php b/modules/unit_test/libraries/Unit_Test.php index 7558759c..badefb79 100644 --- a/modules/unit_test/libraries/Unit_Test.php +++ b/modules/unit_test/libraries/Unit_Test.php @@ -20,6 +20,48 @@ class Unit_Test_Core { // Statistics for every test class protected $stats = array(); + public static $lang = array( + 'class' => 'Class', + 'method' => 'Method', + 'invalid_test_path' => 'Failed to open test path: %s.', + 'duplicate_test_class' => 'Duplicate test class named %s found in %s.', + 'test_class_not_found' => 'No test class by the name of %s found in %s.', + 'test_class_extends' => '%s must extend Unit_Test_Case.', + 'no_tests_found' => 'No tests found', + 'score' => 'Score', + 'total' => 'Total', + 'passed' => 'Passed', + 'failed' => 'Failed', + 'error' => 'Error', + 'errors' => 'Errors', + 'line' => 'line', + 'assert_true' => 'assert_true: Expected true, but was given (%s) %s.', + 'assert_true_strict' => 'assert_true_strict: Expected (boolean) true, but was given (%s) %s.', + 'assert_false' => 'assert_false: Expected false, but was given (%s) %s.', + 'assert_false_strict' => 'assert_false_strict: Expected (boolean) false, but was given (%s) %s.', + 'assert_equal' => 'assert_equal: Expected (%s) %s, but was given (%s) %s.', + 'assert_not_equal' => 'assert_not_equal: Expected not (%s) %s, but was given (%s) %s.', + 'assert_same' => 'assert_same: Expected (%s) %s, but was given (%s) %s.', + 'assert_not_same' => 'assert_not_same: Expected not (%s) %s, but was given (%s) %s.', + 'assert_boolean' => 'assert_boolean: Expected a boolean, but was given (%s) %s.', + 'assert_not_boolean' => 'assert_not_boolean: Expected not a boolean, but was given (%s) %s.', + 'assert_integer' => 'assert_integer: Expected an integer, but was given (%s) %s.', + 'assert_not_integer' => 'assert_not_integer: Expected not an integer, but was given (%s) %s.', + 'assert_float' => 'assert_float: Expected a float, but was given (%s) %s.', + 'assert_not_float' => 'assert_not_float: Expected not a float, but was given (%s) %s.', + 'assert_array' => 'assert_array: Expected an array, but was given (%s) %s.', + 'assert_array_key' => 'assert_array_key: Expected a valid key, but was given (%s) %s.', + 'assert_in_array' => 'assert_in_array: Expected a valid value, but was given (%s) %s.', + 'assert_not_array' => 'assert_not_array: Expected not an array, but was given (%s) %s.', + 'assert_object' => 'assert_object: Expected an object, but was given (%s) %s.', + 'assert_not_object' => 'assert_not_object: Expected not an object, but was given (%s) %s.', + 'assert_null' => 'assert_null: Expected null, but was given (%s) %s.', + 'assert_not_null' => 'assert_not_null: Expected not null, but was given (%s) %s.', + 'assert_empty' => 'assert_empty: Expected an empty value, but was given (%s) %s.', + 'assert_not_empty' => 'assert_not_empty: Expected not an empty value, but was given (%s) %s.', + 'assert_pattern' => 'assert_pattern: Expected %s to match %s.', + 'assert_not_pattern' => 'assert_not_pattern: Expected %s to not match %s.' + ); /** * Sets the test path(s), runs the tests inside and stores the results. * @@ -207,7 +249,7 @@ class Unit_Test_Core { { // No tests found if (empty($this->results)) - return Kohana::lang('unit_test.no_tests_found'); + return sprintf(self::$lang['unit_test.no_tests_found']); // Hide passed tests from the report? $hide_passed = (bool) (($hide_passed !== NULL) ? $hide_passed : Kohana::config('unit_test.hide_passed', FALSE, FALSE)); @@ -259,7 +301,7 @@ abstract class Unit_Test_Case { public function assert_true($value, $debug = NULL) { if ($value != TRUE) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_true'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -267,7 +309,7 @@ abstract class Unit_Test_Case { public function assert_true_strict($value, $debug = NULL) { if ($value !== TRUE) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true_strict', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_true_strict'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -275,7 +317,7 @@ abstract class Unit_Test_Case { public function assert_false($value, $debug = NULL) { if ($value != FALSE) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_false'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -283,7 +325,7 @@ abstract class Unit_Test_Case { public function assert_false_strict($value, $debug = NULL) { if ($value !== FALSE) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false_strict', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_false_strict'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -291,7 +333,7 @@ abstract class Unit_Test_Case { public function assert_equal($expected, $actual, $debug = NULL) { if ($expected != $actual) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_equal', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -299,7 +341,7 @@ abstract class Unit_Test_Case { public function assert_not_equal($expected, $actual, $debug = NULL) { if ($expected == $actual) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_equal', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -307,7 +349,7 @@ abstract class Unit_Test_Case { public function assert_same($expected, $actual, $debug = NULL) { if ($expected !== $actual) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_same', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -315,7 +357,7 @@ abstract class Unit_Test_Case { public function assert_not_same($expected, $actual, $debug = NULL) { if ($expected === $actual) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_same', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -323,7 +365,7 @@ abstract class Unit_Test_Case { public function assert_boolean($value, $debug = NULL) { if ( ! is_bool($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_boolean', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_boolean'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -331,7 +373,7 @@ abstract class Unit_Test_Case { public function assert_not_boolean($value, $debug = NULL) { if (is_bool($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_boolean', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_boolean'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -339,7 +381,7 @@ abstract class Unit_Test_Case { public function assert_integer($value, $debug = NULL) { if ( ! is_int($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_integer', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_integer'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -347,7 +389,7 @@ abstract class Unit_Test_Case { public function assert_not_integer($value, $debug = NULL) { if (is_int($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_integer', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_integer'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -355,7 +397,7 @@ abstract class Unit_Test_Case { public function assert_float($value, $debug = NULL) { if ( ! is_float($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_float', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_float'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -363,7 +405,7 @@ abstract class Unit_Test_Case { public function assert_not_float($value, $debug = NULL) { if (is_float($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_float', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_float'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -371,7 +413,7 @@ abstract class Unit_Test_Case { public function assert_array($value, $debug = NULL) { if ( ! is_array($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_array'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -379,7 +421,7 @@ abstract class Unit_Test_Case { public function assert_array_key($key, $array, $debug = NULL) { if ( ! array_key_exists($key, $array)) { - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array_key', gettype($key), var_export($key, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_array_key'], gettype($key), var_export($key, TRUE)), $debug); } return $this; @@ -388,7 +430,7 @@ abstract class Unit_Test_Case { public function assert_in_array($value, $array, $debug = NULL) { if ( ! in_array($value, $array)) { - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_in_array', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_in_array'], gettype($value), var_export($value, TRUE)), $debug); } return $this; @@ -397,7 +439,7 @@ abstract class Unit_Test_Case { public function assert_not_array($value, $debug = NULL) { if (is_array($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_array', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_array'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -405,7 +447,7 @@ abstract class Unit_Test_Case { public function assert_object($value, $debug = NULL) { if ( ! is_object($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_object', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_object'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -413,7 +455,7 @@ abstract class Unit_Test_Case { public function assert_not_object($value, $debug = NULL) { if (is_object($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_object', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_object'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -421,7 +463,7 @@ abstract class Unit_Test_Case { public function assert_null($value, $debug = NULL) { if ($value !== NULL) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_null', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_null'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -429,7 +471,7 @@ abstract class Unit_Test_Case { public function assert_not_null($value, $debug = NULL) { if ($value === NULL) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_null', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_null'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -437,7 +479,7 @@ abstract class Unit_Test_Case { public function assert_empty($value, $debug = NULL) { if ( ! empty($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_empty'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -445,7 +487,7 @@ abstract class Unit_Test_Case { public function assert_not_empty($value, $debug = NULL) { if (empty($value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_empty'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -453,7 +495,7 @@ abstract class Unit_Test_Case { public function assert_pattern($value, $regex, $debug = NULL) { if ( ! is_string($value) OR ! is_string($regex) OR ! preg_match($regex, $value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug); return $this; } @@ -461,7 +503,7 @@ abstract class Unit_Test_Case { public function assert_not_pattern($value, $regex, $debug = NULL) { if ( ! is_string($value) OR ! is_string($regex) OR preg_match($regex, $value)) - throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug); return $this; } -- cgit v1.2.3 From a22aa4ab05e50bb0bdd5e59a27b5f1867323f7a2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 11:29:28 -0800 Subject: Forgot to rename the file when I renamed the class. --- modules/gallery/tests/Gallery_I18n_Test.php | 108 ++++++++++++++++++++++++++++ modules/gallery/tests/I18n_Test.php | 108 ---------------------------- 2 files changed, 108 insertions(+), 108 deletions(-) create mode 100644 modules/gallery/tests/Gallery_I18n_Test.php delete mode 100644 modules/gallery/tests/I18n_Test.php (limited to 'modules') diff --git a/modules/gallery/tests/Gallery_I18n_Test.php b/modules/gallery/tests/Gallery_I18n_Test.php new file mode 100644 index 00000000..895e3051 --- /dev/null +++ b/modules/gallery/tests/Gallery_I18n_Test.php @@ -0,0 +1,108 @@ + 'en', + 'default_locale' => 'te_ST', + 'locale_dir' => VARPATH . 'locale/'); + $this->i18n = Gallery_I18n::instance($config); + + ORM::factory("incoming_translation") + ->where("locale", "=", "te_ST") + ->delete_all(); + + $messages_te_ST = array( + array('Hello world', 'Hallo Welt'), + array(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('one' => 'Ein Element wurde hinzugefuegt.', + 'other' => '%count Elemente wurden hinzugefuegt.')), + array('Hello %name, how are you today?', 'Hallo %name, wie geht es Dir heute?')); + + foreach ($messages_te_ST as $data) { + list ($message, $translation) = $data; + $entry = ORM::factory("incoming_translation"); + $entry->key = Gallery_I18n::get_message_key($message); + $entry->message = serialize($message); + $entry->translation = serialize($translation); + $entry->locale = 'te_ST'; + $entry->revision = null; + $entry->save(); + } + } + + public function get_locale_test() { + $locale = $this->i18n->locale(); + $this->assert_equal("te_ST", $locale); + } + + public function set_locale_test() { + $this->i18n->locale("de_DE"); + $locale = $this->i18n->locale(); + $this->assert_equal("de_DE", $locale); + } + + public function translate_simple_test() { + $result = $this->i18n->translate('Hello world'); + $this->assert_equal('Hallo Welt', $result); + } + + public function translate_simple_root_fallback_test() { + $result = $this->i18n->translate('Hello world zzz'); + $this->assert_equal('Hello world zzz', $result); + } + + public function translate_plural_other_test() { + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 5)); + $this->assert_equal('5 Elemente wurden hinzugefuegt.', $result); + } + + public function translate_plural_one_test() { + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 1)); + $this->assert_equal('Ein Element wurde hinzugefuegt.', $result); + } + + public function translate_interpolate_test() { + $result = $this->i18n->translate('Hello %name, how are you today?', array('name' => 'John')); + $this->assert_equal('Hallo John, wie geht es Dir heute?', $result); + } + + public function translate_interpolate_missing_value_test() { + $result = $this->i18n->translate('Hello %name, how are you today?', array('foo' => 'bar')); + $this->assert_equal('Hallo %name, wie geht es Dir heute?', $result); + } + + public function translate_plural_zero_test() { + // te_ST has the same plural rules as en and de. + // For count 0, plural form "other" should be used. + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 0)); + $this->assert_equal('0 Elemente wurden hinzugefuegt.', $result); + } +} \ No newline at end of file diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php deleted file mode 100644 index 895e3051..00000000 --- a/modules/gallery/tests/I18n_Test.php +++ /dev/null @@ -1,108 +0,0 @@ - 'en', - 'default_locale' => 'te_ST', - 'locale_dir' => VARPATH . 'locale/'); - $this->i18n = Gallery_I18n::instance($config); - - ORM::factory("incoming_translation") - ->where("locale", "=", "te_ST") - ->delete_all(); - - $messages_te_ST = array( - array('Hello world', 'Hallo Welt'), - array(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('one' => 'Ein Element wurde hinzugefuegt.', - 'other' => '%count Elemente wurden hinzugefuegt.')), - array('Hello %name, how are you today?', 'Hallo %name, wie geht es Dir heute?')); - - foreach ($messages_te_ST as $data) { - list ($message, $translation) = $data; - $entry = ORM::factory("incoming_translation"); - $entry->key = Gallery_I18n::get_message_key($message); - $entry->message = serialize($message); - $entry->translation = serialize($translation); - $entry->locale = 'te_ST'; - $entry->revision = null; - $entry->save(); - } - } - - public function get_locale_test() { - $locale = $this->i18n->locale(); - $this->assert_equal("te_ST", $locale); - } - - public function set_locale_test() { - $this->i18n->locale("de_DE"); - $locale = $this->i18n->locale(); - $this->assert_equal("de_DE", $locale); - } - - public function translate_simple_test() { - $result = $this->i18n->translate('Hello world'); - $this->assert_equal('Hallo Welt', $result); - } - - public function translate_simple_root_fallback_test() { - $result = $this->i18n->translate('Hello world zzz'); - $this->assert_equal('Hello world zzz', $result); - } - - public function translate_plural_other_test() { - $result = $this->i18n->translate(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('count' => 5)); - $this->assert_equal('5 Elemente wurden hinzugefuegt.', $result); - } - - public function translate_plural_one_test() { - $result = $this->i18n->translate(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('count' => 1)); - $this->assert_equal('Ein Element wurde hinzugefuegt.', $result); - } - - public function translate_interpolate_test() { - $result = $this->i18n->translate('Hello %name, how are you today?', array('name' => 'John')); - $this->assert_equal('Hallo John, wie geht es Dir heute?', $result); - } - - public function translate_interpolate_missing_value_test() { - $result = $this->i18n->translate('Hello %name, how are you today?', array('foo' => 'bar')); - $this->assert_equal('Hallo %name, wie geht es Dir heute?', $result); - } - - public function translate_plural_zero_test() { - // te_ST has the same plural rules as en and de. - // For count 0, plural form "other" should be used. - $result = $this->i18n->translate(array('one' => 'One item has been added', - 'other' => '%count elements have been added'), - array('count' => 0)); - $this->assert_equal('0 Elemente wurden hinzugefuegt.', $result); - } -} \ No newline at end of file -- cgit v1.2.3 From 287f79dd721193aaaafdee3908cd8f251654de02 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 11:30:06 -0800 Subject: Updated for K24 --- .../controllers/gallery_unit_test.php | 39 +++++++++++----------- modules/gallery_unit_test/helpers/MY_request.php | 25 ++++++++++++++ 2 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 modules/gallery_unit_test/helpers/MY_request.php (limited to 'modules') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 391ad029..498dd756 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -20,7 +20,7 @@ class Gallery_Unit_Test_Controller extends Controller { function Index() { if (!TEST_MODE) { - print throw new Kohana_404_Exception(); + throw new Kohana_404_Exception(); } // Jump through some hoops to satisfy the way that we check for the site_domain in @@ -30,6 +30,7 @@ class Gallery_Unit_Test_Controller extends Controller { $_SERVER["SCRIPT_FILENAME"] = "index.php"; $_SERVER["SCRIPT_NAME"] = "./index.php"; + $config = Kohana_Config::instance(); $original_config = DOCROOT . "var/database.php"; $test_config = VARPATH . "database.php"; if (!file_exists($original_config)) { @@ -41,20 +42,20 @@ class Gallery_Unit_Test_Controller extends Controller { if (empty($db_config['unit_test'])) { $default = $db_config['default']; $conn = $default['connection']; - Kohana::config_set('database.unit_test.benchmark', $default['benchmark']); - Kohana::config_set('database.unit_test.persistent', $default['persistent']); - Kohana::config_set('database.unit_test.connection.type', $conn['type']); - Kohana::config_set('database.unit_test.connection.user', $conn['user']); - Kohana::config_set('database.unit_test.connection.pass', $conn['pass']); - Kohana::config_set('database.unit_test.connection.host', $conn['host']); - Kohana::config_set('database.unit_test.connection.port', $conn['port']); - Kohana::config_set('database.unit_test.connection.socket', $conn['socket']); - Kohana::config_set('database.unit_test.connection.database', "{$conn['database']}_test"); - Kohana::config_set('database.unit_test.character_set', $default['character_set']); - Kohana::config_set('database.unit_test.table_prefix', $default['table_prefix']); - Kohana::config_set('database.unit_test.object', $default['object']); - Kohana::config_set('database.unit_test.cache', $default['cache']); - Kohana::config_set('database.unit_test.escape', $default['escape']); + $config->set('database.unit_test.benchmark', $default['benchmark']); + $config->set('database.unit_test.persistent', $default['persistent']); + $config->set('database.unit_test.connection.type', $conn['type']); + $config->set('database.unit_test.connection.user', $conn['user']); + $config->set('database.unit_test.connection.pass', $conn['pass']); + $config->set('database.unit_test.connection.host', $conn['host']); + $config->set('database.unit_test.connection.port', $conn['port']); + $config->set('database.unit_test.connection.socket', $conn['socket']); + $config->set('database.unit_test.connection.database', "{$conn['database']}_test"); + $config->set('database.unit_test.character_set', $default['character_set']); + $config->set('database.unit_test.table_prefix', $default['table_prefix']); + $config->set('database.unit_test.object', $default['object']); + $config->set('database.unit_test.cache', $default['cache']); + $config->set('database.unit_test.escape', $default['escape']); $db_config = Kohana::config('database'); } @@ -69,7 +70,7 @@ class Gallery_Unit_Test_Controller extends Controller { $db->connect(); // Make this the default database for the rest of this run - Database::$instances = array('default' => $db); + Database::set_default_instance($db); } catch (Exception $e) { print "{$e->getMessage()}\n"; return; @@ -80,7 +81,7 @@ class Gallery_Unit_Test_Controller extends Controller { // Clean out the database if ($tables = $db->list_tables()) { foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE $table"); + $db->query("DROP TABLE {{$table}}"); } } @@ -97,7 +98,7 @@ class Gallery_Unit_Test_Controller extends Controller { $db->clear_cache(); // Rest the cascading class path - Kohana::config_set("core", Kohana::config_load("core")); + $config->set("core", $config->load("core")); // Install the active modules // Force gallery and user to be installed first to resolve dependencies. @@ -119,7 +120,7 @@ class Gallery_Unit_Test_Controller extends Controller { } } - Kohana::config_set('unit_test.paths', $paths); + $config->set('unit_test.paths', $paths); // Trigger late-binding install actions (defined in gallery_event::user_login) graphics::choose_default_toolkit(); diff --git a/modules/gallery_unit_test/helpers/MY_request.php b/modules/gallery_unit_test/helpers/MY_request.php new file mode 100644 index 00000000..9cc9746a --- /dev/null +++ b/modules/gallery_unit_test/helpers/MY_request.php @@ -0,0 +1,25 @@ + Date: Mon, 21 Dec 2009 11:30:26 -0800 Subject: Add Database::set_default_instance() for tests --- modules/gallery/libraries/MY_Database.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index fd486039..a8f4bc08 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -57,4 +57,11 @@ abstract class Database extends Database_Core { return strtr($sql, $this->_table_names); } + + /** + * This is used by the unit test code to switch the active database connection. + */ + static function set_default_instance($db) { + self::$instances["default"] = $db; + } } \ No newline at end of file -- cgit v1.2.3 From bfcd99f3f2a7d1b2c5ed0b6593c202ff07058b68 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 11:30:34 -0800 Subject: Updated for K24 --- modules/akismet/tests/Akismet_Helper_Test.php | 2 +- modules/comment/tests/Comment_Helper_Test.php | 7 ++++--- modules/gallery/tests/Database_Test.php | 25 +++++++++++++++---------- modules/gallery/tests/Item_Model_Test.php | 15 +++++++++++---- 4 files changed, 31 insertions(+), 18 deletions(-) (limited to 'modules') diff --git a/modules/akismet/tests/Akismet_Helper_Test.php b/modules/akismet/tests/Akismet_Helper_Test.php index 745b455c..d8605d5c 100644 --- a/modules/akismet/tests/Akismet_Helper_Test.php +++ b/modules/akismet/tests/Akismet_Helper_Test.php @@ -22,7 +22,7 @@ class Akismet_Helper_Test extends Unit_Test_Case { public function setup() { Input::instance()->ip_address = "1.1.1.1"; - Kohana::$user_agent = "Akismet_Helper_Test"; + request::set_user_agent("Akismet_Helper_Test"); $root = ORM::factory("item", 1); $this->_comment = comment::create( diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php index 82b7ebd2..8e726869 100644 --- a/modules/comment/tests/Comment_Helper_Test.php +++ b/modules/comment/tests/Comment_Helper_Test.php @@ -23,7 +23,7 @@ class Comment_Helper_Test extends Unit_Test_Case { public function setup() { $this->_ip_address = Input::instance()->ip_address; - $this->_user_agent = Kohana::$user_agent; + $this->_user_agent = request::user_agent(); $this->_save = $_SERVER; $_SERVER["HTTP_ACCEPT"] = "HTTP_ACCEPT"; @@ -33,16 +33,17 @@ class Comment_Helper_Test extends Unit_Test_Case { $_SERVER["HTTP_CONNECTION"] = "HTTP_CONNECTION"; $_SERVER["HTTP_HOST"] = "HTTP_HOST"; $_SERVER["HTTP_REFERER"] = "HTTP_REFERER"; - $_SERVER["HTTP_USER_AGENT"] = "HTTP_USER_AGENT"; $_SERVER["QUERY_STRING"] = "QUERY_STRING"; $_SERVER["REMOTE_ADDR"] = "REMOTE_ADDR"; $_SERVER["REMOTE_HOST"] = "REMOTE_HOST"; $_SERVER["REMOTE_PORT"] = "REMOTE_PORT"; + + request::set_user_agent("HTTP_USER_AGENT"); } public function teardown() { Input::instance()->ip_address = $this->_ip_address; - Kohana::$user_agent = $this->_user_agent; + request::set_user_agent($this->_user_agent); $_SERVER = $this->_save; } diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 9b428379..4259961e 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -19,7 +19,7 @@ */ class Database_Test extends Unit_Test_Case { function simple_where_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("a", "=", 1) ->where("b", "=", 2) ->compile(); @@ -28,7 +28,7 @@ class Database_Test extends Unit_Test_Case { } function compound_where_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) @@ -43,7 +43,7 @@ class Database_Test extends Unit_Test_Case { } function group_first_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->and_open() ->where("inner1", "=", 1) ->or_where("inner2", "=", 2) @@ -58,12 +58,12 @@ class Database_Test extends Unit_Test_Case { } function where_array_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) ->or_where("inner2", "=", 2) - ->or_where("inner3", "=", 3)) + ->or_where("inner3", "=", 3) ->close() ->compile(); $sql = str_replace("\n", " ", $sql); @@ -73,7 +73,7 @@ class Database_Test extends Unit_Test_Case { } function notlike_test() { - $sql = Database::instance() + $sql = Database_Builder_For_Test::instance() ->where("outer1", "=", 1) ->or_open() ->where("inner1", "NOT LIKE", 1) @@ -86,7 +86,7 @@ class Database_Test extends Unit_Test_Case { } function prefix_replacement_test() { - $db = Database_For_Test::instance(); + $db = Database::instance(); $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test_tables} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, @@ -118,7 +118,8 @@ class Database_Test extends Unit_Test_Case { } function prefix_no_replacement_test() { - $update = Database_For_Test::instance()->from("test_tables") + $update = Database_Builder_For_Test::instance() + ->from("test_tables") ->where("1", "=", "1") ->set(array("name" => "Test Name")) ->update(); @@ -129,9 +130,9 @@ class Database_Test extends Unit_Test_Case { } } -class Database_For_Test extends Database { +class Database_Builder_For_Test extends Database_Builder { static function instance() { - $db = new Database_For_Test(); + $db = new Database_Builder_For_Test(); $db->_table_names["{items}"] = "g3test_items"; $db->config["table_prefix"] = "g3test_"; return $db; @@ -143,4 +144,8 @@ class Database_For_Test extends Database { } return $sql; } + + public function compile() { + return parent::compile(); + } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index e7dce893..bf5fca1a 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -35,8 +35,12 @@ class Item_Model_Test extends Unit_Test_Case { $item = self::_create_random_item(); // Force the creation date to something well known - $db = Database::instance(); - $db->update("items", array("created" => 0, "updated" => 0), array("id" => $item->id)); + db::build() + ->update("items") + ->set("created", 0) + ->set("updated", 0) + ->where("id", "=", $item->id) + ->execute(); $item->reload(); $item->title = "foo"; // force a change $item->save(); @@ -51,8 +55,11 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_same(0, $item->view_count); // Force the updated date to something well known - $db = Database::instance(); - $db->update("items", array("updated" => 0), array("id" => $item->id)); + db::build() + ->update("items") + ->set("updated", 0) + ->where("id", "=", $item->id) + ->execute(); $item->reload(); $item->view_count++; $item->save(); -- cgit v1.2.3 From 7d8f76fa7a303447f7835b803c05739b3e8e48c3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 12:07:20 -0800 Subject: Fix the translation keys to not require "unit_test." as a prefix. --- modules/unit_test/libraries/Unit_Test.php | 54 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'modules') diff --git a/modules/unit_test/libraries/Unit_Test.php b/modules/unit_test/libraries/Unit_Test.php index badefb79..46a926d8 100644 --- a/modules/unit_test/libraries/Unit_Test.php +++ b/modules/unit_test/libraries/Unit_Test.php @@ -249,7 +249,7 @@ class Unit_Test_Core { { // No tests found if (empty($this->results)) - return sprintf(self::$lang['unit_test.no_tests_found']); + return sprintf(self::$lang['no_tests_found']); // Hide passed tests from the report? $hide_passed = (bool) (($hide_passed !== NULL) ? $hide_passed : Kohana::config('unit_test.hide_passed', FALSE, FALSE)); @@ -301,7 +301,7 @@ abstract class Unit_Test_Case { public function assert_true($value, $debug = NULL) { if ($value != TRUE) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_true'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_true'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -309,7 +309,7 @@ abstract class Unit_Test_Case { public function assert_true_strict($value, $debug = NULL) { if ($value !== TRUE) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_true_strict'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_true_strict'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -317,7 +317,7 @@ abstract class Unit_Test_Case { public function assert_false($value, $debug = NULL) { if ($value != FALSE) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_false'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_false'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -325,7 +325,7 @@ abstract class Unit_Test_Case { public function assert_false_strict($value, $debug = NULL) { if ($value !== FALSE) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_false_strict'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_false_strict'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -333,7 +333,7 @@ abstract class Unit_Test_Case { public function assert_equal($expected, $actual, $debug = NULL) { if ($expected != $actual) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -341,7 +341,7 @@ abstract class Unit_Test_Case { public function assert_not_equal($expected, $actual, $debug = NULL) { if ($expected == $actual) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_equal'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -349,7 +349,7 @@ abstract class Unit_Test_Case { public function assert_same($expected, $actual, $debug = NULL) { if ($expected !== $actual) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -357,7 +357,7 @@ abstract class Unit_Test_Case { public function assert_not_same($expected, $actual, $debug = NULL) { if ($expected === $actual) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_same'], gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); return $this; } @@ -365,7 +365,7 @@ abstract class Unit_Test_Case { public function assert_boolean($value, $debug = NULL) { if ( ! is_bool($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_boolean'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_boolean'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -373,7 +373,7 @@ abstract class Unit_Test_Case { public function assert_not_boolean($value, $debug = NULL) { if (is_bool($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_boolean'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_boolean'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -381,7 +381,7 @@ abstract class Unit_Test_Case { public function assert_integer($value, $debug = NULL) { if ( ! is_int($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_integer'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_integer'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -389,7 +389,7 @@ abstract class Unit_Test_Case { public function assert_not_integer($value, $debug = NULL) { if (is_int($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_integer'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_integer'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -397,7 +397,7 @@ abstract class Unit_Test_Case { public function assert_float($value, $debug = NULL) { if ( ! is_float($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_float'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_float'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -405,7 +405,7 @@ abstract class Unit_Test_Case { public function assert_not_float($value, $debug = NULL) { if (is_float($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_float'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_float'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -413,7 +413,7 @@ abstract class Unit_Test_Case { public function assert_array($value, $debug = NULL) { if ( ! is_array($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_array'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_array'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -421,7 +421,7 @@ abstract class Unit_Test_Case { public function assert_array_key($key, $array, $debug = NULL) { if ( ! array_key_exists($key, $array)) { - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_array_key'], gettype($key), var_export($key, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_array_key'], gettype($key), var_export($key, TRUE)), $debug); } return $this; @@ -430,7 +430,7 @@ abstract class Unit_Test_Case { public function assert_in_array($value, $array, $debug = NULL) { if ( ! in_array($value, $array)) { - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_in_array'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_in_array'], gettype($value), var_export($value, TRUE)), $debug); } return $this; @@ -439,7 +439,7 @@ abstract class Unit_Test_Case { public function assert_not_array($value, $debug = NULL) { if (is_array($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_array'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_array'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -447,7 +447,7 @@ abstract class Unit_Test_Case { public function assert_object($value, $debug = NULL) { if ( ! is_object($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_object'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_object'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -455,7 +455,7 @@ abstract class Unit_Test_Case { public function assert_not_object($value, $debug = NULL) { if (is_object($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_object'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_object'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -463,7 +463,7 @@ abstract class Unit_Test_Case { public function assert_null($value, $debug = NULL) { if ($value !== NULL) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_null'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_null'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -471,7 +471,7 @@ abstract class Unit_Test_Case { public function assert_not_null($value, $debug = NULL) { if ($value === NULL) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_null'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_null'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -479,7 +479,7 @@ abstract class Unit_Test_Case { public function assert_empty($value, $debug = NULL) { if ( ! empty($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_empty'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_empty'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -487,7 +487,7 @@ abstract class Unit_Test_Case { public function assert_not_empty($value, $debug = NULL) { if (empty($value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_empty'], gettype($value), var_export($value, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_empty'], gettype($value), var_export($value, TRUE)), $debug); return $this; } @@ -495,7 +495,7 @@ abstract class Unit_Test_Case { public function assert_pattern($value, $regex, $debug = NULL) { if ( ! is_string($value) OR ! is_string($regex) OR ! preg_match($regex, $value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug); return $this; } @@ -503,7 +503,7 @@ abstract class Unit_Test_Case { public function assert_not_pattern($value, $regex, $debug = NULL) { if ( ! is_string($value) OR ! is_string($regex) OR preg_match($regex, $value)) - throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['unit_test.assert_not_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug); + throw new Kohana_Unit_Test_Exception(sprintf(Unit_Test::$lang['assert_not_pattern'], var_export($value, TRUE), var_export($regex, TRUE)), $debug); return $this; } -- cgit v1.2.3 From 0c3fd9579fa5008cb51ab7080f2d861aa3fbfd6a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 12:09:16 -0800 Subject: Stop using Kohana::lang. --- modules/gallery_unit_test/views/kohana_unit_test_cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery_unit_test/views/kohana_unit_test_cli.php b/modules/gallery_unit_test/views/kohana_unit_test_cli.php index 352671eb..3203ee44 100644 --- a/modules/gallery_unit_test/views/kohana_unit_test_cli.php +++ b/modules/gallery_unit_test/views/kohana_unit_test_cli.php @@ -44,7 +44,7 @@ foreach ($results as $class => $methods) { red_start(), color_end()); echo " ", $result->getMessage(), "\n"; echo " ", $result->getFile(); - echo " ", "(" . Kohana::lang("unit_test.line") . " " . $result->getLine(), ")\n"; + echo " ", "(line " . $result->getLine(), ")\n"; if ($result->getDebug() !== null) { echo " ", "(", gettype($result->getDebug()), ") ", var_export($result->getDebug(), true), "\n"; -- cgit v1.2.3 From 5df1dc135b6b1fad77a23cd604f008e0784bdd73 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 12:13:25 -0800 Subject: Fix some bugs in the cache database driver, and update the tests for K24. --- .../gallery/libraries/drivers/Cache/Database.php | 7 +- modules/gallery/tests/Cache_Test.php | 79 ++++++++++------------ 2 files changed, 37 insertions(+), 49 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 5c453f28..82a09ab9 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -90,7 +90,7 @@ class Cache_Database_Driver extends Cache_Driver { ->select() ->from("caches"); foreach ($tags as $tag) { - $db->where("tags", "LIKE", "<$tag>"); + $db->where("tags", "LIKE", "%<$tag>%"); } $db_result = $db->execute(); @@ -153,14 +153,13 @@ class Cache_Database_Driver extends Cache_Driver { * @param bool delete a tag * @return bool */ - public function delete($id, $tag = false) { + public function delete($id, $tag=false) { $db = db::build() ->delete("caches"); if ($id === true) { // Delete all caches - $db->where("1", "=", "1"); } else if ($tag === true) { - $db->where("tags", "LIKE", "<$id>"); + $db->where("tags", "LIKE", "%<$id>%"); } else { $db->where("key", "=", $id); } diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index 776c6625..d5bf37cc 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -20,88 +20,83 @@ class Cache_Test extends Unit_Test_Case { private $_driver; public function setup() { - Database::instance()->from("caches")->where("1", "=", "1")->delete(); + db::build()->delete("caches")->execute(); $this->_driver = new Cache_Database_Driver(); } public function cache_exists_test() { - $db = Database::instance(); - $this->assert_false($this->_driver->exists("test_key"), "test_key should not be defined"); $id = md5(rand()); - $db->insert("caches", array("key" => $id, "tags" => ", ", - "expiration" => 84600 + time(), - "cache" => serialize("some test data"))); + db::build() + ->insert("caches") + ->columns("key", "tags", "expiration", "cache") + ->values($id, ", ", 84600 + time(), serialize("some test data")) + ->execute(); $this->assert_true($this->_driver->exists($id), "test_key should be defined"); } public function cache_get_test() { - $db = Database::instance(); - $id = md5(rand()); - $db->insert("caches", array("key" => $id, "tags" => ", ", - "expiration" => 84600 + time(), - "cache" => serialize("some test data"))); - $data = $this->_driver->get($id); + db::build() + ->insert("caches") + ->columns("key", "tags", "expiration", "cache") + ->values($id, ", ", 84600 + time(), serialize("some test data")) + ->execute(); + + $data = $this->_driver->get(array($id)); $this->assert_equal("some test data", $data, "cached data should match"); - $data = $this->_driver->get(""); + $data = $this->_driver->get(array("")); $this->assert_equal(null, $data, "cached data should not be found"); } public function cache_set_test() { - $db = Database::instance(); - $id = md5(rand()); $original_data = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id, $original_data, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id => $original_data), array("tag1", "tag2"), 84600); - $data = $this->_driver->get($id); + $data = $this->_driver->get(array($id)); $this->assert_equal($original_data, $data, "cached data should match"); } - public function cache_find_test() { - $db = Database::instance(); - + public function cache_get_tag_test() { $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 84600); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 84600); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); - $data = $this->_driver->find("tag2"); + $data = $this->_driver->get_tag(array("tag2")); $expected = array($id1 => $value1, $id2 => $value2); ksort($expected); $this->assert_equal($expected, $data, "Expected id1 & id2"); - $data = $this->_driver->find("tag4"); + $data = $this->_driver->get_tag(array("tag4")); $this->assert_equal(array($id3 => $value3), $data, "Expected id3"); } public function cache_delete_expired_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), -84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), -84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), -846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), -846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), -84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), -84600); $data = $this->_driver->delete_expired(); @@ -111,19 +106,17 @@ class Cache_Test extends Unit_Test_Case { } public function cache_delete_id_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); $this->_driver->delete($id1); @@ -133,19 +126,17 @@ class Cache_Test extends Unit_Test_Case { } public function cache_delete_tag_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); $data = $this->_driver->delete("tag3", true); @@ -155,19 +146,17 @@ class Cache_Test extends Unit_Test_Case { } public function cache_delete_all_test() { - $db = Database::instance(); - $id1 = md5(rand()); $value1 = array("field1" => "value1", "field2" => "value2"); - $this->_driver->set($id1, $value1, array("tag1", "tag2"), 84600); + $this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600); $id2 = md5(rand()); $value2 = array("field3" => "value3", "field4" => "value4"); - $this->_driver->set($id2, $value2, array("tag2", "tag3"), 846000); + $this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000); $id3 = md5(rand()); $value3 = array("field5" => "value5", "field6" => "value6"); - $this->_driver->set($id3, $value3, array("tag3", "tag4"), 84600); + $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); $data = $this->_driver->delete(true); -- cgit v1.2.3 From e1f43ad403ac3deba8ac19d3d748500bba608395 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 12:22:19 -0800 Subject: Updated for K24 --- modules/gallery/tests/Sendmail_Test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/Sendmail_Test.php b/modules/gallery/tests/Sendmail_Test.php index 64c1fff0..f3a8d897 100644 --- a/modules/gallery/tests/Sendmail_Test.php +++ b/modules/gallery/tests/Sendmail_Test.php @@ -19,9 +19,7 @@ */ class Sendmail_Test extends Unit_Test_Case { public function setup() { - $config = Kohana::config("sendmail"); - $config["from"] = "from@gallery3.com"; - Kohana::config_set("sendmail", $config); + Kohana_Config::instance()->set("sendmail.from", "from@gallery3.com"); } public function sendmail_test() { -- cgit v1.2.3 From cc4d7c672c863185bab5d654222e205d6517e98a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 15:40:28 -0800 Subject: Update database tests for K24. Use a mock database that we load through the framework so that we're properly testing the Database_Builder, it's a lot cleaner than what we had before. --- modules/gallery/tests/Database_Test.php | 105 +++++++++++++-------- .../libraries/MY_Database_Builder.php | 4 + 2 files changed, 72 insertions(+), 37 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 4259961e..6aa186e5 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -18,17 +18,27 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Database_Test extends Unit_Test_Case { + function setup() { + $config = Kohana_Config::instance(); + $config->set("database.mock.connection.type", "mock"); + $config->set("database.mock.cache", false); + $config->set("database.mock.table_prefix", "g_"); + } + function simple_where_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select("some_column") + ->from("some_table") ->where("a", "=", 1) ->where("b", "=", 2) ->compile(); $sql = str_replace("\n", " ", $sql); - $this->assert_same("SELECT * WHERE `a` = 1 AND `b` = 2", $sql); + $this->assert_same("SELECT [some_column] FROM [some_table] WHERE [a] = [1] AND [b] = [2]", $sql); } function compound_where_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) @@ -38,12 +48,13 @@ class Database_Test extends Unit_Test_Case { ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE `outer1` = 1 AND (`inner1` = 1 OR `inner2` = 2) AND `outer2` = 2", + "SELECT [*] WHERE [outer1] = [1] AND ([inner1] = [1] OR [inner2] = [2]) AND [outer2] = [2]", $sql); } function group_first_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->and_open() ->where("inner1", "=", 1) ->or_where("inner2", "=", 2) @@ -53,12 +64,13 @@ class Database_Test extends Unit_Test_Case { ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE (`inner1` = 1 OR `inner2` = 2) AND `outer1` = 1 AND `outer2` = 2", + "SELECT [*] WHERE ([inner1] = [1] OR [inner2] = [2]) AND [outer1] = [1] AND [outer2] = [2]", $sql); } function where_array_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->where("outer1", "=", 1) ->and_open() ->where("inner1", "=", 1) @@ -68,32 +80,33 @@ class Database_Test extends Unit_Test_Case { ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE `outer1` = 1 AND (`inner1` = 1 OR `inner2` = 2 OR `inner3` = 3)", + "SELECT [*] WHERE [outer1] = [1] AND ([inner1] = [1] OR [inner2] = [2] OR [inner3] = [3])", $sql); } function notlike_test() { - $sql = Database_Builder_For_Test::instance() + $sql = db::build("mock") + ->select() ->where("outer1", "=", 1) ->or_open() - ->where("inner1", "NOT LIKE", 1) + ->where("inner1", "NOT LIKE", "%1%") ->close() ->compile(); $sql = str_replace("\n", " ", $sql); $this->assert_same( - "SELECT * WHERE `outer1` = 1 OR ( `inner1` NOT LIKE '%1%')", + "SELECT [*] WHERE [outer1] = [1] OR ([inner1] NOT LIKE [%1%])", $sql); } function prefix_replacement_test() { - $db = Database::instance(); - $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test_tables} ( + $db = Database::instance("mock"); + $converted = $db->add_table_prefixes("CREATE TABLE IF NOT EXISTS {test} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); - $expected = "CREATE TABLE IF NOT EXISTS g3test_test_tables ( + $expected = "CREATE TABLE IF NOT EXISTS g_test ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), @@ -101,16 +114,16 @@ class Database_Test extends Unit_Test_Case { ENGINE=InnoDB DEFAULT CHARSET=utf8"; $this->assert_same($expected, $converted); - $sql = "UPDATE {test_tables} SET `name` = '{test string}' " . + $sql = "UPDATE {test} SET `name` = '{test string}' " . "WHERE `item_id` IN " . - " (SELECT `id` FROM {items} " . + " (SELECT `id` FROM {test} " . " WHERE `left_ptr` >= 1 " . " AND `right_ptr` <= 6)"; $sql = $db->add_table_prefixes($sql); - $expected = "UPDATE g3test_test_tables SET `name` = '{test string}' " . + $expected = "UPDATE g_test SET `name` = '{test string}' " . "WHERE `item_id` IN " . - " (SELECT `id` FROM g3test_items " . + " (SELECT `id` FROM g_test " . " WHERE `left_ptr` >= 1 " . " AND `right_ptr` <= 6)"; @@ -118,34 +131,52 @@ class Database_Test extends Unit_Test_Case { } function prefix_no_replacement_test() { - $update = Database_Builder_For_Test::instance() + $sql = db::build("mock") ->from("test_tables") ->where("1", "=", "1") ->set(array("name" => "Test Name")) - ->update(); + ->update() + ->compile(); + $sql = str_replace("\n", " ", $sql); + $this->assert_same("UPDATE [test_tables] SET [name] = [Test Name] WHERE [1] = [1]", $sql); + } +} - $expected = "UPDATE `g3test_test_tables` SET `name` = 'Test Name' WHERE 1 = 1"; +class Database_Mock extends Database { + public function connect() { + } - $this->assert_same($expected, $update); + public function disconnect() { } -} -class Database_Builder_For_Test extends Database_Builder { - static function instance() { - $db = new Database_Builder_For_Test(); - $db->_table_names["{items}"] = "g3test_items"; - $db->config["table_prefix"] = "g3test_"; - return $db; + public function set_charset($charset) { } - public function query($sql = '') { - if (!empty($sql)) { - $sql = $this->add_table_prefixes($sql); - } - return $sql; + public function query_execute($sql) { } - public function compile() { - return parent::compile(); + public function escape($val) { } -} + + public function list_constraints($table) { + } + + public function list_fields($table) { + } + + public function list_tables() { + return array("test"); + } + + public function quote_column($val) { + return "[$val]"; + } + + public function quote_table($val) { + return "[$val]"; + } + + public function quote($val) { + return "[$val]"; + } +} \ No newline at end of file diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php index 974f9c6d..54a10860 100644 --- a/modules/kohana23_compat/libraries/MY_Database_Builder.php +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -28,4 +28,8 @@ class Database_Builder extends Database_Builder_Core { } return $this; } + + public function compile() { + return parent::compile(); + } } \ No newline at end of file -- cgit v1.2.3 From 31a545fa26a002432f01beabdae147de34793ec8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 15:58:22 -0800 Subject: Add missing execute() call -- tests ftw! --- modules/comment/helpers/comment_event.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 576e041d..43a30d70 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -21,7 +21,8 @@ class comment_event_Core { static function item_deleted($item) { db::build() ->delete("comments") - ->where("item_id", "=", $item->id); + ->where("item_id", "=", $item->id) + ->execute(); } static function user_deleted($user) { -- cgit v1.2.3 From 5080bc12a240e6e6c1fb7d2c8e93d78137b5092c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 16:40:01 -0800 Subject: Fix the relationship. DigibugProxy belongs to Item, not the other way around. K24 ORM requires this because it needs to know where the foreign key is (in the Digibug_Proxy table, in this case). --- modules/digibug/models/digibug_proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/digibug/models/digibug_proxy.php b/modules/digibug/models/digibug_proxy.php index c76afdae..10949ed7 100644 --- a/modules/digibug/models/digibug_proxy.php +++ b/modules/digibug/models/digibug_proxy.php @@ -18,5 +18,5 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Digibug_Proxy_Model extends ORM { - protected $has_one = array("item"); + protected $belongs_to = array("item"); } -- cgit v1.2.3 From ffb81c33571072e549d9f84f76c801699aef4cff Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 16:40:18 -0800 Subject: Rename $id --> $uuid for clarity. --- modules/digibug/controllers/digibug.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 03f9e812..d070727d 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -55,7 +55,7 @@ class Digibug_Controller extends Controller { print $v; } - public function print_proxy($type, $id) { + public function print_proxy($type, $uuid) { // If its a request for the full size then make sure we are coming from an // authorized address if ($type == "full") { @@ -80,7 +80,7 @@ class Digibug_Controller extends Controller { } } - $proxy = ORM::factory("digibug_proxy", array("uuid" => $id)); + $proxy = ORM::factory("digibug_proxy")->where("uuid", "=", $uuid)->find(); if (!$proxy->loaded() || !$proxy->item->loaded()) { throw new Kohana_404_Exception(); } -- cgit v1.2.3 From a474fb51556d9bf102f779faacf0671dc11dade7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 16:40:48 -0800 Subject: Get rid of unnecessary cleanup that makes debugging harder. --- modules/digibug/tests/Digibug_Controller_Test.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'modules') diff --git a/modules/digibug/tests/Digibug_Controller_Test.php b/modules/digibug/tests/Digibug_Controller_Test.php index a56d58bb..015a270a 100644 --- a/modules/digibug/tests/Digibug_Controller_Test.php +++ b/modules/digibug/tests/Digibug_Controller_Test.php @@ -24,10 +24,6 @@ class Digibug_Controller_Test extends Unit_Test_Case { public function teardown() { $_SERVER = $this->_server; - - if ($this->_proxy) { - $this->_proxy->delete(); - } } public function setup() { -- cgit v1.2.3 From e94009e90df5124ab83aad6a7f6a45806c3ff71b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 17:26:04 -0800 Subject: Add a helper for doing complex string comparisons --- modules/gallery_unit_test/helpers/diff.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 modules/gallery_unit_test/helpers/diff.php (limited to 'modules') diff --git a/modules/gallery_unit_test/helpers/diff.php b/modules/gallery_unit_test/helpers/diff.php new file mode 100644 index 00000000..1ea16fa6 --- /dev/null +++ b/modules/gallery_unit_test/helpers/diff.php @@ -0,0 +1,26 @@ + Date: Mon, 21 Dec 2009 17:26:24 -0800 Subject: Updated for recent K24 Forge changes. --- modules/gallery/tests/DrawForm_Test.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/DrawForm_Test.php b/modules/gallery/tests/DrawForm_Test.php index 7ee80ca2..baded8de 100644 --- a/modules/gallery/tests/DrawForm_Test.php +++ b/modules/gallery/tests/DrawForm_Test.php @@ -25,9 +25,10 @@ class DrawForm_Test extends Unit_Test_Case { $form->submit("")->value(t("Submit")); $rendered = $form->__toString(); + $csrf = access::csrf_token(); $expected = "
      \n" . - "\n" . + "" . "
        \n" . "
      • \n" . " \n" . @@ -36,14 +37,14 @@ class DrawForm_Test extends Unit_Test_Case { "
      • \n" . "
      • \n" . " \n" . - " \n" . "
      • \n" . "
      • \n" . " \n" . "
      • \n" . "
      \n" . - "
      \n"; + ""; $this->assert_same($expected, $rendered); } @@ -55,9 +56,10 @@ class DrawForm_Test extends Unit_Test_Case { $group->submit("")->value(t("Submit")); $rendered = $form->__toString(); + $csrf = access::csrf_token(); $expected = "
      \n" . - "\n" . + "" . "
      \n" . " Test Group\n" . "
        \n" . @@ -68,7 +70,7 @@ class DrawForm_Test extends Unit_Test_Case { " \n" . "
      • \n" . " \n" . - " \n" . "
      • \n" . "
      • \n" . @@ -76,7 +78,7 @@ class DrawForm_Test extends Unit_Test_Case { "
      • \n" . "
      \n" . "
      \n" . - "
      \n"; + ""; $this->assert_same($expected, $rendered); } @@ -91,9 +93,10 @@ class DrawForm_Test extends Unit_Test_Case { $group->submit("")->value(t("Submit")); $rendered = $form->__toString(); + $csrf = access::csrf_token(); $expected = "
      \n" . - "\n" . + "" . "
      \n" . " Test Group\n" . "
        \n" . @@ -104,7 +107,7 @@ class DrawForm_Test extends Unit_Test_Case { " \n" . "
      • \n" . " \n" . - " \n" . "
      • \n" . "
      • \n" . @@ -116,7 +119,7 @@ class DrawForm_Test extends Unit_Test_Case { "\n" . - "
      • \n"; + ""; $this->assert_same($expected, $rendered); } } -- cgit v1.2.3 From 9c5df1d31bd214fab051b71d092c751a1da20ecc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Dec 2009 19:59:44 -0800 Subject: Fix preambles, and fix the File_Structure_Test to be more lenient because of preamble variation in K24. --- application/Bootstrap.php | 22 +++++++++---- modules/gallery/config/log_file.php | 20 ++++++++++- modules/gallery/tests/File_Structure_Test.php | 16 ++++++--- modules/kohana23_compat/config/pagination.php | 42 +++++++++++++----------- modules/kohana23_compat/libraries/Pagination.php | 20 ++++++++++- 5 files changed, 87 insertions(+), 33 deletions(-) (limited to 'modules') diff --git a/application/Bootstrap.php b/application/Bootstrap.php index f36fac14..95f7b8d2 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -1,13 +1,21 @@ -\n"; + $expected_2 = " 'pagination', - 'style' => 'classic', - 'uri_segment' => 3, - 'query_string' => '', - 'items_per_page' => 20, - 'auto_hide' => FALSE, +$config["default"] = array( + "directory" => "pagination", + "style" => "classic", + "uri_segment" => 3, + "query_string" => "", + "items_per_page" => 20, + "auto_hide" => FALSE ); diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php index 8ff8bf94..012bc484 100644 --- a/modules/kohana23_compat/libraries/Pagination.php +++ b/modules/kohana23_compat/libraries/Pagination.php @@ -1,4 +1,22 @@ - Date: Mon, 21 Dec 2009 21:27:43 -0800 Subject: Updates for the latest version of Kohana 2.4: 1) Controller::$input is gone -- use Input::instance() now 2) Handle new 'database..connection.params' parameter 3) Handle new 'cache..prefix' parameter --- installer/database_config.php | 3 ++- modules/digibug/controllers/digibug.php | 2 +- modules/gallery/config/cache.php | 3 ++- modules/gallery/controllers/admin_dashboard.php | 2 +- modules/gallery/controllers/admin_identity.php | 4 ++-- modules/gallery/controllers/admin_languages.php | 7 ++++--- modules/gallery/controllers/admin_modules.php | 2 +- modules/gallery/controllers/admin_sidebar.php | 2 +- modules/gallery/controllers/albums.php | 14 ++++++++------ modules/gallery/controllers/file_proxy.php | 2 +- modules/gallery/controllers/logout.php | 2 +- modules/gallery/controllers/move.php | 2 +- modules/gallery/libraries/MY_Database.php | 14 ++++++++++++++ modules/organize/controllers/organize.php | 4 ++-- modules/rss/controllers/rss.php | 4 ++-- modules/search/controllers/search.php | 4 ++-- modules/server_add/controllers/admin_server_add.php | 4 ++-- modules/server_add/controllers/server_add.php | 2 +- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/controllers/tags.php | 6 +++--- 20 files changed, 52 insertions(+), 33 deletions(-) (limited to 'modules') diff --git a/installer/database_config.php b/installer/database_config.php index 8abf35e7..a5dc8865 100644 --- a/installer/database_config.php +++ b/installer/database_config.php @@ -35,7 +35,8 @@ $config['default'] = array( 'host' => '', 'port' => '' false, 'socket' => false, - 'database' => '' + 'database' => '', + 'params' => null, ), 'character_set' => 'utf8', 'table_prefix' => '', diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index d070727d..a23d2863 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -59,7 +59,7 @@ class Digibug_Controller extends Controller { // If its a request for the full size then make sure we are coming from an // authorized address if ($type == "full") { - $remote_addr = ip2long($this->input->server("REMOTE_ADDR")); + $remote_addr = ip2long(Input::instance()->server("REMOTE_ADDR")); if ($remote_addr === false) { throw new Kohana_404_Exception(); } diff --git a/modules/gallery/config/cache.php b/modules/gallery/config/cache.php index cc3ac87d..d9a27c96 100644 --- a/modules/gallery/config/cache.php +++ b/modules/gallery/config/cache.php @@ -45,5 +45,6 @@ $config["default"] = array ( "driver" => "database", "params" => null, "lifetime" => 84600, - "requests" => 1000 + "requests" => 1000, + "prefix" => null, ); diff --git a/modules/gallery/controllers/admin_dashboard.php b/modules/gallery/controllers/admin_dashboard.php index 7e28f625..5f2cb41d 100644 --- a/modules/gallery/controllers/admin_dashboard.php +++ b/modules/gallery/controllers/admin_dashboard.php @@ -86,7 +86,7 @@ class Admin_Dashboard_Controller extends Admin_Controller { foreach (array("dashboard_sidebar", "dashboard_center") as $location) { $new_blocks = array(); - foreach ($this->input->get($location, array()) as $id) { + foreach (Input::instance()->get($location, array()) as $id) { $new_blocks[$id] = $active_set[$id]; } block_manager::set_active($location, $new_blocks); diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index acf71665..354e6c0c 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -30,7 +30,7 @@ class Admin_Identity_Controller extends Admin_Controller { access::verify_csrf(); $v = new View("admin_identity_confirm.html"); - $v->new_provider = $this->input->post("provider"); + $v->new_provider = Input::instance()->post("provider"); print $v; } @@ -40,7 +40,7 @@ class Admin_Identity_Controller extends Admin_Controller { $active_provider = module::get_var("gallery", "identity_provider", "user"); $providers = identity::providers(); - $new_provider = $this->input->post("provider"); + $new_provider = Input::instance()->post("provider"); if ($new_provider != $active_provider) { diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php index 27537c7f..41523023 100644 --- a/modules/gallery/controllers/admin_languages.php +++ b/modules/gallery/controllers/admin_languages.php @@ -36,10 +36,11 @@ class Admin_Languages_Controller extends Admin_Controller { public function save() { access::verify_csrf(); - locales::update_installed($this->input->post("installed_locales")); + $input = Input::instance(); + locales::update_installed($input->post("installed_locales")); $installed_locales = array_keys(locales::installed()); - $new_default_locale = $this->input->post("default_locale"); + $new_default_locale = $input->post("default_locale"); if (!in_array($new_default_locale, $installed_locales)) { if (!empty($installed_locales)) { $new_default_locale = $installed_locales[0]; @@ -61,7 +62,7 @@ class Admin_Languages_Controller extends Admin_Controller { return $this->index($form); } - if ($this->input->post("share")) { + if (Input::instance()->post("share")) { l10n_client::submit_translations(); message::success(t("Translations submitted")); } else { diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index af6dbbdc..549718e7 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -37,7 +37,7 @@ class Admin_Modules_Controller extends Admin_Controller { continue; } - $desired = $this->input->post($module_name) == 1; + $desired = Input::instance()->post($module_name) == 1; if ($info->active && !$desired && module::is_active($module_name)) { $changes->deactivate[] = $module_name; $deactivated_names[] = t($info->name); diff --git a/modules/gallery/controllers/admin_sidebar.php b/modules/gallery/controllers/admin_sidebar.php index 77e83bc2..4c55bf89 100644 --- a/modules/gallery/controllers/admin_sidebar.php +++ b/modules/gallery/controllers/admin_sidebar.php @@ -34,7 +34,7 @@ class Admin_Sidebar_Controller extends Admin_Controller { $available_blocks = block_manager::get_available_site_blocks(); $active_blocks = array(); - foreach ($this->input->get("block", array()) as $block_id) { + foreach (Input::instance()->get("block", array()) as $block_id) { $active_blocks[md5($block_id)] = explode(":", (string) $block_id); } block_manager::set_active("site_sidebar", $active_blocks); diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 319f1416..2134a419 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -42,7 +42,8 @@ class Albums_Controller extends Items_Controller { } } - $show = $this->input->get("show"); + $input = Input::instance(); + $show = $input->get("show"); if ($show) { $child = ORM::factory("item", $show); @@ -57,7 +58,7 @@ class Albums_Controller extends Items_Controller { } } - $page = $this->input->get("page", "1"); + $page = $input->get("page", "1"); $children_count = $album->viewable()->children_count(); $offset = ($page - 1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); @@ -94,15 +95,16 @@ class Albums_Controller extends Items_Controller { access::required("view", $album); access::required("add", $album); + $input = Input::instance(); $form = album::get_add_form($album); if ($form->validate()) { $new_album = album::create( $album, - $this->input->post("name"), - $this->input->post("title", $this->input->post("name")), - $this->input->post("description"), + $input->post("name"), + $input->post("title", $input->post("name")), + $input->post("description"), identity::active_user()->id, - $this->input->post("slug")); + $input->post("slug")); log::success("content", "Created an album", html::anchor("albums/$new_album->id", "view album")); diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index 8c46de08..6a80ad85 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -29,7 +29,7 @@ class File_Proxy_Controller extends Controller { public function __call($function, $args) { // request_uri: http://example.com/gallery3/var/trunk/albums/foo/bar.jpg - $request_uri = $this->input->server("REQUEST_URI"); + $request_uri = Input::instance()->server("REQUEST_URI"); $request_uri = preg_replace("/\?.*/", "", $request_uri); // var_uri: http://example.com/gallery3/var/ diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 2b93655d..fe9c48ba 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -20,7 +20,7 @@ class Logout_Controller extends Controller { public function index() { auth::logout(); - if ($continue_url = $this->input->get("continue")) { + if ($continue_url = Input::instance()->get("continue")) { $item = url::get_item_from_uri($continue_url); if (access::can("view", $item)) { // Don't use url::redirect() because it'll call url::site() and munge the continue url. diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index 863b13bb..14513fdc 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -32,7 +32,7 @@ class Move_Controller extends Controller { public function save($source_id) { access::verify_csrf(); $source = ORM::factory("item", $source_id); - $target = ORM::factory("item", $this->input->post("target_id")); + $target = ORM::factory("item", Input::instance()->post("target_id")); access::required("view", $source); access::required("edit", $source); diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index a8f4bc08..de3e5a84 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -20,6 +20,20 @@ abstract class Database extends Database_Core { protected $_table_names; + /** + * Kohana 2.4 introduces a new connection parameter. If it's not specified, make sure that we + * define it here to avoid an error later on. + * + * @todo: add an upgrade path to modify var/database.php so that we can avoid doing this at + * runtime. + */ + protected function __construct(array $config) { + if (!isset($config["connection"]["params"])) { + $config["connection"]["params"] = null; + } + parent::__construct($config); + } + /** * Parse the query string and convert any strings of the form `\([a-zA-Z0-9_]*?)\] * table prefix . $1 diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 08c80de3..03dea13d 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -48,7 +48,7 @@ class Organize_Controller extends Controller { access::required("view", $target_album); access::required("add", $target_album); - foreach ($this->input->post("source_ids") as $source_id) { + foreach (Input::instance()->post("source_ids") as $source_id) { $source = ORM::factory("item", $source_id); if (!$source->contains($target_album)) { access::required("edit", $source); @@ -69,7 +69,7 @@ class Organize_Controller extends Controller { access::required("view", $album); access::required("edit", $album); - $source_ids = $this->input->post("source_ids", array()); + $source_ids = Input::instance()->post("source_ids", array()); if ($album->sort_column != "weight") { $i = 0; diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php index a963a1dc..41c781d9 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -21,13 +21,13 @@ class Rss_Controller extends Controller { public static $page_size = 20; public function feed($module_id, $feed_id, $id=null) { - $page = (int) $this->input->get("page", 1); + $page = (int) Input::instance()->get("page", 1); if ($page < 1) { url::redirect(url::merge(array("page" => 1))); } // Configurable page size between 1 and 100, default 20 - $page_size = max(1, min(100, (int) $this->input->get("page_size", self::$page_size))); + $page_size = max(1, min(100, (int) Input::instance()->get("page_size", self::$page_size))); // Run the appropriate feed callback if (module::is_active($module_id)) { diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index 2f1aeb76..ea870847 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -20,8 +20,8 @@ class Search_Controller extends Controller { public function index() { $page_size = module::get_var("gallery", "page_size", 9); - $q = $this->input->get("q"); - $page = $this->input->get("page", 1); + $q = Input::instance()->get("q"); + $page = Input::instance()->get("page", 1); $offset = ($page - 1) * $page_size; // Make sure that the page references a valid offset diff --git a/modules/server_add/controllers/admin_server_add.php b/modules/server_add/controllers/admin_server_add.php index f32bb834..17c3f68b 100644 --- a/modules/server_add/controllers/admin_server_add.php +++ b/modules/server_add/controllers/admin_server_add.php @@ -58,7 +58,7 @@ class Admin_Server_Add_Controller extends Admin_Controller { public function remove_path() { access::verify_csrf(); - $path = $this->input->get("path"); + $path = Input::instance()->get("path"); $paths = unserialize(module::get_var("server_add", "authorized_paths")); if (isset($paths[$path])) { unset($paths[$path]); @@ -71,7 +71,7 @@ class Admin_Server_Add_Controller extends Admin_Controller { public function autocomplete() { $directories = array(); - $path_prefix = $this->input->get("q"); + $path_prefix = Input::instance()->get("q"); foreach (glob("{$path_prefix}*") as $file) { if (is_dir($file) && !is_link($file)) { $directories[] = $file; diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 70ad6ea2..77487673 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -34,7 +34,7 @@ class Server_Add_Controller extends Admin_Controller { } public function children() { - $path = $this->input->get("path"); + $path = Input::instance()->get("path"); $tree = new View("server_add_tree.html"); $tree->files = array(); diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index ed4a0366..a56d4d20 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -19,7 +19,7 @@ */ class Admin_Tags_Controller extends Admin_Controller { public function index() { - $filter = $this->input->get("filter"); + $filter = Input::instance()->get("filter"); $view = new Admin_View("admin.html"); $view->content = new View("admin_tags.html"); diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index a44f6aa3..992c7411 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -21,7 +21,7 @@ class Tags_Controller extends Controller { public function show($tag_id) { $tag = ORM::factory("tag", $tag_id); $page_size = module::get_var("gallery", "page_size", 9); - $page = (int) $this->input->get("page", "1"); + $page = (int) Input::instance()->get("page", "1"); $children_count = $tag->items_count(); $offset = ($page-1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); @@ -79,8 +79,8 @@ class Tags_Controller extends Controller { public function autocomplete() { $tags = array(); - $tag_parts = preg_split("#,#", $this->input->get("q")); - $limit = $this->input->get("limit"); + $tag_parts = preg_split("#,#", Input::instance()->get("q")); + $limit = Input::instance()->get("limit"); $tag_part = end($tag_parts); $tag_list = ORM::factory("tag") ->where("name", "LIKE", "{$tag_part}%") -- cgit v1.2.3 From 7118f84aa9ae0ece97a41aba4e4d269a1e136df6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 13:32:02 -0800 Subject: ORM::factory() in K24 does not allow you to specify an alternate key for lookup. So instead of doing: ORM::factory("foo", array("some_key" => "some_value")) you have to do: ORM::factory("foo"->where("some_key", "=" "some_value")->find() --- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/module.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index d76c4d19..bb7cb449 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -42,7 +42,7 @@ class l10n_scanner_Core { return $cache[$key]; } - $entry = ORM::factory("incoming_translation", array("key" => $key)); + $entry = ORM::factory("incoming_translation")->where("key", "=", $key)->find(); if (!$entry->loaded()) { $entry->key = $key; $entry->message = serialize($message); diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 71c4efa0..6c7078a3 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -51,7 +51,7 @@ class module_Core { */ static function get($module_name) { if (empty(self::$modules[$module_name])) { - return ORM::factory("module", array("name" => $module_name)); + return ORM::factory("module")->where("name", "=", $module_name)->find(); } return self::$modules[$module_name]; } -- cgit v1.2.3 From 0650109d4bb5442cd77fcda61745dab67a632836 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 13:50:52 -0800 Subject: Add merge_or_where() to MY_Datatabase_Builder and use that instead of or_where() for compatibility and convenience. Caught by failing unit tests. --- modules/gallery/helpers/item.php | 4 ++-- modules/kohana23_compat/libraries/MY_Database_Builder.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index b7be23cd..f6181f8a 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -155,12 +155,12 @@ class item_Core { $view_restrictions = array(); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { - $view_restrictions["items.view_$id"] = access::ALLOW; + $view_restrictions[] = array("items.view_$id", "=", access::ALLOW); } } if (count($view_restrictions)) { - $model->and_open()->or_where($view_restrictions)->close(); + $model->and_open()->merge_or_where($view_restrictions)->close(); } return $model; diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php index 54a10860..c82b6ac4 100644 --- a/modules/kohana23_compat/libraries/MY_Database_Builder.php +++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php @@ -29,6 +29,17 @@ class Database_Builder extends Database_Builder_Core { return $this; } + /** + * Merge in a series of where clause tuples and call or_where() on each one. + * @chainable + */ + public function merge_or_where($tuples) { + foreach ($tuples as $tuple) { + $this->or_where($tuple[0], $tuple[1], $tuple[2]); + } + return $this; + } + public function compile() { return parent::compile(); } -- cgit v1.2.3 From ca293db214e2f74471ce7f9d29f65bd629f2f284 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 13:57:49 -0800 Subject: Don't rely on implicit object -> id conversion, that doesn't work with K24's Database_Builder::where() --- modules/gallery/tests/Access_Helper_Test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 799d5e44..084bfb47 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -131,7 +131,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function can_allow_deny_and_reset_intent_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - $intent = ORM::factory("access_intent")->where("item_id", "=", $album)->find(); + $intent = ORM::factory("access_intent")->where("item_id", "=", $album->id)->find(); // Allow access::allow(identity::everybody(), "view", $album); @@ -141,19 +141,19 @@ class Access_Helper_Test extends Unit_Test_Case { access::deny(identity::everybody(), "view", $album); $this->assert_same( access::DENY, - ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album->id)->find()->view_1); // Allow again. If the initial value was allow, then the first Allow clause above may not // have actually changed any values. access::allow(identity::everybody(), "view", $album); $this->assert_same( access::ALLOW, - ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album->id)->find()->view_1); access::reset(identity::everybody(), "view", $album); $this->assert_same( null, - ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1); + ORM::factory("access_intent")->where("item_id", "=", $album->id)->find()->view_1); } public function cant_reset_root_item_test() { -- cgit v1.2.3 From fda4227bb10d7c9ae4de5f16e59890bf7cf3b83b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 14:00:52 -0800 Subject: Latest K24 does not automatically add an id attribute to every form element with the same value as the name. Yay! That was a weird and unexpected behavior. --- modules/gallery/tests/DrawForm_Test.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/DrawForm_Test.php b/modules/gallery/tests/DrawForm_Test.php index baded8de..90361d06 100644 --- a/modules/gallery/tests/DrawForm_Test.php +++ b/modules/gallery/tests/DrawForm_Test.php @@ -28,16 +28,16 @@ class DrawForm_Test extends Unit_Test_Case { $csrf = access::csrf_token(); $expected = "
        \n" . - "" . + "" . "
          \n" . "
        • \n" . " \n" . - " \n" . "
        • \n" . "
        • \n" . " \n" . - " \n" . "
        • \n" . "
        • \n" . @@ -59,18 +59,18 @@ class DrawForm_Test extends Unit_Test_Case { $csrf = access::csrf_token(); $expected = "\n" . - "" . + "" . "
          \n" . " Test Group\n" . "
            \n" . "
          • \n" . " \n" . - " \n" . "
          • \n" . "
          • \n" . " \n" . - " \n" . "
          • \n" . "
          • \n" . @@ -96,18 +96,18 @@ class DrawForm_Test extends Unit_Test_Case { $csrf = access::csrf_token(); $expected = "\n" . - "" . + "" . "
            \n" . " Test Group\n" . "
              \n" . "
            • \n" . " \n" . - " \n" . "
            • \n" . "
            • \n" . " \n" . - " \n" . "
            • \n" . "
            • \n" . -- cgit v1.2.3 From d711c5b9300a17e7269415573a15e8a63f0d149c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 15:36:36 -0800 Subject: Convert tabs to spaces. Enough to get the file structure test to pass, but not really the Gallery coding convention -- this is a compatibility class though. --- modules/kohana23_compat/libraries/Pagination.php | 438 +++++++++++------------ 1 file changed, 219 insertions(+), 219 deletions(-) (limited to 'modules') diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php index 012bc484..2b06f359 100644 --- a/modules/kohana23_compat/libraries/Pagination.php +++ b/modules/kohana23_compat/libraries/Pagination.php @@ -29,224 +29,224 @@ */ class Pagination_Core { - // Config values - protected $base_url = ''; - protected $directory = 'pagination'; - protected $style = 'classic'; - protected $uri_segment = 3; - protected $query_string = ''; - protected $items_per_page = 20; - protected $total_items = 0; - protected $auto_hide = FALSE; - - // Autogenerated values - protected $url; - protected $current_page; - protected $total_pages; - protected $current_first_item; - protected $current_last_item; - protected $first_page; - protected $last_page; - protected $previous_page; - protected $next_page; - protected $sql_offset; - protected $sql_limit; - - /** - * Constructs and returns a new Pagination object. - * - * @param array configuration settings - * @return object - */ - public function factory($config = array()) - { - return new Pagination($config); - } - - /** - * Constructs a new Pagination object. - * - * @param array configuration settings - * @return void - */ - public function __construct($config = array()) - { - // No custom group name given - if ( ! isset($config['group'])) - { - $config['group'] = 'default'; - } - - // Pagination setup - $this->initialize($config); - } - - /** - * Sets config values. - * - * @throws Kohana_Exception - * @param array configuration settings - * @return void - */ - public function initialize($config = array()) - { - // Load config group - if (isset($config['group'])) - { - // Load and validate config group - if ( ! is_array($group_config = Kohana::config('pagination.'.$config['group']))) - throw new Kohana_Exception('pagination.undefined_group: ' . $config['group']); - - // All pagination config groups inherit default config group - if ($config['group'] !== 'default') - { - // Load and validate default config group - if ( ! is_array($default_config = Kohana::config('pagination.default'))) - throw new Kohana_Exception('pagination.undefined_group: default'); - - // Merge config group with default config group - $group_config += $default_config; - } - - // Merge custom config items with config group - $config += $group_config; - } - - // Assign config values to the object - foreach ($config as $key => $value) - { - if (property_exists($this, $key)) - { - $this->$key = $value; - } - } - - // Clean view directory - $this->directory = trim($this->directory, '/').'/'; - - // Build generic URL with page in query string - if ($this->query_string !== '') - { - // Extract current page - $this->current_page = isset($_GET[$this->query_string]) ? (int) $_GET[$this->query_string] : 1; - - // Insert {page} placeholder - $_GET[$this->query_string] = '{page}'; - - // Create full URL - $base_url = ($this->base_url === '') ? Router::$current_uri : $this->base_url; - $this->url = url::site($base_url).'?'.str_replace('%7Bpage%7D', '{page}', http_build_query($_GET)); - - // Reset page number - $_GET[$this->query_string] = $this->current_page; - } - - // Build generic URL with page as URI segment - else - { - // Use current URI if no base_url set - $this->url = ($this->base_url === '') ? Router::$segments : explode('/', trim($this->base_url, '/')); - - // Convert uri 'label' to corresponding integer if needed - if (is_string($this->uri_segment)) - { - if (($key = array_search($this->uri_segment, $this->url)) === FALSE) - { - // If uri 'label' is not found, auto add it to base_url - $this->url[] = $this->uri_segment; - $this->uri_segment = count($this->url) + 1; - } - else - { - $this->uri_segment = $key + 2; - } - } - - // Insert {page} placeholder - $this->url[$this->uri_segment - 1] = '{page}'; - - // Create full URL - $this->url = url::site(implode('/', $this->url)).Router::$query_string; - - // Extract current page - $this->current_page = URI::instance()->segment($this->uri_segment); - } - - // Core pagination values - $this->total_items = (int) max(0, $this->total_items); - $this->items_per_page = (int) max(1, $this->items_per_page); - $this->total_pages = (int) ceil($this->total_items / $this->items_per_page); - $this->current_page = (int) min(max(1, $this->current_page), max(1, $this->total_pages)); - $this->current_first_item = (int) min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items); - $this->current_last_item = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items); - - // If there is no first/last/previous/next page, relative to the - // current page, value is set to FALSE. Valid page number otherwise. - $this->first_page = ($this->current_page === 1) ? FALSE : 1; - $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages; - $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE; - $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE; - - // SQL values - $this->sql_offset = (int) ($this->current_page - 1) * $this->items_per_page; - $this->sql_limit = sprintf(' LIMIT %d OFFSET %d ', $this->items_per_page, $this->sql_offset); - } - - /** - * Generates the HTML for the chosen pagination style. - * - * @param string pagination style - * @return string pagination html - */ - public function render($style = NULL) - { - // Hide single page pagination - if ($this->auto_hide === TRUE AND $this->total_pages <= 1) - return ''; - - if ($style === NULL) - { - // Use default style - $style = $this->style; - } - - // Return rendered pagination view - return View::factory($this->directory.$style, get_object_vars($this))->render(); - } - - /** - * Magically converts Pagination object to string. - * - * @return string pagination html - */ - public function __toString() - { - return $this->render(); - } - - /** - * Magically gets a pagination variable. - * - * @param string variable key - * @return mixed variable value if the key is found - * @return void if the key is not found - */ - public function __get($key) - { - if (isset($this->$key)) - return $this->$key; - } - - /** - * Adds a secondary interface for accessing properties, e.g. $pagination->total_pages(). - * Note that $pagination->total_pages is the recommended way to access properties. - * - * @param string function name - * @return string - */ - public function __call($func, $args = NULL) - { - return $this->__get($func); - } + // Config values + protected $base_url = ''; + protected $directory = 'pagination'; + protected $style = 'classic'; + protected $uri_segment = 3; + protected $query_string = ''; + protected $items_per_page = 20; + protected $total_items = 0; + protected $auto_hide = FALSE; + + // Autogenerated values + protected $url; + protected $current_page; + protected $total_pages; + protected $current_first_item; + protected $current_last_item; + protected $first_page; + protected $last_page; + protected $previous_page; + protected $next_page; + protected $sql_offset; + protected $sql_limit; + + /** + * Constructs and returns a new Pagination object. + * + * @param array configuration settings + * @return object + */ + public function factory($config = array()) + { + return new Pagination($config); + } + + /** + * Constructs a new Pagination object. + * + * @param array configuration settings + * @return void + */ + public function __construct($config = array()) + { + // No custom group name given + if ( ! isset($config['group'])) + { + $config['group'] = 'default'; + } + + // Pagination setup + $this->initialize($config); + } + + /** + * Sets config values. + * + * @throws Kohana_Exception + * @param array configuration settings + * @return void + */ + public function initialize($config = array()) + { + // Load config group + if (isset($config['group'])) + { + // Load and validate config group + if ( ! is_array($group_config = Kohana::config('pagination.'.$config['group']))) + throw new Kohana_Exception('pagination.undefined_group: ' . $config['group']); + + // All pagination config groups inherit default config group + if ($config['group'] !== 'default') + { + // Load and validate default config group + if ( ! is_array($default_config = Kohana::config('pagination.default'))) + throw new Kohana_Exception('pagination.undefined_group: default'); + + // Merge config group with default config group + $group_config += $default_config; + } + + // Merge custom config items with config group + $config += $group_config; + } + + // Assign config values to the object + foreach ($config as $key => $value) + { + if (property_exists($this, $key)) + { + $this->$key = $value; + } + } + + // Clean view directory + $this->directory = trim($this->directory, '/').'/'; + + // Build generic URL with page in query string + if ($this->query_string !== '') + { + // Extract current page + $this->current_page = isset($_GET[$this->query_string]) ? (int) $_GET[$this->query_string] : 1; + + // Insert {page} placeholder + $_GET[$this->query_string] = '{page}'; + + // Create full URL + $base_url = ($this->base_url === '') ? Router::$current_uri : $this->base_url; + $this->url = url::site($base_url).'?'.str_replace('%7Bpage%7D', '{page}', http_build_query($_GET)); + + // Reset page number + $_GET[$this->query_string] = $this->current_page; + } + + // Build generic URL with page as URI segment + else + { + // Use current URI if no base_url set + $this->url = ($this->base_url === '') ? Router::$segments : explode('/', trim($this->base_url, '/')); + + // Convert uri 'label' to corresponding integer if needed + if (is_string($this->uri_segment)) + { + if (($key = array_search($this->uri_segment, $this->url)) === FALSE) + { + // If uri 'label' is not found, auto add it to base_url + $this->url[] = $this->uri_segment; + $this->uri_segment = count($this->url) + 1; + } + else + { + $this->uri_segment = $key + 2; + } + } + + // Insert {page} placeholder + $this->url[$this->uri_segment - 1] = '{page}'; + + // Create full URL + $this->url = url::site(implode('/', $this->url)).Router::$query_string; + + // Extract current page + $this->current_page = URI::instance()->segment($this->uri_segment); + } + + // Core pagination values + $this->total_items = (int) max(0, $this->total_items); + $this->items_per_page = (int) max(1, $this->items_per_page); + $this->total_pages = (int) ceil($this->total_items / $this->items_per_page); + $this->current_page = (int) min(max(1, $this->current_page), max(1, $this->total_pages)); + $this->current_first_item = (int) min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items); + $this->current_last_item = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items); + + // If there is no first/last/previous/next page, relative to the + // current page, value is set to FALSE. Valid page number otherwise. + $this->first_page = ($this->current_page === 1) ? FALSE : 1; + $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages; + $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE; + $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE; + + // SQL values + $this->sql_offset = (int) ($this->current_page - 1) * $this->items_per_page; + $this->sql_limit = sprintf(' LIMIT %d OFFSET %d ', $this->items_per_page, $this->sql_offset); + } + + /** + * Generates the HTML for the chosen pagination style. + * + * @param string pagination style + * @return string pagination html + */ + public function render($style = NULL) + { + // Hide single page pagination + if ($this->auto_hide === TRUE AND $this->total_pages <= 1) + return ''; + + if ($style === NULL) + { + // Use default style + $style = $this->style; + } + + // Return rendered pagination view + return View::factory($this->directory.$style, get_object_vars($this))->render(); + } + + /** + * Magically converts Pagination object to string. + * + * @return string pagination html + */ + public function __toString() + { + return $this->render(); + } + + /** + * Magically gets a pagination variable. + * + * @param string variable key + * @return mixed variable value if the key is found + * @return void if the key is not found + */ + public function __get($key) + { + if (isset($this->$key)) + return $this->$key; + } + + /** + * Adds a secondary interface for accessing properties, e.g. $pagination->total_pages(). + * Note that $pagination->total_pages is the recommended way to access properties. + * + * @param string function name + * @return string + */ + public function __call($func, $args = NULL) + { + return $this->__get($func); + } } // End Pagination Class \ No newline at end of file -- cgit v1.2.3 From bdd7c68ede05d46ba758b0ab3e04b46202d761af Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 15:41:47 -0800 Subject: Fix some function definitions (they should be static) --- modules/gallery_unit_test/helpers/MY_request.php | 2 +- modules/gallery_unit_test/helpers/diff.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery_unit_test/helpers/MY_request.php b/modules/gallery_unit_test/helpers/MY_request.php index 9cc9746a..452fb0cc 100644 --- a/modules/gallery_unit_test/helpers/MY_request.php +++ b/modules/gallery_unit_test/helpers/MY_request.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class request extends request_Core { - public function set_user_agent($value) { + static function set_user_agent($value) { self::$user_agent = null; $_SERVER["HTTP_USER_AGENT"] = $value; } diff --git a/modules/gallery_unit_test/helpers/diff.php b/modules/gallery_unit_test/helpers/diff.php index 1ea16fa6..7b573732 100644 --- a/modules/gallery_unit_test/helpers/diff.php +++ b/modules/gallery_unit_test/helpers/diff.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class diff_Core { - public function compare($a, $b) { + static function compare($a, $b) { fwrite(fopen($a_name = tempnam("/tmp", "test"), "w"), $a); fwrite(fopen($b_name = tempnam("/tmp", "test"), "w"), $b); return `diff $a_name $b_name`; -- cgit v1.2.3 From 71e154b6748a2bedd2289133c6b4c6f3f58d3603 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:13:08 -0800 Subject: Use a Database_Expression to handle the MAX() function. --- modules/gallery/tests/Gallery_Installer_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php index f36f638f..43399fb4 100644 --- a/modules/gallery/tests/Gallery_Installer_Test.php +++ b/modules/gallery/tests/Gallery_Installer_Test.php @@ -35,7 +35,7 @@ class Gallery_Installer_Test extends Unit_Test_Case { public function install_creates_root_item_test() { $max_right_ptr = ORM::factory("item") - ->select("MAX(`right_ptr`) AS `right_ptr`") + ->select(new Database_Expression("MAX(`right_ptr`) AS `right_ptr`")) ->find()->right_ptr; $root = ORM::factory('item')->find(1); $this->assert_equal("Gallery", $root->title); -- cgit v1.2.3 From a6da027aad5072a85719fc9e201ee946963e74f0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:22:24 -0800 Subject: The default value for $offset should always be null (according to the new K24 ORM). Fix up a bad where tuple in the test. --- modules/gallery/libraries/ORM_MPTT.php | 2 +- modules/gallery/models/item.php | 2 +- modules/gallery/tests/ORM_MPTT_Test.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 949ca48c..0ea519c9 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -201,7 +201,7 @@ class ORM_MPTT_Core extends ORM { * @param array order_by * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) { + function descendants($limit=null, $offset=null, $where=null, $order_by=array("id" => "ASC")) { if ($where) { $this->merge_where($where); } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index e2208b73..e3d27b6d 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -634,7 +634,7 @@ class Item_Model extends ORM_MPTT { * @param array additional where clauses * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $where=array(), $order_by=null) { + function descendants($limit=null, $offset=null, $where=array(), $order_by=null) { if (empty($order_by)) { $order_by = array($this->sort_column => $this->sort_order); // Use id as a tie breaker diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 36a81d2c..69b6bea9 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -190,8 +190,8 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent->reload(); $this->assert_equal(3, $parent->descendants()->count()); - $this->assert_equal(2, $parent->descendants(null, 0, array("type" => "photo"))->count()); - $this->assert_equal(1, $parent->descendants(null, 0, array("type" => "album"))->count()); + $this->assert_equal(2, $parent->descendants(null, null, array(array("type", "=", "photo")))->count()); + $this->assert_equal(1, $parent->descendants(null, null, array(array("type", "=", "album")))->count()); } public function descendant_limit_test() { -- cgit v1.2.3 From 6601bb29d90ebe0b6f6df0b27616d2804783e447 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:25:31 -0800 Subject: Update. --- modules/gallery/tests/xss_data.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 3708bc6d..5a15d2ac 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -121,6 +121,7 @@ modules/gallery/views/admin_themes_preview.html.php 7 DIRTY_ATTR $url modules/gallery/views/form_uploadify.html.php 20 DIRTY_JS url::file("lib/uploadify/uploadify.swf") modules/gallery/views/form_uploadify.html.php 21 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") modules/gallery/views/form_uploadify.html.php 25 DIRTY_JS url::file("lib/uploadify/cancel.png") +modules/gallery/views/form_uploadify.html.php 27 DIRTY_JS $simultaneous_upload_limit modules/gallery/views/form_uploadify.html.php 52 DIRTY_JS t("Completed") modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form"),$hidden) modules/gallery/views/in_place_edit.html.php 5 DIRTY form::input("input",$form["input"]," class=\"textbox\"") @@ -274,11 +275,11 @@ modules/rss/views/feed.mrss.php 55 DIRTY_ATTR @fil modules/rss/views/feed.mrss.php 56 DIRTY_ATTR $child->mime_type modules/rss/views/feed.mrss.php 57 DIRTY_ATTR $child->resize_height modules/rss/views/feed.mrss.php 58 DIRTY_ATTR $child->resize_width -modules/rss/views/feed.mrss.php 62 DIRTY_ATTR $child->file_url(true) -modules/rss/views/feed.mrss.php 63 DIRTY_ATTR @filesize($child->file_path()) -modules/rss/views/feed.mrss.php 64 DIRTY_ATTR $child->mime_type -modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->height -modules/rss/views/feed.mrss.php 66 DIRTY_ATTR $child->width +modules/rss/views/feed.mrss.php 61 DIRTY_ATTR $child->file_url(true) +modules/rss/views/feed.mrss.php 62 DIRTY_ATTR @filesize($child->file_path()) +modules/rss/views/feed.mrss.php 63 DIRTY_ATTR $child->mime_type +modules/rss/views/feed.mrss.php 64 DIRTY_ATTR $child->height +modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->width modules/rss/views/feed.mrss.php 70 DIRTY_ATTR $child->file_url(true) modules/rss/views/feed.mrss.php 71 DIRTY_ATTR @filesize($child->file_path()) modules/rss/views/feed.mrss.php 72 DIRTY_ATTR $child->height -- cgit v1.2.3 From 0bc92614d37e08ab5f85c83cf4317132d4c6b99c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:48:18 -0800 Subject: Checkpoint --- modules/gallery/tests/controller_auth_data.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 1fe29ffb..044a8f22 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -3,7 +3,8 @@ modules/comment/helpers/comment_rss.php feed modules/digibug/controllers/digibug.php print_proxy DIRTY_CSRF|DIRTY_AUTH modules/digibug/controllers/digibug.php close_window DIRTY_AUTH modules/gallery/controllers/admin.php __call DIRTY_AUTH -modules/gallery/controllers/albums.php _show DIRTY_CSRF +modules/gallery/controllers/albums.php index DIRTY_AUTH +modules/gallery/controllers/albums.php show DIRTY_CSRF modules/gallery/controllers/combined.php javascript DIRTY_AUTH modules/gallery/controllers/combined.php css DIRTY_AUTH modules/gallery/controllers/file_proxy.php __call DIRTY_CSRF|DIRTY_AUTH -- cgit v1.2.3 From 63fd9622c06e97e67e6dd11db00b12157924e6b8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 16:50:15 -0800 Subject: Don't use as_array() on the result from db::build()->execute() -- it's no longer necessary. --- modules/gallery/libraries/Gallery_I18n.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php index 9a5e7dc1..4e0c1f82 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -132,8 +132,7 @@ class Gallery_I18n_Core { ->select("key", "translation") ->from("incoming_translations") ->where("locale", "=", $locale) - ->execute() - ->as_array() as $row) { + ->execute() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); } @@ -142,8 +141,7 @@ class Gallery_I18n_Core { ->select("key", "translation") ->from("outgoing_translations") ->where("locale", "=", $locale) - ->execute() - ->as_array() as $row) { + ->execute() as $row) { $this->_cache[$locale][$row->key] = unserialize($row->translation); } } -- cgit v1.2.3 From ffca63235a53e8005d2f163efd97dbf69f8a1442 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 22 Dec 2009 21:18:31 -0800 Subject: Fix where tuple sent to descendant_counts() -- it needs to be wrapped in an array --- modules/gallery/helpers/gallery_rss.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 4aef27ad..d422636f 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -51,7 +51,7 @@ class gallery_rss_Core { ->viewable() ->descendants($limit, $offset, array(array("type", "=", "photo"))); $feed->max_pages = ceil( - $item->viewable()->descendants_count(array("type", "=", "photo")) / $limit); + $item->viewable()->descendants_count(array(array("type", "=", "photo"))) / $limit); $feed->title = html::purify($item->title); $feed->description = nl2br(html::purify($item->description)); -- cgit v1.2.3 From eb047d7f5deff499ce71fe720058b335f4868fe3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 23 Dec 2009 13:31:52 -0800 Subject: ORM relations now require you to do find_all() or count_all() to get the results. --- modules/user/views/admin_users_group.html.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/user/views/admin_users_group.html.php b/modules/user/views/admin_users_group.html.php index b7e573b3..6c6c341e 100644 --- a/modules/user/views/admin_users_group.html.php +++ b/modules/user/views/admin_users_group.html.php @@ -13,9 +13,9 @@ -users->count() > 0): ?> +users->count_all() > 0): ?>
                - users as $i => $user): ?> + users->find_all() as $i => $user): ?>
              • name) ?> special): ?> -- cgit v1.2.3 From 29f982679d775dc981544b06da64970dee9e6e47 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 23 Dec 2009 20:36:38 -0800 Subject: First shot at integrating the K24 error page. --- modules/gallery/views/kohana/error.php | 257 +++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 modules/gallery/views/kohana/error.php (limited to 'modules') diff --git a/modules/gallery/views/kohana/error.php b/modules/gallery/views/kohana/error.php new file mode 100644 index 00000000..f973f5b9 --- /dev/null +++ b/modules/gallery/views/kohana/error.php @@ -0,0 +1,257 @@ + + + + + + + <?= t("Something went wrong!") ?> + + + + + + admin ?> +
                +

                + +

                +

                + +

                + +

                + +

                + +
                + +
                +

                + +

                +
                +

                + + [ ]: + + + + +

                +
                +
                +

                + + [ ] + +

                + + $row): ?>"> + +
                + + +
                  + $step): ?> +
                1. +

                  + + + + [ ] + + [ ] + + + {} + + + » + ( + + ) +

                  + + + + + + +
                2. + + +
                + + +
                +

                + " onclick="return koggle('')"> +

                + +
                +
                + + + -- cgit v1.2.3 From b62083bd24b7e5fa079726dc0819fb646c31192b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 23 Dec 2009 20:48:50 -0800 Subject: Cleaner version. Probably has a bunch of cruft in it, but it looks good enough. --- modules/gallery/views/kohana/error.php | 78 ++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 28 deletions(-) (limited to 'modules') diff --git a/modules/gallery/views/kohana/error.php b/modules/gallery/views/kohana/error.php index f973f5b9..7c4a959c 100644 --- a/modules/gallery/views/kohana/error.php +++ b/modules/gallery/views/kohana/error.php @@ -72,8 +72,34 @@ padding-bottom: 10px; } - #first_error { - padding-left: 20px; + .source { + border: solid 1px #ccc; + background: #efe; + margin-bottom: 5px; + } + + table { + width: 100%; + display: block; + margin: 0 0 0.4em; + padding: 0; + border-collapse: collapse; + background: #efe; + } + + table td { + border: solid 1px #ddd; + text-align: left; + vertical-align: top; + padding: 0.4em; + } + + .args table td.key { + width: 200px; + } + + .number { + padding-right: 1em; } @@ -134,21 +160,23 @@
                -
                -

                - - [ ] - -

                +
                  +
                1. +

                  + + [ ] + +

                  - $row): ?>"> - -
                +
                + $row): ?>"> + +
                +
              • - -
                  + $step): ?> -
                1. +
                2. @@ -171,12 +199,10 @@ $arg): ?> - - @@ -185,7 +211,7 @@ - + @@ -205,9 +231,7 @@ @@ -220,9 +244,7 @@ @@ -236,12 +258,12 @@
                  - - - + +
                  +
                  - - - +
                  - - - +
                  $value): ?> - - -- cgit v1.2.3 From 057e8d09afaecd27f672f804a6a65341578d50fd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 23 Dec 2009 20:51:33 -0800 Subject: Convert a bunch of leftover kohana::show_404 calls to throw Kohana_404_Exception instead. These are the ones where we used a lower-case 'k' so my previous filter didn't catch it. --- modules/digibug/controllers/digibug.php | 2 +- modules/gallery/controllers/admin.php | 2 +- modules/gallery/controllers/file_proxy.php | 16 ++++++++-------- modules/tag/controllers/admin_tags.php | 4 ++-- modules/user/controllers/admin_users.php | 16 ++++++++-------- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'modules') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index a23d2863..6e6009db 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -87,7 +87,7 @@ class Digibug_Controller extends Controller { $file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path(); if (!file_exists($file)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // We don't need to save the session for this request diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 98cac557..e4216991 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -44,7 +44,7 @@ class Admin_Controller extends Controller { } if (!method_exists($controller_name, $method)) { - return kohana::show_404(); + throw new Kohana_404_Exception(); } call_user_func_array(array(new $controller_name, $method), $args); diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index 6a80ad85..65c0cb50 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -38,19 +38,19 @@ class File_Proxy_Controller extends Controller { // Make sure that the request is for a file inside var $offset = strpos($request_uri, $var_uri); if ($offset === false) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $file_uri = substr($request_uri, strlen($var_uri)); // Make sure that we don't leave the var dir if (strpos($file_uri, "..") !== false) { - kohana::show_404(); + throw new Kohana_404_Exception(); } list ($type, $path) = explode("/", $file_uri, 2); if ($type != "resizes" && $type != "albums" && $type != "thumbs") { - kohana::show_404(); + throw new Kohana_404_Exception(); } // If the last element is .album.jpg, pop that off since it's not a real item @@ -78,7 +78,7 @@ class File_Proxy_Controller extends Controller { } if (!$item->loaded()) { - kohana::show_404(); + throw new Kohana_404_Exception(); } if ($type == "albums") { @@ -91,21 +91,21 @@ class File_Proxy_Controller extends Controller { // Make sure we have access to the item if (!access::can("view", $item)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // Make sure we have view_full access to the original if ($type == "albums" && !access::can("view_full", $item)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // Don't try to load a directory if ($type == "albums" && $item->is_album()) { - kohana::show_404(); + throw new Kohana_404_Exception(); } if (!file_exists($file)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // We don't need to save the session for this request diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index a56d4d20..e20b8ac8 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -45,7 +45,7 @@ class Admin_Tags_Controller extends Admin_Controller { $tag = ORM::factory("tag", $id); if (!$tag->loaded()) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $form = tag::get_delete_form($tag); @@ -80,7 +80,7 @@ class Admin_Tags_Controller extends Admin_Controller { $tag = ORM::factory("tag", $id); if (!$tag->loaded()) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $in_place_edit = InPlaceEdit::factory($tag->name) diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index ee65efd2..96b86fff 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -77,7 +77,7 @@ class Admin_Users_Controller extends Admin_Controller { $user = user::lookup($id); if (empty($user)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $form = $this->_get_user_delete_form_admin($user); @@ -98,7 +98,7 @@ class Admin_Users_Controller extends Admin_Controller { public function delete_user_form($id) { $user = user::lookup($id); if (empty($user)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } print $this->_get_user_delete_form_admin($user); } @@ -108,7 +108,7 @@ class Admin_Users_Controller extends Admin_Controller { $user = user::lookup($id); if (empty($user)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $form = $this->_get_user_edit_form_admin($user); @@ -155,7 +155,7 @@ class Admin_Users_Controller extends Admin_Controller { public function edit_user_form($id) { $user = user::lookup($id); if (empty($user)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $v = new View("user_form.html"); @@ -224,7 +224,7 @@ class Admin_Users_Controller extends Admin_Controller { $group = group::lookup($id); if (empty($group)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $form = $this->_get_group_delete_form_admin($group); @@ -245,7 +245,7 @@ class Admin_Users_Controller extends Admin_Controller { public function delete_group_form($id) { $group = group::lookup($id); if (empty($group)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } print $this->_get_group_delete_form_admin($group); @@ -256,7 +256,7 @@ class Admin_Users_Controller extends Admin_Controller { $group = group::lookup($id); if (empty($group)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $form = $this->_get_group_edit_form_admin($group); @@ -288,7 +288,7 @@ class Admin_Users_Controller extends Admin_Controller { public function edit_group_form($id) { $group = group::lookup($id); if (empty($group)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } print $this->_get_group_edit_form_admin($group); -- cgit v1.2.3 From b16ab9d94af3b463c3f3497c0b4cb57416349a27 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 24 Dec 2009 03:08:06 -0800 Subject: Don't treat objects like strings. --- modules/g2_import/helpers/g2_import.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 3cf7eb80..a7a69746 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -611,11 +611,9 @@ class g2_import_Core { array("id" => $g2_item_id, "exception" => $e->__toString())); } - $tags = ""; // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { - $tags .= (strlen($tags) ? ", " : "") . - tag::add($g3_item, $tag_name); + tag::add($g3_item, $tag_name); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't @@ -634,11 +632,10 @@ class g2_import_Core { $delim = " "; } - $tags = ""; foreach (preg_split("/$delim/", $keywords) as $keyword) { $keyword = trim($keyword); if ($keyword) { - $tags .= (strlen($tags) ? ", " : "") . tag::add($item, $keyword); + tag::add($item, $keyword); } } } -- cgit v1.2.3 From 24ef52eccbe854688d61a798ee79d64f24f63ac1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 24 Dec 2009 18:06:26 -0800 Subject: whitespace fix --- modules/gallery/helpers/gallery_block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 40660874..1db7585c 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -34,7 +34,7 @@ class gallery_block_Core { static function get($block_id) { $block = new Block(); - switch($block_id) { + switch ($block_id) { case "welcome": $block->css_id = "g-welcome"; $block->title = t("Welcome to Gallery 3"); -- cgit v1.2.3 From 73aeed890263386a0cd44b210ddf360dc6613843 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 24 Dec 2009 20:08:04 -0800 Subject: indentation fix. --- modules/gallery/helpers/gallery_block.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 1db7585c..9d4e81b6 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -101,8 +101,7 @@ class gallery_block_Core { $block->css_id = "g-user-language-block"; $block->title = t("Language preference"); $block->content = new View("user_languages_block.html"); - $block->content->installed_locales = - array_merge(array("" => t("« none »")), $locales); + $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); $block->content->selected = (string) locales::cookie_locale(); } else { $block = ""; -- cgit v1.2.3 From c50c2d135c5e769e8904e5dc766d27bcd4a1d8b3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 25 Dec 2009 12:39:09 -0800 Subject: Fix uses of count_records() and use ORM to count instead. --- modules/server_add/controllers/server_add.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 77487673..6ff00812 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -175,15 +175,15 @@ class Server_Add_Controller extends Admin_Controller { // over 10% in percent_complete. $task->set("queue", $queue); $task->percent_complete = min($task->percent_complete + 0.1, 10); - $task->status = t2("Found one file", "Found %count files", - db::build()->count_records( - "server_add_files", array("task_id" => $task->id))); + $task->status = t2( + "Found one file", "Found %count files", + ORM::factory("server_add_file")->where("task_id", "=", $task->id)->count_all()); if (!$queue) { $task->set("mode", "add-files"); $task->set( - "total_files", db::build()->count_records( - "server_add_files", array("task_id" => $task->id))); + "total_files", + ORM::factory("server_add_file")->where("task_id", "=", $task->id)->count_all()); $task->percent_complete = 10; } break; @@ -256,7 +256,7 @@ class Server_Add_Controller extends Admin_Controller { $task->status = t("Adding photos / albums (%completed of %total)", array("completed" => $completed_files, "total" => $total_files)); - $task->percent_complete = 10 + 100 * ($completed_files / $total_files); + $task->percent_complete = $total_files ? 10 + 100 * ($completed_files / $total_files) : 100; break; case "done": -- cgit v1.2.3 From 07a9ef2276a421fe3b8ebad4c4ff845b147be847 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 25 Dec 2009 13:24:38 -0800 Subject: Convert some database calls --- modules/organize/controllers/organize.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 03dea13d..201ced30 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -75,7 +75,11 @@ class Organize_Controller extends Controller { $i = 0; foreach ($album->children() as $child) { // Do this directly in the database to avoid sending notifications - Database::Instance()->update("items", array("weight" => ++$i), array("id" => $child->id)); + db::build() + ->update("items") + ->set("weight", ++$i) + ->where("id", "=", $child->id) + ->execute(); } $album->sort_column = "weight"; $album->sort_order = "ASC"; @@ -91,15 +95,20 @@ class Organize_Controller extends Controller { // Make a hole $count = count($source_ids); - Database::Instance()->query( - "UPDATE {items} " . - "SET `weight` = `weight` + $count " . - "WHERE `weight` >= $target_weight AND `parent_id` = {$album->id}"); + db::build() + ->update("items") + ->set("weight", new Database_Expression("`weight` + $count")) + ->where("weight", ">=", $target_weight) + ->where("parent_id", "=", $album->id) + ->execute(); // Insert source items into the hole foreach ($source_ids as $source_id) { - Database::Instance()->update( - "items", array("weight" => $target_weight++), array("id" => $source_id)); + db::build() + ->update("items") + ->set("weight", $target_weight++) + ->where("id", "=", $source_id) + ->execute(); } module::event("album_rearrange", $album); -- cgit v1.2.3 From da7ee6ab30d8f2545781910d7ef1f573c5dfee93 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 25 Dec 2009 13:24:47 -0800 Subject: Fix over-targetting in CSS --- modules/organize/js/organize.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index a7fe1ad2..afa9e17a 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -149,7 +149,7 @@ window.location.reload(); }); - $("#g-dialog #g-organize-close").click(function(event) { + $("#g-organize-close").click(function(event) { $("#g-dialog").dialog("close"); }); -- cgit v1.2.3
                  + +