Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/controllers/components/editors.php
diff options
context:
space:
mode:
Diffstat (limited to 'site/app/controllers/components/editors.php')
-rw-r--r--site/app/controllers/components/editors.php395
1 files changed, 21 insertions, 374 deletions
diff --git a/site/app/controllers/components/editors.php b/site/app/controllers/components/editors.php
index 0576751..f7b761f 100644
--- a/site/app/controllers/components/editors.php
+++ b/site/app/controllers/components/editors.php
@@ -123,9 +123,9 @@ class EditorsComponent extends Object {
$authors[] = $user['email'];
}
}
-
- $releasenotes = $this->controller->Version->findById($version['Version']['id'], array('Version.releasenotes'), null, -1);
+ $releasenotes = $this->controller->Version->findById($version['Version']['id'], array('Version.releasenotes'), null, -1);
+
$emailInfo = array('name' => $addon['Translation']['name']['string'],
'id' => $this->controller->Addon->id,
'reviewer' => $session['firstname'].' '.$session['lastname'],
@@ -136,7 +136,7 @@ class EditorsComponent extends Object {
);
$this->controller->set('info', $emailInfo);
-
+
if ($data['Approval']['ActionField'] == 'public') {
if (SITE_RELEASE_EMAIL) {
$this->controller->Email->template = 'email/aslo/release';
@@ -145,7 +145,7 @@ class EditorsComponent extends Object {
$this->controller->Email->send(false, SITE_RELEASE_EMAIL);
}
}
-
+
if ($data['Approval']['ActionField'] != 'superreview') {
$this->controller->Email->template = 'email/nominated/'.$data['Approval']['ActionField'];
$this->controller->Email->to = $emailInfo['email'];
@@ -281,7 +281,7 @@ class EditorsComponent extends Object {
'releasenotes' => $releasenotes[0]['releasenotes']
);
$this->controller->set('info', $emailInfo);
-
+
if ($data['Approval']['ActionField'] == 'public') {
if (SITE_RELEASE_EMAIL) {
$this->controller->Email->template = 'email/aslo/release';
@@ -290,7 +290,7 @@ class EditorsComponent extends Object {
$this->controller->Email->send(false, SITE_RELEASE_EMAIL);
}
}
-
+
if ($data['Approval']['ActionField'] != 'superreview') {
$this->controller->Email->template = 'email/pending/'.$data['Approval']['ActionField'];
$this->controller->Email->to = $emailInfo['email'];
@@ -366,20 +366,22 @@ class EditorsComponent extends Object {
function redirectByQueueRank($listtype, $rank) {
switch($listtype) {
case 'nominated':
+ $addon = $this->controller->Addon->findAll(array('Addon.status' => STATUS_NOMINATED),
+ array('Addon.id'), null, 1, $rank);
+ if (!empty($addon)) {
+ $addon = $this->controller->Addon->getAddon($addon[0]['Addon']['id'], array('latest_version'));
+ if (!empty($addon['Version'])) {
+ $this->controller->redirect("/editors/review/{$addon['Version'][0]['id']}?num={$rank}");
+ return;
+ }
+ }
+ break;
+
case 'pending':
- $rank = intval($rank);
- $offset = ($rank > 0) ? $rank - 1 : 0;
- $sql = $this->buildQueueFilterQuery($listtype);
- $queue_sql = "SELECT `Version`.`id`
- {$sql['FROM']}
- {$sql['JOIN']}
- {$sql['WHERE']}
- {$sql['ORDER']}
- LIMIT 1 OFFSET {$offset}";
-
- if ($result = $this->controller->Addon->query($queue_sql)) {
- $review_id = $result[0]['Version']['id'];
- $this->controller->redirect("/editors/review/{$review_id}?num={$rank}");
+ $file = $this->controller->File->findAll(array('File.status'=>STATUS_PENDING),
+ array('File.version_id'), null, 1, $rank);
+ if (!empty($file)) {
+ $this->controller->redirect("/editors/review/{$file[0]['File']['version_id']}?num={$rank}");
return;
}
break;
@@ -489,361 +491,6 @@ class EditorsComponent extends Object {
$this->controller->Email->subject = sprintf('[RELEASE] %s-%s', $emailInfo['name'], $emailInfo['version']);
$this->controller->Email->send(false, SITE_RELEASE_EMAIL);
}
-
- }
-
- /**
- * Determine if the specified queue is filterable
- * Queues currently filterable are: 'nominated' and 'pending'
- * @param string $queue name of queue
- * @return bool
- */
- function isFilterableQueue($queue) {
- return in_array($queue, array('pending', 'nominated'));
- }
-
- /**
- * Build query components for filtering the specified queue
- * Returns empty array for unfilterable queues
- * @param string $queue name of queue
- * @return array array('FROM'=>string, 'JOIN'=>string, 'WHERE'=>string, 'ORDER'=>string)
- * @TODO: for cake >=1.2, return compatible 'joins' and 'conditions' arrays
- */
- function buildQueueFilterQuery($queue='pending') {
- if (!$this->isFilterableQueue($queue)) {
- return array();
- }
-
- // Setup query components
- $base_components = $this->baseQueueFilterQuery($queue);
- $from = $base_components['FROM'];
- $joins = $base_components['JOIN'];
- $where = $base_components['WHERE'];
- $order = 'ORDER BY';
-
- // Fetch and apply filter
- if ($filter = $this->getQueueFilter($queue)) {
- $this->controller->Amo->clean($filter, false);
-
- if (isset($filter['AddonOrAuthor']) && strlen($filter['AddonOrAuthor']) > 0) {
- // search addons.name (localized), addons.supportemail (localized) and users.email
- $where .= "\nAND (`Version`.`addon_id` IN(
- SELECT `a`.`id` FROM `addons` AS `a`
- LEFT JOIN `translations` AS `ntr_l` ON
- (`ntr_l`.`id`=`a`.`name` AND `ntr_l`.`locale`='".LANG."')
- LEFT JOIN `translations` AS `ntr_en` ON
- (`ntr_en`.`id`=`a`.`name` AND `ntr_en`.`locale`=`a`.`defaultlocale`)
- LEFT JOIN `translations` AS `etr_l` ON
- (`etr_l`.`id`=`a`.`supportemail` AND `etr_l`.`locale`='".LANG."')
- LEFT JOIN `translations` AS `etr_en` ON
- (`etr_en`.`id`=`a`.`supportemail` AND `etr_en`.`locale`=`a`.`defaultlocale`)
- WHERE
- IFNULL(`ntr_l`.`localized_string`, `ntr_en`.`localized_string`)
- LIKE '%{$filter['AddonOrAuthor']}%'
- OR IFNULL(`etr_l`.`localized_string`, `etr_en`.`localized_string`)
- LIKE '%{$filter['AddonOrAuthor']}%'
-
- ) OR `Version`.`addon_id` IN(
- SELECT `a`.`id` FROM `addons` AS `a`
- LEFT JOIN `addons_users` AS `au` ON (`a`.`id`=`au`.`addon_id`)
- LEFT JOIN `users` AS `u` ON (`au`.`user_id`=`u`.`id`)
- WHERE
- `au`.`role` IN(".AUTHOR_ROLE_ADMINOWNER.","
- .AUTHOR_ROLE_ADMIN.","
- .AUTHOR_ROLE_OWNER.","
- .AUTHOR_ROLE_DEV.")
- AND `u`.`email` LIKE '%{$filter['AddonOrAuthor']}%'
- ))";
- }
-
- if (!empty($filter['Application'])) {
- $joins .= "\nLEFT JOIN `applications_versions`
- ON (`Version`.`id`=`applications_versions`.`version_id`)";
- $where .= "\nAND (
- `applications_versions`.`application_id`='{$filter['Application']}')";
-
- if (!empty($filter['MaxVersion'])) {
- $where .= "\nAND (`applications_versions`.`max`='{$filter['MaxVersion']}')";
- }
- }
-
- if (!empty($filter['SubmissionAge'])) {
- $age = $filter['SubmissionAge'];
- $age_op = '='; // exact match by default
-
- if (substr($age, -1) == '+') {
- // values like '10+' magically turn into a '>=10' comparison
- $age_op = '>=';
- $age = substr($age, 0, -1);
- } elseif ($age === '1') {
- // make '1 day' include less than 1 as well
- $age_op = '<=';
- }
-
- if ($queue == 'pending') {
- $where .= "\nAND (TIMESTAMPDIFF(DAY, `Version`.`created`, NOW()){$age_op}'{$age}')";
- } elseif ($queue == 'nominated') {
- $where .= "\nAND (TIMESTAMPDIFF(DAY, `Addon`.`nominationdate`, NOW()){$age_op}'{$age}')";
- }
- }
-
- if (!empty($filter['Addontype'])) {
- if (is_array($filter['Addontype'])) {
- $filter_vals = $filter['Addontype'];
- } else {
- $filter_vals = array($filter['Addontype']);
- }
-
- $where .= "\nAND (`Addon`.`addontype_id` IN('"
- . implode("','", $filter_vals) ."'))";
- }
-
- if (!empty($filter['Platform'])) {
- if (is_array($filter['Platform'])) {
- $filter_vals = $filter['Platform'];
- } else {
- $filter_vals = array($filter['Platform']);
- }
-
- // only available to pending queue for now
- if ($queue == 'pending') {
- $where .= "\nAND (`File`.`platform_id` IN('"
- . implode("','", $filter_vals) ."'))";
- }
- }
- }
- //End apply filter
-
- // Sorting
- $theSort = $this->getQueueSort($queue);
- switch ($theSort['sortby']) {
- case 'name':
- $joins .= "\nLEFT JOIN `translations` AS `tr_l` ON
- (`tr_l`.`id` = `Addon`.`name` AND `tr_l`.`locale` = '".LANG."')"
- ."\nLEFT JOIN `translations` AS `tr_en` ON
- (`tr_en`.`id` = `Addon`.`name` AND `tr_en`.`locale` = `Addon`.`defaultlocale`)";
- $order .= ' IFNULL(tr_l.localized_string, tr_en.localized_string)';
- $order .= strtoupper($theSort['direction'] == 'DESC') ? ' DESC' : ' ASC';
- break;
-
- case 'type':
- $joins .= "\nLEFT JOIN addontypes AS `Addontype` ON
- (`Addon`.`addontype_id`=`Addontype`.`id`)"
- ."\nLEFT JOIN translations AS `tr_l` ON
- (`tr_l`.`id` = `Addontype`.`name` AND `tr_l`.`locale` = '".LANG."')"
- ."\nLEFT JOIN translations AS tr_en ON
- (`tr_en`.`id` = `Addontype`.`name` AND `tr_en`.`locale` = 'en-US')";
- $order .= ' IFNULL(`tr_l`.`localized_string`, `tr_en`.`localized_string`)';
- $order .= strtoupper($theSort['direction'] == 'DESC') ? ' DESC' : ' ASC';
- // secondary sort by age
- if ($queue == 'pending') {
- $order .= ', `Version`.`created` ASC';
- } else {
- $order .= ', `Addon`.`nominationdate` ASC';
- }
- break;
-
- case 'age':
- default:
- if ($queue == 'pending') {
- $order .= ' `Version`.`created`';
- } else {
- $order .= ' `Addon`.`nominationdate`';
- }
- $order .= strtoupper($theSort['direction'] == 'DESC') ? ' DESC' : ' ASC';
- break;
- }
-
- return array('FROM'=>$from, 'JOIN'=>$joins, 'WHERE'=>$where, 'ORDER'=>$order);
- }
-
- /**
- * Return base query components for filtering the specified queue
- * Returns empty array for unfilterable queues
- * @param string $queue name of queue
- * @return array array('FROM'=>string, 'JOIN'=>string, 'WHERE'=>string)
- * @TODO: for cake >=1.2, return compatible 'joins' and 'conditions' arrays
- */
- function baseQueueFilterQuery($queue='pending') {
- if (!$this->isFilterableQueue($queue)) {
- return array();
- }
-
- // Setup query components
- if ($queue == 'pending') {
- $from = "FROM `files` AS `File`";
- $joins = "LEFT JOIN `versions` AS `Version` ON (`File`.`version_id`=`Version`.`id`)";
- $joins .= "\nINNER JOIN `addons` AS `Addon` ON (`Version`.`addon_id`=`Addon`.`id`)";
- $where = "WHERE `File`.`status`='".STATUS_PENDING."'";
-
- } elseif ($queue == 'nominated') {
- $from = "FROM `addons` AS `Addon`";
- $joins = "INNER JOIN `versions` AS `Version` ON (`Addon`.`id`=`Version`.`addon_id`)";
- $where = "WHERE `Addon`.`status`='".STATUS_NOMINATED."'";
-
- // This makes sure we get only the most recent version
- // "Find the version where no other version exists for the same addon and a greater creation date"
- // http://stackoverflow.com/questions/157459/problem-joining-on-the-highest-value-in-mysql-table
- $joins .= "\nLEFT JOIN `versions` AS `v2` ON (
- `Version`.`addon_id`=`v2`.`addon_id` AND
- `Version`.`created`<`v2`.`created`)";
- $where .= "\nAND (`v2`.`id` IS NULL)";
- }
-
- return array('FROM'=>$from, 'JOIN'=>$joins, 'WHERE'=>$where);
- }
-
- /**
- * Get the active filter for the specified queue
- * @param string $queue name of queue
- * @return array filter array or empty array if none exists
- */
- function getQueueFilter($queue) {
- if (!$this->isFilterableQueue($queue)) {
- return array();
- }
-
- $filter = array();
- $queue_filters = $this->controller->Session->read('editor_queue_filters');
- if (isset($queue_filters[$queue])) {
- $filter = $queue_filters[$queue];
- }
- return $filter;
- }
-
- /**
- * Set the active filter for the specified queue
- * Only known fields are saved into the filter
- * @param string $queue name of queue
- * @return array empty array, or valid saved filter
- */
- function setQueueFilter($queue, $new_filter) {
- if (!$this->isFilterableQueue($queue)) {
- return array();
- }
-
- // known filter fields
- $filter_fields = array('Addontype', 'Application', 'MaxVersion',
- 'Platform', 'SubmissionAge', 'AddonOrAuthor');
- $filter = array();
-
- if (is_array($new_filter)) {
- foreach ($new_filter as $k => $val) {
- // only save known filter fields
- if (!empty($val) && in_array($k, $filter_fields)) {
- $filter[$k] = $val;
- }
- }
- }
-
- // get or create array of filters
- $queue_filters = $this->controller->Session->read('editor_queue_filters');
- if (!is_array($queue_filters)) {
- $queue_filters = array();
- }
-
- if ($filter) {
- // update filter
- $queue_filters[$queue] = $filter;
- } else {
- // clear filter
- unset($queue_filters[$queue]);
- }
-
- // save all filters
- $this->controller->Session->write('editor_queue_filters', $queue_filters);
-
- return $filter;
- }
-
- /**
- * Determine if the specified queue is sortable
- * @param string $queue name of queue
- * @return bool
- */
- function isSortableQueue($queue) {
- return in_array($queue, array('pending', 'nominated'));
- }
-
- /**
- * Get current sort order parameters for specified queue
- * @param string $queue name of queue
- * @param string $default return default filter instead of saved - defaults to false
- * @return array
- */
- function getQueueSort($queue, $default=false) {
- if (!$this->isSortableQueue($queue)) {
- return array();
- }
-
- $defaults = array(
- 'pending' => array('sortby'=>'age', 'direction'=>'ASC'),
- 'nominated' => array('sortby'=>'age', 'direction'=>'ASC'),
- );
-
- if (!$default) {
- $queue_sorts = $this->controller->Session->read('editor_queue_sorts');
- if (isset($queue_sorts[$queue])) {
- return $queue_sorts[$queue];
- }
- }
-
- return $defaults[$queue];
- }
-
- /**
- * Set sort order parameters on specified queue
- * @param string $queue
- * @param string $sortby
- * @param string $direction
- * @return bool
- */
- function setQueueSort($queue, $sortby='default', $direction='default') {
- if (!$this->isSortableQueue($queue)) {
- return array();
- }
-
- // valid sorts for the queues, each sort containing default directions
- $validSorts = array(
- 'pending' => array(
- 'age' => array('direction'=>'ASC'),
- 'type' => array('direction'=>'ASC'),
- 'name' => array('direction'=>'ASC'),
- ),
- 'nominated' => array(
- 'age' => array('direction'=>'ASC'),
- 'type' => array('direction'=>'ASC'),
- 'name' => array('direction'=>'ASC'),
- ),
- );
-
- $queueSorts = $this->controller->Session->read('editor_queue_sorts');
- if (!is_array($queueSorts)) {
- $queueSorts = array();
- }
-
- // reset to default
- if ($sortby == 'default') {
- unset($queueSorts[$queue]);
- $this->controller->Session->write('editor_queue_sorts', $queueSorts);
-
- // set to a known sort
- } elseif (array_key_exists($sortby, $validSorts[$queue])) {
- $newSort = $validSorts[$queue][$sortby];
- $newSort['sortby'] = $sortby;
- // use default direction unless...
- if (in_array(strtoupper($direction), array('DESC', 'ASC'))) {
- $newSort['direction'] = strtoupper($direction);
- }
- $queueSorts[$queue] = $newSort;
- $this->controller->Session->write('editor_queue_sorts', $queueSorts);
-
- // unknown sort
- } else {
- return false;
- }
-
- return true;
}
}
?>