Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-11-22 07:23:58 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-11-22 07:23:58 (GMT)
commit494c06625fc7b3fbe94a4c1f4774bf289568ea30 (patch)
treeac9d74283ab8ea2191a491d88326f84201378289 /site
parent41f3e3761aeeac5611a286372355dcf3bc06e495 (diff)
Initial version of microformat updater
Diffstat (limited to 'site')
-rw-r--r--site/app/controllers/collections_controller.php27
-rw-r--r--site/app/models/addon.php40
-rw-r--r--site/app/models/addon_collection.php16
-rw-r--r--site/app/models/version.php36
-rw-r--r--site/app/views/collections/edit.thtml14
-rw-r--r--site/app/views/elements/amo2009/separated_list_items.thtml2
-rw-r--r--site/app/views/helpers/install_button.php4
-rw-r--r--site/app/webroot/js/amo2009/addons.js61
-rw-r--r--site/app/webroot/services/micro-format.php85
-rw-r--r--site/app/webroot/services/update-aslo.php5
10 files changed, 264 insertions, 26 deletions
diff --git a/site/app/controllers/collections_controller.php b/site/app/controllers/collections_controller.php
index 72150be..3ce4e5d 100644
--- a/site/app/controllers/collections_controller.php
+++ b/site/app/controllers/collections_controller.php
@@ -417,14 +417,7 @@ class CollectionsController extends AppController
// Fetch #3! Pull useful addon data this time.
$addons = $this->Addon->getAddonList($pagedIds,array(
'all_categories', 'authors', 'compatible_apps', 'files', 'latest_version',
- 'list_details'));
-
- foreach($addons as &$addon) {
- $a = &$addon['Addon'];
- // Get publish details for each add-on
- $publishDetails = $this->Addon->getCollectionPublishDetails($a['id'], $collection_id);
- $a = array_merge($a, $publishDetails);
- }
+ 'list_details'), null, $collection_id);
return array($addons, $sort_options, $sortby);
}
@@ -1273,6 +1266,24 @@ class CollectionsController extends AppController
}
break;
+ case 'save_addon_version':
+ $addon_version = strip_tags(trim($this->params['form']['addon_version']));
+ $addon = $this->AddonCollection->find(array('addon_id'=>$addon_id, 'collection_id'=>$collection_id), array('user_id'));
+ if (empty($addon)) return $this->Error->getJSONforError(___('Add-on not found!'));
+ if (!$rights['isadmin'] && !$rights['atleast_manager']) {
+ // publisher's own add-on?
+ if ($addon['AddonCollection']['user_id'] != $user['id']) return $this->Error->getJSONforError(___('Access Denied'));
+ }
+ if (!$this->AddonCollection->setAddonVersion($collection_id, $addon_id, $addon_version)) {
+ return $this->Error->getJSONforError(___('Error saving addon version!'));
+ } else {
+ return array(
+ 'addon_id' => $addon_id,
+ 'addon_version' => $addon_version
+ );
+ }
+ break;
+
default:
return $this->Error->getJSONforError(sprintf(___('Missing argument: %s'), 'action'));
}
diff --git a/site/app/models/addon.php b/site/app/models/addon.php
index 1b55f9d..cfcc301 100644
--- a/site/app/models/addon.php
+++ b/site/app/models/addon.php
@@ -177,7 +177,7 @@ class Addon extends AppModel
* By convention, the associations array should be all lower case and sorted
* alphabetically, to promote cache hits across pages.
*/
- function getAddon($id, $associations = array(), $app_ver = null) {
+ function getAddon($id, $associations = array(), $app_ver = null, $collection_id = null) {
global $valid_status;
if (!isset($app_ver) || $app_ver == 'any')
@@ -308,15 +308,38 @@ class Addon extends AppModel
// get desired add-on from DB
$addon = $this->findById($id, array_unique($fields));
+ if ($collection_id) {
+ // comments are en-US only
+ $sql = "SELECT addons_collections.added, translations.localized_string as comment, users.id, users.firstname, users.lastname, users.nickname, addons_collections.addon_version
+ FROM addons_collections
+ LEFT JOIN translations
+ ON translations.id = addons_collections.comments AND translations.locale='en-US'
+ INNER JOIN users
+ ON users.id = addons_collections.user_id
+ WHERE collection_id = {$collection_id} AND addon_id = {$id}";
+ $data = $this->query($sql);
+
+ $addon['Addon']['dateadded'] = $data[0]['addons_collections']['added'];
+ $addon['Addon']['publisher'] = $data[0]['users'];
+ $addon['Addon']['comment'] = $data[0]['translations']['comment'];
+ $addon['Addon']['addon_version'] = (string)$data[0]['addons_collections']['addon_version'];
+ }
+
// add additional data
if (in_array('latest_version', $associations)) {
// pull in last version
$this->Version->unbindFully();
$this->Version->caching = false;
$this->Version->useDbConfig = 'shadow';
- $buf = $this->Version->findAll(array(
- 'Version.id' => $this->Version->getVersionByAddonId($id,
- ($addon['Addon']['status']==STATUS_PUBLIC ? STATUS_PUBLIC : $valid_status), $app_ver)),
+
+ $version_status = ($addon['Addon']['status']==STATUS_PUBLIC ? STATUS_PUBLIC : $valid_status);
+ if ($addon['Addon']['addon_version'])
+ $version_id = $this->Version->getVersionByAddonIdAndVersion($id, $addon['Addon']['addon_version'], $version_status, $app_ver);
+ else
+ $version_id = $this->Version->getVersionByAddonId($id, $version_status, $app_ver);
+
+ $buf = $this->Version->findAll(
+ array('Version.id' => $version_id),
array('Version.id', 'Version.version', 'Version.created'));
if (!empty($buf[0]['Version'])) {
@@ -399,10 +422,10 @@ class Addon extends AppModel
* Get a list of add-ons by id, each with the given associations
* uses the object invalidation framework
*/
- function getAddonList($ids, $associations = array(), $app_ver = null) {
+ function getAddonList($ids, $associations = array(), $app_ver = null, $collection_id = null) {
$result = array();
foreach ($ids as $id) {
- $result[] = $this->getAddon($id, $associations, $app_ver);
+ $result[] = $this->getAddon($id, $associations, $app_ver, $collection_id);
}
return $result;
}
@@ -808,7 +831,7 @@ class Addon extends AppModel
$this->unbindFully();
// comments are en-US only
- $sql = "SELECT addons_collections.added, translations.localized_string as comment, users.id, users.firstname, users.lastname, users.nickname
+ $sql = "SELECT addons_collections.added, translations.localized_string as comment, users.id, users.firstname, users.lastname, users.nickname, addons_collections.addon_version
FROM addons_collections
LEFT JOIN translations
ON translations.id = addons_collections.comments AND translations.locale='en-US'
@@ -820,7 +843,8 @@ class Addon extends AppModel
$details = array(
'dateadded' => $data[0]['addons_collections']['added'],
'publisher' => $data[0]['users'],
- 'comment' => $data[0]['translations']['comment']
+ 'comment' => $data[0]['translations']['comment'],
+ 'addon_version' => (string)$data[0]['addons_collections']['addon_version'],
);
return $details;
}
diff --git a/site/app/models/addon_collection.php b/site/app/models/addon_collection.php
index 92c89f7..ec161fc 100644
--- a/site/app/models/addon_collection.php
+++ b/site/app/models/addon_collection.php
@@ -77,7 +77,7 @@ class AddonCollection extends AppModel
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$collection_id = $db->value($collection_id);
$this->unbindFully();
- $res = $this->findAll(array('collection_id' => $collection_id));
+ $res = $this->query("SELECT * FROM addons_collections as AddonCollection WHERE collection_id = {$collection_id}");
if (!empty($res)) {
loadModel('Addon');
loadModel('User');
@@ -147,6 +147,20 @@ class AddonCollection extends AppModel
}
}
+ function setAddonVersion($collection_id, $addon_id, $addon_version) {
+ $db =& ConnectionManager::getDataSource($this->useDbConfig);
+ $collection_id = $db->value($collection_id);
+ $addon_id = $db->value($addon_id);
+
+ if (empty($addon_version))
+ $addon_version = 'null';
+
+ $res = $db->execute("UPDATE addons_collections SET addon_version = {$addon_version} "
+ ."WHERE collection_id = {$collection_id} AND addon_id = {$addon_id}");
+
+ return false !== $res;
+ }
+
/**
* is an add-on part of a given collection?
*
diff --git a/site/app/models/version.php b/site/app/models/version.php
index c0ea46d..f15ba00 100644
--- a/site/app/models/version.php
+++ b/site/app/models/version.php
@@ -168,6 +168,42 @@ class Version extends AppModel
return 0;
}
+
+ function getVersionByAddonIdAndVersion($id, $version, $status = array(STATUS_PUBLIC), $app_ver = null) {
+ if (!is_array($status)) $status = array($status);
+ $status_sql = implode(',',$status);
+
+ if (!isset($app_ver) || $app_ver == 'any')
+ $app_ver = parse_sp();
+
+ $sql = "
+ SELECT
+ Version.id
+ FROM
+ versions AS Version
+ INNER JOIN
+ files AS File ON File.status IN ({$status_sql}) AND File.version_id = Version.id
+ INNER JOIN
+ applications_versions A ON A.version_id = Version.id
+ INNER JOIN
+ appversions as B ON B.id = A.min
+ INNER JOIN
+ appversions as C ON C.id = A.max
+ WHERE
+ Version.addon_id = {$id} AND Version.version = {$version}
+ ORDER BY
+ IF({$app_ver} AND ({$app_ver} < CAST(B.version AS DECIMAL(3,3)) OR {$app_ver} > CAST(C.version AS DECIMAL(3,3))), 1, 1000000) + CAST(Version.version AS DECIMAL) DESC
+ LIMIT 1
+ ";
+
+ $buf = $this->query($sql);
+
+ if (!empty($buf[0]['Version']['id'])) {
+ return $buf[0]['Version']['id'];
+ }
+
+ return 0;
+ }
/**
* Get the apps compatible with a given addon version
diff --git a/site/app/views/collections/edit.thtml b/site/app/views/collections/edit.thtml
index bf96005..53c49e3 100644
--- a/site/app/views/collections/edit.thtml
+++ b/site/app/views/collections/edit.thtml
@@ -257,8 +257,12 @@ JS;
<div id="currentaddons" class="jsonly">
<h3><?=___('Current Add-ons:')?></h3>
<div class="coll-addon" id="addon-new" style="display:none">
+ <span class="addon_name_value" style="display:none"></span>
+ <span class="addon_version_value" style="display:none"></span>
<p><img src="" alt=""/><span class="name"></span><span class="added"><?=___('Added %1$s by %2$s')?></span></p>
<a href="#" class="removeaddon"><?=___('Remove this add-on')?></a>
+ <span class="version_sep">&nbsp;&nbsp;</span>
+ <a href="#" class="set_version"><?=___('Version')?></a>
<blockquote title="publishercomment"></blockquote>
<a href="#" class="addlink"><?=___('Add publisher comment')?></a>
<div class="editdelete">
@@ -270,6 +274,11 @@ JS;
<input type="button" value="<?=___('Save Comment')?>"/>
<p><?=___('Note: Comment will appear as though written by original publisher on the original publication date')?></p>
</div>
+ <div class="version_box">
+ <label for="addon_version"><?=___('Version')?></label>
+ <input id="addon_version" type="text" size="5" class="addon_version" value=""/>
+ <input type="button" value="<?=___('Save')?>"/>
+ </div>
</div>
</div>
</div>
@@ -317,7 +326,7 @@ JS;
collections_edit.init();
<?php
foreach ($addons as &$addon) {
- echo sprintf("collections_edit.addon_show('%s','%s','%s','%s','%s','%s', %s, %s);\n",
+ echo sprintf("collections_edit.addon_show('%s','%s','%s','%s','%s','%s', %s, %s, '%s');\n",
$addon['AddonCollection']['addon_id'], // id
addslashes($html->unsanitize($addon['Addon']['Translation']['name']['string'])), // name
$this->controller->Image->getAddonIconURL($addon['AddonCollection']['addon_id']), // iconurl
@@ -325,7 +334,8 @@ JS;
$html->linkUserFromModel($addon['User']), // publisher
preg_replace('/\n/', '<br/>', $addon['Translation']['comments']['string']), // comment
(($atleast_manager || $addon['User']['id'] == $user['id']) ? 1 : 0), // editable
- 0 // insert at the end
+ 0, // insert at the end
+ $addon['AddonCollection']['addon_version']
);
}
foreach (array('publishers', 'managers') as $role) {
diff --git a/site/app/views/elements/amo2009/separated_list_items.thtml b/site/app/views/elements/amo2009/separated_list_items.thtml
index e2ce16c..57ec921 100644
--- a/site/app/views/elements/amo2009/separated_list_items.thtml
+++ b/site/app/views/elements/amo2009/separated_list_items.thtml
@@ -77,7 +77,7 @@
<!-- TODO: a11y ordering -->
<h4>
<a href="<?=$addon_link?>">
- <?=$addon['Translation']['name']['string']?>
+ <?=$addon['Translation']['name']['string']?><?= $a['addon_version'] ? "-" . $a['addon_version'] : "" ?>
</a>
<span>
<?=sprintf(___('created by %1$s'),
diff --git a/site/app/views/helpers/install_button.php b/site/app/views/helpers/install_button.php
index 7c27738..c5cf541 100644
--- a/site/app/views/helpers/install_button.php
+++ b/site/app/views/helpers/install_button.php
@@ -795,9 +795,9 @@ class InstallButtonHelper extends Helper {
}
function isLatest() {
- return isset($this->options['is_latest']) ?
+ return !$this->addon['Addon']['addon_version'] && (isset($this->options['is_latest']) ?
$this->options['is_latest'] :
- ($this->addonStatus() == STATUS_PUBLIC);
+ ($this->addonStatus() == STATUS_PUBLIC));
}
function compatibleApps() {
diff --git a/site/app/webroot/js/amo2009/addons.js b/site/app/webroot/js/amo2009/addons.js
index 93d89c4..d810c48 100644
--- a/site/app/webroot/js/amo2009/addons.js
+++ b/site/app/webroot/js/amo2009/addons.js
@@ -1720,7 +1720,7 @@ var collections_edit = {
/**
* show an add-on in the UI
*/
- addon_show: function(id, name, iconurl, date, publisher, comment, editable, ontop) {
+ addon_show: function(id, name, iconurl, date, publisher, comment, editable, ontop, addon_version) {
var div = $('<div class="coll-addon" id="addon-'+id+'"/>');
var tpl = $('#addon-new'); // template
@@ -1728,9 +1728,17 @@ var collections_edit = {
idfield.val(id);
div.append(idfield);
+ var addon_name_value = tpl.find('.addon_name_value').clone(true);
+ addon_name_value.text(name);
+ div.append(addon_name_value);
+
+ var addon_version_value = tpl.find('.addon_version_value').clone(true);
+ addon_version_value.text(addon_version);
+ div.append(addon_version_value);
+
var p = tpl.children('p').clone();
p.find('img').attr('src', iconurl);
- p.find('.name').text(name);
+ p.find('.name').text(name + (addon_version ? "-" + addon_version : ""));
p.find('.added').html(sprintf(p.find('.added').text(), date, publisher));
div.append(p);
if (editable) div.append(tpl.children('.removeaddon').clone(true));
@@ -1740,6 +1748,10 @@ var collections_edit = {
$('#currentaddons #addon-new').after(div);
}
collections_edit.addon_comment_show(id, comment, editable);
+ if (editable) {
+ div.append(tpl.children('.version_sep').clone(true));
+ div.append(tpl.children('.set_version').clone(true));
+ }
$('#currentaddons').show();
},
/**
@@ -1758,7 +1770,7 @@ var collections_edit = {
$('#addonname').select();
} else {
collections_edit.addon_show(data.id, data.name, data.iconURL,
- data.date, data.publisher, '', 1, 1);
+ data.date, data.publisher, '', 1, 1, '');
$('#addonname').val('');
}
return true;
@@ -1793,6 +1805,7 @@ var collections_edit = {
var tpl = $('#addon-new');
tpl.children('a.removeaddon').click(this.addon_delete);
tpl.children('a.addlink').click(this.addon_comment_add);
+ tpl.children('a.set_version').click(this.addon_set_version);
tpl.find('a.editlink').click(this.addon_comment_edit);
tpl.find('a.deletelink').click(function() {
var container = $(this).parent().parent();
@@ -1809,6 +1822,39 @@ var collections_edit = {
collections_edit.addon_comment_save(addonid, comment);
return false;
});
+
+ tpl.find('.version_box>input:button').click(function() {
+ var addon_version = $(this).parent().children('input:text').attr('value');
+ var container = $(this).parent().parent();
+ var idstring = container.attr('id');
+ var addonid = idstring.substr(idstring.lastIndexOf('-')+1);
+
+ $.post(jsonURL+'/addon/save_addon_version', {
+ sessionCheck: $('#collections>div.hsession>input[name=sessionCheck]').val(),
+ collection_id: collection_id,
+ addon_id: addonid,
+ addon_version: addon_version
+ }, function(data) {
+ var addonid = /addon_id=(\d+)/.exec(this.data)[1];
+ var container = $('#addon-'+addonid);
+ if (data.error) {
+ var msg = $('<div class="error">'+data.error_message+'</div>');
+ container.append(msg);
+ msg.delay(2000, function(){ $(this).fadeRemove(); });
+ } else {
+ var name = container.children('.addon_name_value').text();
+ container.children('.addon_version_value').text(addon_version);
+ container.find('p>.name').text(name + (addon_version ? "-" + addon_version : ""));
+
+ container.children('.version_box').remove();
+ var tpl = $('#addon-new');
+ container.append(tpl.children('.set_version').clone(true));
+ }
+ return true;
+ }, 'json');
+
+ return false;
+ });
},
/**
* show a publisher comment in the UI
@@ -1833,6 +1879,15 @@ var collections_edit = {
editbox.children('textarea').focus();
return false;
},
+ addon_set_version: function() {
+ var addon_version = $(this).parent().find('.addon_version_value').text();
+ var version_box = $('#addon-new>.version_box').clone(true);
+ $(this).parent().append(version_box);
+ $(this).remove();
+ version_box.children('input:text').attr('value', addon_version);
+ version_box.children('input:text').focus();
+ return false;
+ },
/**
* edit an existing publisher comment in the UI
*/
diff --git a/site/app/webroot/services/micro-format.php b/site/app/webroot/services/micro-format.php
new file mode 100644
index 0000000..efd0b3b
--- /dev/null
+++ b/site/app/webroot/services/micro-format.php
@@ -0,0 +1,85 @@
+<?php
+
+require_once('../../config/config.php');
+require_once('../../config/config-local.php');
+require_once('../../config/constants.php');
+require_once('./functions.php');
+
+$errors = array();
+
+foreach (array('name') as $var) {
+ if (empty($_GET[$var]))
+ $errors[] = 'Required variable '.$var.' not set.';
+}
+
+$dbh = @mysql_connect(DB_HOST.':'.DB_PORT,DB_USER,DB_PASS);
+
+if (!is_resource($dbh)) {
+ $errors[] = 'MySQL connection to DB failed.';
+} elseif (!@mysql_select_db(DB_NAME, $dbh)) {
+ $errors[] = 'Could not select database '.DB_NAME.'.';
+}
+
+if (empty($errors)) {
+ $sql_query = "
+ SELECT
+ addons.id,
+ addons.guid,
+ max(versions.version) as version,
+ files.size,
+ files.filename,
+ files.id as file_id
+ FROM
+ collections
+ INNER JOIN addons_collections ON collections.id = addons_collections.collection_id
+ INNER JOIN addons ON addons.id = addons_collections.addon_id
+ INNER JOIN versions ON versions.addon_id = addons.id AND (addons_collections.addon_version IS NULL OR versions.version = addons_collections.addon_version)
+ INNER JOIN files ON files.version_id = versions.id
+ WHERE
+ collections.nickname = '{$_GET['name']}'
+ GROUP BY
+ addons.id
+ ";
+
+ $query = mysql_query($sql_query);
+
+ if (!$query)
+ $errors[] = 'MySQL query for update information failed.';
+}
+
+echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
+echo "<html lang=\"en\">\n";
+
+echo "<head>\n";
+echo "<title>ASLO micro-format output</title>\n";
+echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
+echo "</head>\n";
+
+echo "<body>\n";
+
+if (!empty($errors)) {
+ foreach ($errors as $error)
+ echo $error;
+} else {
+ echo "<table>\n";
+ while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
+ if (defined(FILES_HOST))
+ $url = FILES_HOST . '/' . $row['id'] . '/' . $row['filename'];
+ else
+ $url = '/downloads/file/' . $row['file_id'] . '/' . $row['filename'];
+ echo "<tr>\n";
+ echo "<td class=\"olpc-activity-info\">\n";
+ echo "<span class=\"olpc-activity-id\">{$row['guid']}</span>\n";
+ echo "<span class=\"olpc-activity-version\">{$row['version']}</span>\n";
+ echo "<span class=\"olpc-activity-size\">{$row['size']}</span>\n";
+ echo "<span class=\"olpc-activity-url\"><a href=\"{$url}\">download</a></span>\n";
+ echo "</td>\n";
+ echo "</tr>\n";
+ }
+ echo "</table>\n";
+}
+
+echo "</body>\n";
+
+echo "</html>";
+?>
diff --git a/site/app/webroot/services/update-aslo.php b/site/app/webroot/services/update-aslo.php
index 82f27d6..dfb3cae 100644
--- a/site/app/webroot/services/update-aslo.php
+++ b/site/app/webroot/services/update-aslo.php
@@ -257,7 +257,10 @@ if (empty($errors) && !$detect_installed) {
*
* If you want to test updates, change your config and set up a web dir with public files in it.
*/
- $data['uri'] = FILES_HOST . '/' . $data['id'] . '/' . $data['filename'];
+ if (defined(FILES_HOST))
+ $data['uri'] = FILES_HOST . '/' . $data['id'] . '/' . $data['filename'];
+ else
+ $data['uri'] = SITE_URL . '/downloads/file/' . $data['file_id'] . '/' . $data['filename'];
}
if (!empty($data['type'])) {