Skip to content

Commit

Permalink
Merge pull request #103 from Elgg/56-last-action
Browse files Browse the repository at this point in the history
chore(list): list plugins by last_action - most recent version upload
  • Loading branch information
beck24 committed Nov 26, 2014
2 parents 7402b7b + 9d5cd8d commit 5586706
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 5 deletions.
2 changes: 2 additions & 0 deletions actions/plugins/create_release.php
Expand Up @@ -94,6 +94,8 @@
'object_guid' => $release->guid,
));

update_entity_last_action($plugin_project->guid);

system_message(elgg_echo("plugins:release:saved"));

elgg_clear_sticky_form('community_plugins');
Expand Down
1 change: 1 addition & 0 deletions languages/en.php
Expand Up @@ -36,6 +36,7 @@
* Object views
*/
'plugins:uploadtime' => "Uploaded %s (%s)",
'plugins:updatedtime' => "Updated %s (%s)",
'plugins:release:version_warning' => 'Warning: The author recommends using a different release of this plugin! Do you still want to download this release?',
'plugins:download:version' => "Download %s",
'plugins:project:title:version' => "%s for Elgg %s",
Expand Down
1 change: 1 addition & 0 deletions lib/events.php
Expand Up @@ -125,4 +125,5 @@ function upgrades() {

elgg_load_library('plugins:upgrades');
run_function_once(__NAMESPACE__ . '\\upgrade_20141121');
run_function_once(__NAMESPACE__ . '\\upgrade_20141125');
}
44 changes: 44 additions & 0 deletions lib/upgrades.php
@@ -1,6 +1,7 @@
<?php

namespace Elgg\CommunityPlugins;
use ElggBatch;

// start using plugin setting version to handle future upgrades
function upgrade_20141121() {
Expand All @@ -12,3 +13,46 @@ function upgrade_20141121() {
error_log('setting version');
elgg_set_plugin_setting('version', 20141121, PLUGIN_ID);
}

function upgrade_20141125() {

$version = (int) elgg_get_plugin_setting('version', PLUGIN_ID);
if ($version == 2011111502) {
// this didn't happen correctly in the last upgrade
// due to some legacy setting
elgg_set_plugin_setting('version', 20141121, PLUGIN_ID);
$version = 20141121;
}

if ($version >= UPGRADE_VERSION) {
return true;
}

$options = array(
'type' => 'object',
'subtype' => 'plugin_project',
'limit' => false
);

$batch = new ElggBatch('elgg_get_entities', $options);

foreach ($batch as $plugin) {
// get most recent release
$releases = elgg_get_entities(array(
'type' => 'object',
'subtype' => 'plugin_release',
'container_guid' => $plugin->guid,
'limit' => 1,
'callback' => false // keep it quick as possible
));

if ($releases[0]->time_created) {
update_entity_last_action($plugin->guid, $releases[0]->time_created);
}
else {
update_entity_last_action($plugin->guid, $plugin->time_created);
}
}

elgg_set_plugin_setting('version', 20141125, PLUGIN_ID);
}
2 changes: 1 addition & 1 deletion pages/plugins/list.php
Expand Up @@ -36,7 +36,7 @@
break;
case 'newest':
default:
$options['order_by'] = 'e.time_created DESC';
$options['order_by'] = 'e.last_action DESC';
break;
}

Expand Down
2 changes: 1 addition & 1 deletion start.php
Expand Up @@ -14,7 +14,7 @@
define('PLUGINS_CONTRIBUTOR_RELATIONSHIP', 'plugin_contributor');

const PLUGIN_ID = 'community_plugins';
const UPGRADE_VERSION = 20141121;
const UPGRADE_VERSION = 20141125;

elgg_register_event_handler('init', 'system', __NAMESPACE__ . '\\init');

Expand Down
4 changes: 2 additions & 2 deletions views/default/object/plugin_project/plugin_project.php
Expand Up @@ -8,8 +8,8 @@
'href' => $project->getURL(),
'text' => $project->title,
));
$friendlytime = elgg_view_friendly_time($project->time_created);
$friendlytime = elgg_view_friendly_time($project->last_action);
$downloads = $project->getDownloadCount();
$info = "<div class=\"elgg-subtext\">" . elgg_echo('plugins:uploadtime', array($friendlytime, $downloads)) . "</div>";
$info = "<div class=\"elgg-subtext\">" . elgg_echo('plugins:updatedtime', array($friendlytime, $downloads)) . "</div>";

echo elgg_view_image_block($icon, $link . $info);
7 changes: 6 additions & 1 deletion views/default/plugins/front/bottom.php
Expand Up @@ -7,7 +7,12 @@

// Note: Not using elgg_extract because these are potentially expensive database queries.
if (!isset($vars['newest'])) {
$vars['newest'] = elgg_list_entities(array('type' => 'object', 'subtype' => 'plugin_project', 'pagination' => false));
$vars['newest'] = elgg_list_entities(array(
'type' => 'object',
'subtype' => 'plugin_project',
'pagination' => false,
'order_by' => 'e.last_action DESC'
));
}

if (!isset($vars['popular'])) {
Expand Down
1 change: 1 addition & 0 deletions views/default/widgets/plugins/content.php
Expand Up @@ -20,6 +20,7 @@
'subtypes' => array('plugin_project'),
'limit' => $number,
'offset' => 0,
'order_by' => 'e.last_action DESC',
'pagination' => false,
);

Expand Down

0 comments on commit 5586706

Please sign in to comment.