From be1a87314916f11e074a0a63726320c84cedaf65 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 9 Apr 2011 16:07:40 +0000 Subject: Refs #3241 sorting upgrades so that upgrades from old upgrade system are ordered in datalist array git-svn-id: http://code.elgg.org/elgg/trunk@8966 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/upgrade.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/upgrade.php b/engine/lib/upgrade.php index 755c100dd..85810956b 100644 --- a/engine/lib/upgrade.php +++ b/engine/lib/upgrade.php @@ -147,6 +147,8 @@ function elgg_get_upgrade_files($upgrade_path = null) { $upgrade_files[] = $upgrade_file; } + sort($upgrade_files); + return $upgrade_files; } -- cgit v1.2.3 From 472b45795825eb65f68c8835e8f7daeb82598741 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 9 Apr 2011 17:14:14 +0000 Subject: Fixes #3224 Fixes #3241 stopping upgrade after plugin upgrade and restarting git-svn-id: http://code.elgg.org/elgg/trunk@8969 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/upgrades/2011010101.php | 18 ++++++++++++++++++ ...00-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php | 3 +++ 2 files changed, 21 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/upgrades/2011010101.php b/engine/lib/upgrades/2011010101.php index be1adac1a..9dbaff1e4 100644 --- a/engine/lib/upgrades/2011010101.php +++ b/engine/lib/upgrades/2011010101.php @@ -73,3 +73,21 @@ remove_metadata($site->guid, 'pluginorder'); remove_metadata($site->guid, 'enabled_plugins'); elgg_set_ignore_access($old_id); + +/** + * @hack + * + * We stop the upgrade at this point because plugins weren't given the chance to + * load due to the new plugin code introduced with Elgg 1.8. Instead, we manually + * set the version and start the upgrade process again. + * + * The variables from upgrade_code() are available because this script was included + */ +if ($upgrade_version > $version) { + datalist_set('version', $upgrade_version); +} + +$processed_upgrades = array_unique($processed_upgrades); +datalist_set('processed_upgrades', serialize($processed_upgrades)); + +forward('upgrade.php'); diff --git a/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php b/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php index 592adb403..7efa687ae 100644 --- a/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php +++ b/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php @@ -11,3 +11,6 @@ foreach ($admins as $admin) { // call the admin handler for the make_admin event elgg_add_admin_widgets('make_admin', 'user', $admin); } + +// as last upgrade for 1.8.0 (or nearly so) we add a reminder to update .htaccess +system_message("IMPORTANT: update your .htaccess file (or equivalent)"); -- cgit v1.2.3 From cab1ccee2adc382151ce89674498a93addb89b34 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 9 Apr 2011 19:14:38 +0000 Subject: Fixes #3193 moves default widgets upgrade to an action git-svn-id: http://code.elgg.org/elgg/trunk@8971 36083f99-b078-4883-b0ff-0f9b5a30f544 --- actions/widgets/upgrade.php | 65 ++++++++++++++++++++++ ...svn-update_default_widgets-7daf5a459720d06d.php | 60 -------------------- engine/lib/widgets.php | 1 + languages/en.php | 1 + views/default/admin/appearance/default_widgets.php | 16 ++++++ 5 files changed, 83 insertions(+), 60 deletions(-) create mode 100644 actions/widgets/upgrade.php delete mode 100644 engine/lib/upgrades/2011032300-1.8_svn-update_default_widgets-7daf5a459720d06d.php (limited to 'engine/lib') diff --git a/actions/widgets/upgrade.php b/actions/widgets/upgrade.php new file mode 100644 index 000000000..0a5cf8d48 --- /dev/null +++ b/actions/widgets/upgrade.php @@ -0,0 +1,65 @@ + 'object', + 'subtype' => 'moddefaultwidgets', + 'limit' => 1, +)); + +if (!$object) { + forward(REFERER); +} + +$object = $object[0]; + +$site = elgg_get_site_entity(); + +$ia = elgg_set_ignore_access(true); +foreach (array('profile', 'dashboard') as $context) { + if (isset($object->$context)) { + elgg_push_context($context); + elgg_push_context('default_widgets'); + elgg_push_context('widgets'); + + // deserialize the widget information + list($left, $middle, $right) = split('%%', $object->$context); + $left_widgets = split('::', $left); + $middle_widgets = split('::', $middle); + $right_widgets = split('::', $right); + + // 1st column is right column in default theme + $widgets = array( + 1 => array_reverse($right_widgets), + 2 => array_reverse($middle_widgets), + 3 => array_reverse($left_widgets), + ); + + foreach ($widgets as $column => $column_widgets) { + foreach ($column_widgets as $handler) { + $guid = elgg_create_widget($site->getGUID(), $handler, $context); + if ($guid) { + $widget = get_entity($guid); + $widget->move($column, 0); + } + } + } + + elgg_pop_context(); + elgg_pop_context(); + elgg_pop_context(); + } +} +elgg_set_ignore_access($ia); + +$object->delete(); +system_message(elgg_echo('upgrade:core')); +forward(REFERER); diff --git a/engine/lib/upgrades/2011032300-1.8_svn-update_default_widgets-7daf5a459720d06d.php b/engine/lib/upgrades/2011032300-1.8_svn-update_default_widgets-7daf5a459720d06d.php deleted file mode 100644 index 6a5f2fa02..000000000 --- a/engine/lib/upgrades/2011032300-1.8_svn-update_default_widgets-7daf5a459720d06d.php +++ /dev/null @@ -1,60 +0,0 @@ - 'object', - 'subtype' => 'moddefaultwidgets', - 'limit' => 1, -)); - -if (!$object) { - // nothing to upgrade - return true; -} - -$object = $object[0]; - -$site = elgg_get_site_entity(); - -$ia = elgg_set_ignore_access(true); -foreach (array('profile', 'dashboard') as $context) { - if (isset($object->$context)) { - elgg_push_context($context); - elgg_push_context('default_widgets'); - elgg_push_context('widgets'); - - // deserialize the widget information - list($left, $middle, $right) = split('%%', $object->$context); - $left_widgets = split('::', $left); - $middle_widgets = split('::', $middle); - $right_widgets = split('::', $right); - - // 1st column is right column in default theme - $widgets = array( - 1 => array_reverse($right_widgets), - 2 => array_reverse($middle_widgets), - 3 => array_reverse($left_widgets), - ); - - foreach ($widgets as $column => $column_widgets) { - foreach ($column_widgets as $handler) { - $guid = elgg_create_widget($site->getGUID(), $handler, $context); - if ($guid) { - $widget = get_entity($guid); - $widget->move($column, 0); - } - } - } - - elgg_pop_context(); - elgg_pop_context(); - elgg_pop_context(); - } -} -elgg_set_ignore_access($ia); diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php index b20f92f74..cc3cf20e4 100644 --- a/engine/lib/widgets.php +++ b/engine/lib/widgets.php @@ -272,6 +272,7 @@ function elgg_widgets_init() { elgg_register_action('widgets/add'); elgg_register_action('widgets/move'); elgg_register_action('widgets/delete'); + elgg_register_action('widgets/upgrade', '', 'admin'); run_function_once("elgg_widget_run_once"); } diff --git a/languages/en.php b/languages/en.php index 427452aa9..86fa9c7e7 100644 --- a/languages/en.php +++ b/languages/en.php @@ -795,6 +795,7 @@ $english = array( 'post' => 'Post', 'submit' => 'Submit', 'comment' => 'Comment', + 'upgrade' => 'Upgrade', 'site' => 'Site', 'activity' => 'Activity', diff --git a/views/default/admin/appearance/default_widgets.php b/views/default/admin/appearance/default_widgets.php index ce9f6a5c2..5ce0d0acf 100644 --- a/views/default/admin/appearance/default_widgets.php +++ b/views/default/admin/appearance/default_widgets.php @@ -6,6 +6,22 @@ * @subpackage Administration.DefaultWidgets */ +$object = elgg_get_entities(array( + 'type' => 'object', + 'subtype' => 'moddefaultwidgets', + 'limit' => 1, +)); + +if ($object) { + echo elgg_view('output/url', array( + 'text' => elgg_echo('upgrade'), + 'href' => 'action/widgets/upgrade', + 'is_action' => true, + 'class' => 'elgg_button elgg-button-submit', + 'title' => 'Upgrade your default widgets to work on Elgg 1.8', + )); +} + elgg_push_context('default_widgets'); $widget_context = get_input('widget_context'); $list = elgg_trigger_plugin_hook('get_list', 'default_widgets', null, array()); -- cgit v1.2.3 From 20c4b5112b823a0b65bf1bf1a5f0bc83e7321e59 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 9 Apr 2011 19:58:35 +0000 Subject: Reopens #3224 not as clever as I thought - user experiences error before seeing reminder git-svn-id: http://code.elgg.org/elgg/trunk@8974 36083f99-b078-4883-b0ff-0f9b5a30f544 --- .../2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php b/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php index 7efa687ae..592adb403 100644 --- a/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php +++ b/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php @@ -11,6 +11,3 @@ foreach ($admins as $admin) { // call the admin handler for the make_admin event elgg_add_admin_widgets('make_admin', 'user', $admin); } - -// as last upgrade for 1.8.0 (or nearly so) we add a reminder to update .htaccess -system_message("IMPORTANT: update your .htaccess file (or equivalent)"); -- cgit v1.2.3 From 37881edcff91abd6426b72efaf07c73bd8f80bb1 Mon Sep 17 00:00:00 2001 From: cash Date: Mon, 11 Apr 2011 12:00:35 +0000 Subject: Fixes #3327 fixed typo git-svn-id: http://code.elgg.org/elgg/trunk@8982 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/output.php b/engine/lib/output.php index 8c2a3d50d..3f35a1576 100644 --- a/engine/lib/output.php +++ b/engine/lib/output.php @@ -170,7 +170,7 @@ function elgg_format_attributes(array $attrs) { } // ignore $vars['entity'] => ElggEntity stuff - if (is_not_null($val) && (is_array($val) || !is_object($var))) { + if (is_not_null($val) && (is_array($val) || !is_object($val))) { // allow $vars['class'] => array('one', 'two'); // @todo what about $vars['style']? Needs to be semi-colon separated... -- cgit v1.2.3 From bffcde9dfe570af9cd1c2315e31f13d6d0ebec8e Mon Sep 17 00:00:00 2001 From: cash Date: Tue, 12 Apr 2011 22:24:48 +0000 Subject: Fixes #3347 fixes comment typo for ege git-svn-id: http://code.elgg.org/elgg/trunk@8984 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 742630cc7..685c68a5b 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -740,7 +740,7 @@ function elgg_entity_exists($guid) { * type_subtype_pairs => NULL|ARR (array('type' => 'subtype')) * (type = '$type' AND subtype = '$subtype') pairs * - * entity_guids => NULL|ARR Array of entity guids + * guids => NULL|ARR Array of entity guids * * owner_guids => NULL|ARR Array of owner guids * -- cgit v1.2.3 From 388d8405bb10b3b2107629f8cd4133bff3a7693c Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 13 Apr 2011 14:39:21 +0000 Subject: Consolidated the css and js pagehandlers with elgg_cachable_view_pagehandler() and fixed for URLs with multiple dots after the last / (like /js/calendars/fullcalendar.min.123456789.js) git-svn-id: http://code.elgg.org/elgg/trunk@8985 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 76 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 23 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 1aef48ef4..063e25fc4 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1685,21 +1685,7 @@ function _elgg_shutdown_hook() { * @elgg_pagehandler js */ function elgg_js_page_handler($page) { - if (is_array($page) && sizeof($page)) { - $js = implode('/', $page); - $js = substr($js, 0, strpos($js, '.')); - $return = elgg_view('js/' . $js); - - header('Content-type: text/javascript'); - - // @todo should js be cached when simple cache turned off - //header('Expires: ' . date('r', time() + 864000)); - //header("Pragma: public"); - //header("Cache-Control: public"); - //header("Content-Length: " . strlen($return)); - - echo $return; - } + return elgg_cacheable_view_page_handler($page, 'js'); } /** @@ -1749,18 +1735,62 @@ function elgg_css_page_handler($page) { // default css $page[0] = 'elgg'; } + + return elgg_cacheable_view_page_handler($page, 'css'); +} + +/** + * Serves a JS or CSS view with headers for caching. + * + * //name/of/view.. + * + * @param array $page The page array + * @param string $type The type: js or css + * + * @return mixed + */ +function elgg_cacheable_view_page_handler($page, $type) { + + switch ($type) { + case 'js': + $content_type = 'text/javascript'; + break; + + case 'css': + $content_type = 'text/css'; + break; + + default: + return false; + break; + } + + if ($page) { + // the view file names can have multiple dots + // eg: views/default/js/calendars/jquery.fullcalendar.min.php + // translates to the url /js/calendars/jquery.fullcalendar.min..js + // and the view js/calendars/jquery.fullcalendar.min + // we ignore the last two dots for the ts and the ext. + $last_part = array_pop($page); + $last_part_bits = explode('.', $last_part); + $last_part_bits = array_slice($last_part_bits, 0, -2); + $page[] = implode('.', $last_part_bits); - $css = substr($page[0], 0, strpos($page[0], '.')); - $return = elgg_view("css/$css"); + $view = implode('/', $page); + $return = elgg_view("$type/$view"); + + header("Content-type: $content_type"); - header("Content-type: text/css", true); + // @todo should js be cached when simple cache turned off + //header('Expires: ' . date('r', time() + 864000)); + //header("Pragma: public"); + //header("Cache-Control: public"); + //header("Content-Length: " . strlen($return)); - // @todo should css be cached when simple cache is turned off - //header('Expires: ' . date('r', time() + 86400000), true); - //header("Pragma: public", true); - //header("Cache-Control: public", true); + echo $return; + } - echo $return; + return true; } /** -- cgit v1.2.3 From d87b6ffe7312888d109428e6a939f33394549677 Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 13 Apr 2011 19:30:44 +0000 Subject: Fixes #3331. Changed cache schema to allow for JS/CSS views with slashes and dots. git-svn-id: http://code.elgg.org/elgg/trunk@8986 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/handlers/cache_handler.php | 15 +++++++++------ engine/lib/cache.php | 2 +- engine/lib/elgglib.php | 10 ++++------ 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'engine/lib') diff --git a/engine/handlers/cache_handler.php b/engine/handlers/cache_handler.php index 05c35171b..7d6f42dc3 100644 --- a/engine/handlers/cache_handler.php +++ b/engine/handlers/cache_handler.php @@ -3,7 +3,7 @@ * Cache handler. * * External access to cached CSS and JavaScript views. The cached file URLS - * should be of the form: cache//// where + * should be of the form: cache///.. where * type is either css or js, view is the name of the cached view, and * unique_id is an identifier that is updated every time the cache is flushed. * The simplest way to maintain a unique identifier is to use the lastcache @@ -50,13 +50,16 @@ if (!$request || !$simplecache_enabled) { echo 'Cache error: bad request'; exit; } -$request = explode('/', $request); +// testing showed regex to be marginally faster than array / string functions over 100000 reps +// it won't make a difference in real life and regex is easier to read. +// //.. +$regex = '|([^/]+)/([^/]+)/(.+)\.([^\.]+)\.([^.]+)$|'; +preg_match($regex, $request, $matches); -//cache//// -$type = $request[0]; -$view = $request[1]; -$viewtype = $request[2]; +$type = $matches[1]; +$viewtype = $matches[2]; +$view = $matches[3]; switch ($type) { case 'css': diff --git a/engine/lib/cache.php b/engine/lib/cache.php index d4888f9d9..8529ae7fa 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -166,7 +166,7 @@ function elgg_get_simplecache_url($type, $view) { if (elgg_is_simplecache_enabled()) { $viewtype = elgg_get_viewtype(); - $url = elgg_get_site_url() . "cache/$type/$view/$viewtype/$view.$lastcache.$type"; + $url = elgg_get_site_url() . "cache/$type/$viewtype/$view.$lastcache.$type"; } else { $url = elgg_get_site_url() . "$type/$view.$lastcache.$type"; } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 063e25fc4..a800aca7a 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1771,12 +1771,10 @@ function elgg_cacheable_view_page_handler($page, $type) { // translates to the url /js/calendars/jquery.fullcalendar.min..js // and the view js/calendars/jquery.fullcalendar.min // we ignore the last two dots for the ts and the ext. - $last_part = array_pop($page); - $last_part_bits = explode('.', $last_part); - $last_part_bits = array_slice($last_part_bits, 0, -2); - $page[] = implode('.', $last_part_bits); - - $view = implode('/', $page); + $page = implode('/', $page); + $regex = '|(.+)\.([^\.]+)\.([^.]+)$|'; + preg_match($regex, $page, $matches); + $view = $matches[1]; $return = elgg_view("$type/$view"); header("Content-type: $content_type"); -- cgit v1.2.3 From e809367625ed4f9d05b5711791392c60d8fac69e Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Apr 2011 00:42:02 +0000 Subject: preventing warnings with the user password authorization pam (hellekin) git-svn-id: http://code.elgg.org/elgg/trunk@8993 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/sessions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php index 5d45cc73d..ae42956a9 100644 --- a/engine/lib/sessions.php +++ b/engine/lib/sessions.php @@ -155,9 +155,9 @@ function elgg_authenticate($username, $password) { * @return bool * @throws LoginException */ -function pam_auth_userpass($credentials = NULL) { +function pam_auth_userpass(array $credentials = array()) { - if (!is_array($credentials) || !isset($credentials['username']) || !isset($credentials['password'])) { + if (!isset($credentials['username']) || !isset($credentials['password'])) { return false; } -- cgit v1.2.3 From 3d49441f503b1a25f68f8d56fdfb5582bf96bf8b Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Apr 2011 01:26:40 +0000 Subject: handles empty array in get_metastring_id() (hellekin) git-svn-id: http://code.elgg.org/elgg/trunk@8994 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/metastrings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index 47712d3fa..913d33a7d 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -75,7 +75,7 @@ function get_metastring_id($string, $case_sensitive = TRUE) { $ids[] = $metaString->id; } return $ids; - } else if ($metaStrings) { + } else if (isset($metaStrings[0])) { $row = $metaStrings[0]; } } -- cgit v1.2.3 From c38f617a9b4a8186574c64db6663b5582fd49acb Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Apr 2011 01:51:56 +0000 Subject: Fixes #3268 forwarding to referrer (fixed by ashwanthkumar) git-svn-id: http://code.elgg.org/elgg/trunk@8995 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/actions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/actions.php b/engine/lib/actions.php index 407b99f87..47e4dd4a4 100644 --- a/engine/lib/actions.php +++ b/engine/lib/actions.php @@ -113,7 +113,11 @@ function action($action, $forwarder = "") { register_error(elgg_echo('actionundefined', array($action))); } - forward($forwarder); + if (!empty($forwarder)) { + forward($forwarder); + } else { + forward(REFERER); + } } /** -- cgit v1.2.3 From 6f6f9abc3d45dc305ab8ea8dfd53f7f975982228 Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Apr 2011 11:25:47 +0000 Subject: fixed filtering of external files array and suppressed warning in external files unit test git-svn-id: http://code.elgg.org/elgg/trunk@8998 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 2 +- engine/tests/api/helpers.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index a800aca7a..6c94133df 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -400,7 +400,7 @@ function elgg_get_loaded_external_files($type, $location) { if (isset($CONFIG->externals) && isset($CONFIG->externals[$type])) { $items = array_values($CONFIG->externals[$type]); - $callback = "return \$v->loaded == true && \$v->location == $location;"; + $callback = "return \$v->loaded == true && \$v->location == '$location';"; $items = array_filter($items, create_function('$v', $callback)); if ($items) { usort($items, create_function('$a,$b','return $a->priority >= $b->priority;')); diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index 1362b3c9d..461627547 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -109,7 +109,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $this->assertIdentical('http://test1.com', $CONFIG->externals['js']['key']->url); // send a bad url - $result = elgg_register_js(); + $result = @elgg_register_js('bad'); $this->assertFalse($result); } @@ -140,7 +140,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $result = elgg_unregister_js('id1'); $this->assertTrue($result); - $this->assertNULL($CONFIG->externals['js']['head']['id1']); + @$this->assertNULL($CONFIG->externals['js']['head']['id1']); $result = elgg_unregister_js('id1'); $this->assertFalse($result); -- cgit v1.2.3 From e60d45a1e8025a10220a42285d3ff17335af5214 Mon Sep 17 00:00:00 2001 From: brettp Date: Thu, 14 Apr 2011 23:06:51 +0000 Subject: Refs #3195. Changed the way annotation calculations are performed. Seems to be working better, but will want to test more before closing. git-svn-id: http://code.elgg.org/elgg/trunk@9000 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 41 +++++++++++++++++++++++++---------------- engine/lib/deprecated-1.8.php | 8 ++++---- engine/lib/metastrings.php | 12 +++++++++++- 3 files changed, 40 insertions(+), 21 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 1178a079f..7a4e62921 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -386,21 +386,27 @@ function elgg_list_entities_from_annotations($options = array()) { } /** - * Get entities ordered by a mathematical calculation + * Get entities ordered by a mathematical calculation on annotation values + * + * @todo I think at some point this could run through elgg_get_annotations() and pass a the callback + * as entity_row_to_elggstar * * @param array $options An options array: - * 'calculation' => The calculation to use. Must be a valid MySQL function. - * Defaults to sum. Result selected as 'calculated'. - * 'order_by' => The order for the sorting. Defaults to 'calculated desc'. + * 'annotation_calculation' => The calculation to use. Must be a valid MySQL function. + * Defaults to sum. Result selected as 'annotation_calculation'. + * 'order_by' => The order for the sorting. Defaults to 'calculation desc'. + * 'annotation_names' => The names of annotations on the entity. + * 'annotation_values' => The values of annotations on the entity. + * + * 'metadata_names' => The name of metadata on the entity. + * 'metadata_values' => The value of metadata on the entitiy. * * @return mixed */ function elgg_get_entities_from_annotation_calculation($options) { - global $CONFIG; - $defaults = array( - 'calculation' => 'sum', - 'order_by' => 'calculated desc', + 'calculation' => 'sum', + 'order_by' => 'calculation desc' ); $options = array_merge($defaults, $options); @@ -408,17 +414,20 @@ function elgg_get_entities_from_annotation_calculation($options) { $function = sanitize_string(elgg_extract('calculation', $options, 'sum', false)); // you must cast this as an int or it sorts wrong. - $options['selects'][] = "$function(cast(msv.string as signed)) as calculated"; - $options['selects'][] = "msn.string as value"; - $options['order_by'] = 'calculated desc'; + $options['selects'][] = 'e.*'; + $options['selects'][] = "$function(cast(v.string as signed)) as calculation"; // need our own join to get the values. - $db_prefix = get_config('dbprefix'); - $options['joins'][] = "JOIN {$db_prefix}annotations calc_table on e.guid = calc_table.entity_guid"; - $options['joins'][] = "JOIN {$db_prefix}metastrings msv on calc_table.value_id = msv.id"; - $options['wheres'][] = "calc_table.name_id = n_table.name_id"; +// $options['joins'][] = "JOIN {$db_prefix}metastrings msv ON a.value_id = msv.id"; +// $options['joins'][] = "JOIN {$db_prefix}entities ae ON a.entity_guid = ae.guid"; + + $options['wheres'][] = get_access_sql_suffix('n_table'); +// $options['wheres'][] = "e.guid = a.entity_guid"; + $options['group_by'] = 'n_table.entity_guid'; + + $options['callback'] = 'entity_row_to_elggstar'; - return elgg_get_entities_from_annotations($options); + return elgg_get_annotations($options); } /** diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php index 165546d31..27a973601 100644 --- a/engine/lib/deprecated-1.8.php +++ b/engine/lib/deprecated-1.8.php @@ -115,7 +115,7 @@ function get_entities_from_annotations_calculate_x($sum = "sum", $entity_type = $options['limit'] = $limit; $options['offset'] = $offset; - $options['order_by'] = "calculated $orderdir"; + $options['order_by'] = "calculation $orderdir"; $options['count'] = $count; @@ -179,7 +179,7 @@ function get_entities_from_annotation_count($entity_type = "", $entity_subtype = $options['limit'] = $limit; $options['offset'] = $offset; - $options['order_by'] = "calculated $orderdir"; + $options['order_by'] = "calculation $orderdir"; $options['count'] = $count; @@ -241,7 +241,7 @@ function list_entities_from_annotation_count($entity_type = "", $entity_subtype $options['limit'] = $limit; - $options['order_by'] = "calculated $orderdir"; + $options['order_by'] = "calculation $orderdir"; return elgg_get_entities_from_annotation_calculation($options); } @@ -3492,7 +3492,7 @@ $asc = false, $fullview = true, $listtypetoggle = false, $pagination = true, $or $options['limit'] = $limit; - $options['order_by'] = "calculated $orderdir"; + $options['order_by'] = "calculation $orderdir"; return elgg_get_entities_from_annotation_calculation($options); } diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index 913d33a7d..604c7f765 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -406,8 +406,18 @@ function elgg_get_metastring_based_objects($options) { } if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE) { + // evalutate selects + if ($options['selects']) { + $selects = ''; + foreach ($options['selects'] as $select) { + $selects .= ", $select"; + } + } else { + $selects = ''; + } + $query = "SELECT DISTINCT n_table.*, n.string as name, - v.string as value FROM {$db_prefix}$type n_table"; + v.string as value{$selects} FROM {$db_prefix}$type n_table"; } else { $query = "SELECT {$options['metastring_calculation']}(v.string) as calculation FROM {$db_prefix}$type n_table"; } -- cgit v1.2.3 From 2b2afd98c05139c1a5c25f1752e2bb412e26e335 Mon Sep 17 00:00:00 2001 From: brettp Date: Thu, 14 Apr 2011 23:49:43 +0000 Subject: Fixed problem with list_entities_from_metadata() wrapper. git-svn-id: http://code.elgg.org/elgg/trunk@9001 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/deprecated-1.8.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php index 27a973601..bb52881cd 100644 --- a/engine/lib/deprecated-1.8.php +++ b/engine/lib/deprecated-1.8.php @@ -1152,10 +1152,22 @@ function list_entities_from_metadata($meta_name, $meta_value = "", $entity_type $offset = (int)get_input('offset'); $limit = (int)$limit; - $options = array('metadata_name' => $meta_name, 'metadata_value' => $meta_value, - 'types' => $entity_type, 'subtypes' => $entity_subtype, 'owner_guid' => $owner_guid, - 'limit' => $limit, 'offset' => $offset, 'count' => TRUE, - 'metadata_case_sensitive' => $case_sensitive); + $options = array( + 'metadata_name' => $meta_name, + 'metadata_value' => $meta_value, + 'types' => $entity_type, + 'subtypes' => $entity_subtype, + 'limit' => $limit, + 'offset' => $offset, + 'count' => TRUE, + 'metadata_case_sensitive' => $case_sensitive + ); + + // previous function allowed falsy $owner_guid for anything + if ($owner_guid) { + $options['owner_guid'] = $owner_guid; + } + $count = elgg_get_entities_from_metadata($options); $options['count'] = FALSE; -- cgit v1.2.3