Skip to content

Commit

Permalink
fix(combine): properly sum plugin download counts
Browse files Browse the repository at this point in the history
  • Loading branch information
beck24 committed Nov 25, 2014
1 parent 3b4d631 commit ef7c035
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions actions/plugins/admin/combine.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

/**
* Action for combining two plugin projects
*/

$old_guid = (int)get_input('old_guid');
$new_guid = (int)get_input('new_guid');
$old_guid = (int) get_input('old_guid');
$new_guid = (int) get_input('new_guid');

$old_project = get_entity($old_guid);
$new_project = get_entity($new_guid);

if (!($old_project instanceof PluginProject) ||
!($new_project instanceof PluginProject)) {
!($new_project instanceof PluginProject)) {
register_error(elgg_echo('plugins:action:combine:invalid_guids'));
forward(REFERER);
}
Expand Down Expand Up @@ -39,7 +39,7 @@
$new_releases_name = '';
if ($new_releases) {
$info = pathinfo($new_releases[0]->originalfilename);
$new_releases_name = $info['filename'];
$new_releases_name = $info['filename'];
}

foreach ($releases as $release) {
Expand All @@ -48,18 +48,18 @@
if ($dupe) {
$release->version = $release->version . '-old';
}

$new_project->moveFilesOnSystem($release, $new_project->guid);
$release->owner_guid = $new_project->guid;
$release->container_guid = $new_project->guid;
$release->save();

if ($new_releases_name) {
$prefix = "plugins/";
// update file names on the filestore
$oldname = $release->getFilenameOnFilestore();
$info = pathinfo($oldname);

$new_file_name = $new_releases_name . '.' . $info['extension'];
$release->setFilename($prefix . strtolower($release->time_created . $new_file_name));
$release->originalfilename = $new_file_name;
Expand All @@ -68,15 +68,11 @@
}
}

// move download count to new project
$annotation_name = get_metastring_id('download', TRUE);
if ($annotation_name) {
$dbprefix = elgg_get_config('dbprefix');
$query = "UPDATE {$dbprefix}annotations
SET entity_guid=$new_project->guid
WHERE entity_guid=$old_project->guid AND name_id=$annotation_name";
update_data($query);
}
// merge plugin download count
$dbprefix = elgg_get_config('dbprefix');
$q = "UPDATE {$dbprefix}plugin_downloads pd JOIN {$dbprefix}plugin_downloads pd2 SET pd.downloads = (pd.downloads + pd2.downloads)"
. "WHERE pd.guid = {$new_project->guid} AND pd2.guid = {$old_project->guid}";
update_data($q);

$old_project->delete();

Expand Down

0 comments on commit ef7c035

Please sign in to comment.