diff options
Diffstat (limited to 'site/app/controllers/developers_controller.php')
-rw-r--r-- | site/app/controllers/developers_controller.php | 127 |
1 files changed, 106 insertions, 21 deletions
diff --git a/site/app/controllers/developers_controller.php b/site/app/controllers/developers_controller.php index b46bcd1..8ff0a4f 100644 --- a/site/app/controllers/developers_controller.php +++ b/site/app/controllers/developers_controller.php @@ -40,8 +40,11 @@ require_once('Archive/Zip.php'); class DevelopersController extends AppController { var $name = 'Developers'; - var $uses = array('Addon', 'Addontype', 'Application', 'Appversion', 'Eventlog', 'File', 'Platform', 'Preview', 'Review', 'Tag', 'Translation', 'User', 'Version'); - var $components = array('Amo', 'Developers', 'Error', 'Image', 'Opensearch', 'Rdf', 'Src', 'Versioncompare'); + var $uses = array('Addon', 'Addontype', 'Application', 'Approval', 'Appversion', + 'EditorSubscription', 'Eventlog', 'File', 'Platform', 'Preview', 'Review', + 'Tag', 'Translation', 'User', 'Version'); + var $components = array('Amo', 'Developers', 'Editors', 'Email', 'Error', + 'Image', 'Opensearch', 'Rdf', 'Src', 'Versioncompare'); var $helpers = array('Html', 'Javascript', 'Ajax', 'Link', 'Listing', 'Localization', 'Form'); var $addVars = array(); //variables accessible to all additem steps @@ -226,7 +229,7 @@ class DevelopersController extends AppController if (!in_array($data['Addon']['addontype_id'], array(ADDON_SEARCH, ADDON_ACTIVITY))) { // Make sure GUID doesn't exist already if ($existing = $this->Addon->findAll("Addon.guid='{$data['Addon']['guid']}'")) { - return $this->Error->getJSONforError(sprintf('This add-on ID (%1$s) already exists in the database. If this is your add-on, you can <a href="%2$s">upload a new version</a>.', $data['Addon']['guid'], $this->url("/developers/versions/add/{$existing[0]['Addon']['id']}"))); + return $this->Error->getJSONforError(sprintf(___('devcp_new_addon_error'), $data['Addon']['guid'], $this->url("/developers/versions/add/{$existing[0]['Addon']['id']}"))); } } @@ -296,7 +299,7 @@ class DevelopersController extends AppController // Make sure user has upload permissions $role = $this->Amo->getAuthorRole($addon_id); if (empty($role) || $role < AUTHOR_ROLE_DEV) { - return $this->Error->getJSONforError('You do not have sufficient privileges to update this add-on.'); + return $this->Error->getJSONforError(___('devcp_update_addon_priv_error')); } $addon = $this->Addon->findById($addon_id); @@ -305,7 +308,7 @@ class DevelopersController extends AppController if ($data['Addon']['addontype_id'] != ADDON_SEARCH) { // Make sure GUID matches add-on ID if ($addon['Addon']['guid'] != $data['Addon']['guid']) { - return $this->Error->getJSONforError(sprintf('The add-on GUID used in this file (%1$s) does not match the existing GUID for this add-on (%2$s).', $data['Addon']['guid'], $addon['Addon']['guid'])); + return $this->Error->getJSONforError(sprintf(___('devcp_update_addon_guid_error'), $data['Addon']['guid'], $addon['Addon']['guid'])); } } @@ -313,7 +316,7 @@ class DevelopersController extends AppController // Make sure version doesn't exist already $vcheck = $this->Version->find("Version.addon_id={$addon_id} AND Version.version='{$data['Version']['version']}'"); if (!empty($vcheck)) { - return $this->Error->getJSONforError(sprintf('The version number uploaded (%1$s) already exists for this add-on. If you are trying to add another file to this version, <a href="%2$s">click here</a>.', $data['Version']['version'], $this->url('/developers/versions/addfile/'.$vcheck['Version']['id']))); + return $this->Error->getJSONforError(sprintf(___('devcp_update_addon_version_exists_error'), $data['Version']['version'], $this->url('/developers/versions/addfile/'.$vcheck['Version']['id']))); } @@ -334,6 +337,9 @@ class DevelopersController extends AppController $this->Version->addCompatibleApp($version_id, $appversion['application_id'], $appversion['min'], $appversion['max']); } } + + // notify subscribed editors of update (if any) + $this->Editors->updateNotify($addon['Addon']['id'], $version_id); } elseif ($type == 'file') { $version_id = $this->data['Version']['id']; @@ -341,12 +347,13 @@ class DevelopersController extends AppController // Make sure version id belongs to this add-on $vcheck = $this->Version->find("Version.id={$version_id} AND Version.addon_id={$addon_id}"); if (empty($vcheck)) { + return $this->Error->getJSONforError(sprintf(___('devcp_update_addon_version_belong_error'), $version_id, $addon_id)); return $this->Error->getJSONforError(sprintf('The specified version (%1$s) does not belong to this add-on (%2$s).', $version_id, $addon_id)); } // Make sure version number matches if ($vcheck['Version']['version'] != $data['Version']['version']) { - return $this->Error->getJSONforError(sprintf('The uploaded version number (%1$s) does not match the existing version number (%2$s).', $data['Version']['version'], $vcheck['Version']['version'])); + return $this->Error->getJSONforError(sprintf(___('devcp_update_addon_version_match_error'), $data['Version']['version'], $vcheck['Version']['version'])); } } $data['Version']['id'] = $version_id; @@ -560,7 +567,7 @@ class DevelopersController extends AppController ); } else { - return $this->Error->getJSONforError('No account found for that email address.'); + return $this->Error->getJSONforError(___('devcp_verify_author_error')); } } @@ -900,7 +907,7 @@ class DevelopersController extends AppController function _addonStatusAction($action) { $this->publish('subaction', $action); - $addon = $this->Addon->findById($this->viewVars['addon_id'], array('addontype_id', 'nominationmessage', 'status', 'higheststatus'), null, -1); + $addon = $this->Addon->findById($this->viewVars['addon_id'], array('id', 'addontype_id', 'nominationmessage', 'status', 'higheststatus'), null, -1); $this->publish('addon', $addon); // Complete an add-on @@ -960,6 +967,11 @@ class DevelopersController extends AppController $addonData = array('status' => STATUS_NOMINATED, 'nominationmessage' => $this->params['form']['data']['Addon']['nominationmessage']); $this->Addon->save($addonData); $this->publish('success', true); + + // notify subscribed editors of update + global $valid_status; + $version_id = $this->Version->getVersionByAddonId($addon['Addon']['id'], $valid_status); + $this->Editors->updateNotify($addon['Addon']['id'], $version_id); } } @@ -1079,7 +1091,7 @@ class DevelopersController extends AppController // Make sure user has permission if ($this->viewVars['author_role'] < AUTHOR_ROLE_DEV) { - $this->flash('You do not have privileges to delete versions or files.', '/developers/versions/edit/'.$version_id, 6); + $this->flash(___('devcp_delete_version_priv_error'), '/developers/versions/edit/'.$version_id, 6); return; } @@ -1290,7 +1302,7 @@ class DevelopersController extends AppController // flush cached add-on objects if (QUERY_CACHE) $this->Addon->Cache->markListForFlush("addon:{$addon_id}"); - $messages['success'][] = 'Please note that some changes may take several hours to appear in all areas of the website.'; + $messages['success'][] = ___('devcp_several_hours'); $this->publish('messages', $messages); } @@ -1335,7 +1347,7 @@ class DevelopersController extends AppController // Check for allowed file extensions $extension = strtolower(substr($name, strrpos($name, '.'))); if (!in_array($extension, $this->Developers->imageExtensions)) { - $return['errors'][] = sprintf('File %1$s has an invalid extension (%2$s). Allowed extensions: %3$s', $name, $extension, implode(', ', $this->Developers->imageExtensions)); + $return['errors'][] = sprintf(___('devcp_add_previews_extension_error'), $name, $extension, implode(', ', $this->Developers->imageExtensions)); continue; } @@ -1363,12 +1375,12 @@ class DevelopersController extends AppController // Save preview to db if ($this->Preview->save($previewData)) { if (in_array($id, $existing)) - $return['success'][] = sprintf('Preview %1$s was replaced with file %2$s successfully.', $id, $name); + $return['success'][] = sprintf(___('devcp_add_previews_success_replace'), $id, $name); else - $return['success'][] = sprintf('File %s was uploaded successfully. You can add a caption below.', $name); + $return['success'][] = sprintf(___('devcp_add_previews_success_upload'), $name); } else - $return['errors'][] = sprintf('File %s could not be saved to the database. Please try again.', $name); + $return['errors'][] = sprintf(___('devcp_add_previews_save_error'), $name); } return $return; @@ -1387,14 +1399,87 @@ class DevelopersController extends AppController // Delete the preview $this->Preview->id = $id; if ($this->Preview->delete()) - $return['success'][] = sprintf('Preview %s has been deleted successfully.', $id); + $return['success'][] = sprintf(___('devcp_delete_previews_success'), $id); else - $return['errors'][] = sprintf('Preview %s could not be deleted from the database. Please try again.', $id); + $return['errors'][] = sprintf(___('devcp_delete_previews_error'), $id); } return $return; } + /** + * Discuss a review request with an editor + */ + function discuss($infoid) { + global $valid_status; + + $inforequest = $this->Approval->findById($infoid); + if (empty($inforequest)) { + $this->flash(_('error_addon_notfound'), '/developers/index'); + return; + } + // Make sure user has some permissions to view this add-on + $role = $this->Amo->getAuthorRole($inforequest['Approval']['addon_id']); + if (empty($role)) $this->Amo->accessDenied(); + + $this->publish('inforequest', $inforequest); + + $addon = $this->Addon->getAddon($inforequest['Approval']['addon_id'], array('authors')); + $this->publish('addonName', $addon['Translation']['name']['string']); + + $versionid = $this->Version->getVersionByAddonId($addon['Addon']['id'], $valid_status); + $version = $this->Version->findById($versionid, null, null, -1); + $this->publish('versionno', $version['Version']['version']); + + // grab replies + $replies = $this->Approval->findAll(array('reply_to' => $infoid), null, 'Approval.created'); + $this->publish('replies', $replies); + + if (!empty($this->data)) { + $session = $this->Session->read('User'); + + // reply submitted + $approvalData = array( + 'user_id' => $session['id'], + 'reviewtype' => 'info', + 'action' => 0, + 'reply_to' => $infoid, + 'addon_id' => $addon['Addon']['id'], + 'comments' => $this->data['Approval']['comments'] + ); + if (true === $this->Approval->save($approvalData)) { + $this->set('success', true); + + // add this to the replies set + $replies[] = $this->Approval->findById($this->Approval->getLastInsertID()); + $this->publish('replies', $replies); + + // send email to all authors and the editor, but not the current user + $recipients = array(); + foreach ($addon['User'] as &$user) $recipients[] = $user['email']; + $recipients[] = $inforequest['User']['email']; + foreach ($replies as &$reply) $recipients[] = $reply['User']['email']; + $recipients = array_diff(array_unique($recipients), array($session['email'])); // remove current user + + $emailInfo = array( + 'name' => $addon['Translation']['name']['string'], + 'infoid' => $infoid, + 'sender' => $session['firstname'].' '.$session['lastname'], + 'comments' => $this->data['Approval']['comments'], + 'version' => !empty($version) ? $version['Version']['version'] : '' + ); + $this->publish('info', $emailInfo, false); + $this->Email->template = '../editors/email/inforequest_reply'; + $this->Email->subject = sprintf('Mozilla Add-ons: %s %s', $emailInfo['name'], $emailInfo['version']); + foreach ($recipients as &$recipient) { + $this->Email->to = $recipient; + $this->Email->send(); + } + } + } + $this->render(); + } + /** * Index */ @@ -2391,10 +2476,10 @@ class DevelopersController extends AppController //Update/insert icon if (!empty($this->data['Addon']['icon']['name'])) { - $fileErrors = array('1' => _('Exceeds maximum upload size'), - '2' => _('Exceeds maximum upload size'), - '3' => _('Incomplete transfer'), - '4' => _('No file uploaded') + $fileErrors = array('1' => ___('devcp_edit_file_error_size'), + '2' => ___('devcp_edit_file_error_size'), + '3' => ___('devcp_edit_file_error_incomplete'), + '4' => ___('devcp_edit_file_error_no') ); $allowedImage = array('.png', '.jpg', '.gif'); |