Commit 86c399b6 authored by Joshua Spence's avatar Joshua Spence
Browse files

Rename `PhabricatorApplication` subclasses

Summary: Ref T5655. Some discussion in D9839. Generally speaking, `Phabricator{$name}Application` is clearer than `PhabricatorApplication{$name}`.

Test Plan:
# Pinned and uninstalled some applications.
# Applied patch and performed migrations.
# Verified that the pinned applications were still pinned and that the uninstalled applications were still uninstalled.
# Performed a sanity check on the database contents.

Reviewers: btrahan, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: hach-que, epriestley, Korvin

Maniphest Tasks: T5655

Differential Revision: https://secure.phabricator.com/D9982
parent 1649cf94
<?php
$applications = array(
'Audit',
'Auth',
'Calendar',
'ChatLog',
'Conduit',
'Config',
'Conpherence',
'Countdown',
'Daemons',
'Dashboard',
'Differential',
'Diffusion',
'Diviner',
'Doorkeeper',
'Drydock',
'Fact',
'Feed',
'Files',
'Flags',
'Harbormaster',
'Help',
'Herald',
'Home',
'Legalpad',
'Macro',
'MailingLists',
'Maniphest',
'Applications',
'MetaMTA',
'Notifications',
'Nuance',
'OAuthServer',
'Owners',
'Passphrase',
'Paste',
'People',
'Phame',
'Phlux',
'Pholio',
'Phortune',
'PHPAST',
'Phragment',
'Phrequent',
'Phriction',
'Policy',
'Ponder',
'Project',
'Releeph',
'Repositories',
'Search',
'Settings',
'Slowvote',
'Subscriptions',
'Support',
'System',
'Test',
'Tokens',
'Transactions',
'Typeahead',
'UIExamples',
'XHProf',
);
$map = array();
foreach ($applications as $application) {
$old_name = 'PhabricatorApplication'.$application;
$new_name = 'Phabricator'.$application.'Application';
$map[$old_name] = $new_name;
}
/* -( User preferences )--------------------------------------------------- */
echo "Migrating user preferences...\n";
$table = new PhabricatorUserPreferences();
$conn_w = $table->establishConnection('w');
$pref_pinned = PhabricatorUserPreferences::PREFERENCE_APP_PINNED;
foreach (new LiskMigrationIterator(new PhabricatorUser()) as $user) {
$user_preferences = $user->loadPreferences();
$old_pinned_apps = $user_preferences->getPreference($pref_pinned);
$new_pinned_apps = array();
if (!$old_pinned_apps) {
continue;
}
foreach ($old_pinned_apps as $pinned_app) {
$new_pinned_apps[] = idx($map, $pinned_app, $pinned_app);
}
$user_preferences
->setPreference($pref_pinned, $new_pinned_apps);
queryfx(
$conn_w,
'UPDATE %T SET preferences = %s WHERE id = %d',
$user_preferences->getTableName(),
json_encode($user_preferences->getPreferences()),
$user_preferences->getID());
}
/* -( Dashboard installs )------------------------------------------------- */
echo "Migrating dashboard installs...\n";
$table = new PhabricatorDashboardInstall();
$conn_w = $table->establishConnection('w');
foreach (new LiskMigrationIterator($table) as $dashboard_install) {
$application = $dashboard_install->getApplicationClass();
queryfx(
$conn_w,
'UPDATE %T SET applicationClass = %s WHERE id = %d',
$table->getTableName(),
idx($map, $application, $application),
$dashboard_install->getID());
}
/* -( Phabricator configuration )------------------------------------------ */
$config_key = 'phabricator.uninstalled-applications';
echo "Migrating `{$config_key}` config...\n";
$config = PhabricatorConfigEntry::loadConfigEntry($config_key);
$old_config = $config->getValue();
$new_config = array();
if ($old_config) {
foreach ($old_config as $application => $uninstalled) {
$new_config[idx($map, $application, $application)] = $uninstalled;
}
$config
->setIsDeleted(0)
->setValue($new_config)
->save();
}
/* -( phabricator.application-settings )----------------------------------- */
$config_key = 'phabricator.application-settings';
echo "Migrating `{$config_key}` config...\n";
$config = PhabricatorConfigEntry::loadConfigEntry($config_key);
$old_config = $config->getValue();
$new_config = array();
if ($old_config) {
foreach ($old_config as $application => $settings) {
$application = preg_replace('/^PHID-APPS-/', '', $application);
$new_config['PHID-APPS-'.idx($map, $application, $application)] = $settings;
}
$config
->setIsDeleted(0)
->setValue($new_config)
->save();
}
This diff is collapsed.
......@@ -8,9 +8,7 @@
class AphrontDefaultApplicationConfiguration
extends AphrontApplicationConfiguration {
public function __construct() {
}
public function __construct() {}
public function getApplicationName() {
return 'aphront-default';
......@@ -172,7 +170,6 @@ class AphrontDefaultApplicationConfiguration
}
if ($ex instanceof PhabricatorPolicyException) {
if (!$user->isLoggedIn()) {
// If the user isn't logged in, just give them a login form. This is
// probably a generally more useful response than a policy dialog that
......@@ -182,7 +179,7 @@ class AphrontDefaultApplicationConfiguration
// the thing you are trying to look at".
$login_controller = new PhabricatorAuthStartController($request);
$auth_app_class = 'PhabricatorApplicationAuth';
$auth_app_class = 'PhabricatorAuthApplication';
$auth_app = PhabricatorApplication::getByClass($auth_app_class);
$login_controller->setCurrentApplication($auth_app);
......@@ -247,7 +244,6 @@ class AphrontDefaultApplicationConfiguration
return $response;
}
// Always log the unhandled exception.
phlog($ex);
......
<?php
final class PhabricatorApplicationAudit extends PhabricatorApplication {
final class PhabricatorAuditApplication extends PhabricatorApplication {
public function getBaseURI() {
return '/audit/';
......@@ -24,7 +24,7 @@ final class PhabricatorApplicationAudit extends PhabricatorApplication {
public function getEventListeners() {
return array(
new AuditActionMenuEventListener()
new AuditActionMenuEventListener(),
);
}
......
......@@ -3,7 +3,7 @@
abstract class ConduitAPI_audit_Method extends ConduitAPIMethod {
public function getApplication() {
return PhabricatorApplication::getByClass('PhabricatorApplicationAudit');
return PhabricatorApplication::getByClass('PhabricatorAuditApplication');
}
}
......@@ -3,7 +3,7 @@
final class PhabricatorAuditMailReceiver extends PhabricatorObjectMailReceiver {
public function isEnabled() {
$app_class = 'PhabricatorApplicationAudit';
$app_class = 'PhabricatorAuditApplication';
return PhabricatorApplication::isClassInstalled($app_class);
}
......
<?php
final class PhabricatorApplicationAuth extends PhabricatorApplication {
final class PhabricatorAuthApplication extends PhabricatorApplication {
public function canUninstall() {
return false;
......@@ -83,11 +83,11 @@ final class PhabricatorApplicationAuth extends PhabricatorApplication {
'new/' => 'PhabricatorAuthNewController',
'new/(?P<className>[^/]+)/' => 'PhabricatorAuthEditController',
'edit/(?P<id>\d+)/' => 'PhabricatorAuthEditController',
'(?P<action>enable|disable)/(?P<id>\d+)/' =>
'PhabricatorAuthDisableController',
'(?P<action>enable|disable)/(?P<id>\d+)/'
=> 'PhabricatorAuthDisableController',
),
'login/(?P<pkey>[^/]+)/(?:(?P<extra>[^/]+)/)?' =>
'PhabricatorAuthLoginController',
'login/(?P<pkey>[^/]+)/(?:(?P<extra>[^/]+)/)?'
=> 'PhabricatorAuthLoginController',
'register/(?:(?P<akey>[^/]+)/)?' => 'PhabricatorAuthRegisterController',
'start/' => 'PhabricatorAuthStartController',
'validate/' => 'PhabricatorAuthValidateController',
......@@ -120,8 +120,8 @@ final class PhabricatorApplicationAuth extends PhabricatorApplication {
'mustverify/' => 'PhabricatorMustVerifyEmailController',
),
'/emailverify/(?P<code>[^/]+)/' =>
'PhabricatorEmailVerificationController',
'/emailverify/(?P<code>[^/]+)/'
=> 'PhabricatorEmailVerificationController',
'/logout/' => 'PhabricatorLogoutController',
);
......
......@@ -93,8 +93,7 @@ abstract class PhabricatorAuthProvider {
throw new Exception(
pht(
"Two authentication providers use the same provider key ".
"('%s'). Each provider must be identified by a unique ".
"key.",
"('%s'). Each provider must be identified by a unique key.",
$key));
}
$providers[$key] = $object;
......@@ -147,24 +146,22 @@ abstract class PhabricatorAuthProvider {
}
/**
* Should we allow the adapter to be marked as "trusted"
* This is true for all adapters except those that allow the user to type in
* emails (@see PhabricatorPasswordAuthProvider)
* Should we allow the adapter to be marked as "trusted". This is true for
* all adapters except those that allow the user to type in emails (see
* @{class:PhabricatorPasswordAuthProvider}).
*/
public function shouldAllowEmailTrustConfiguration() {
return true;
}
public function buildLoginForm(
PhabricatorAuthStartController $controller) {
public function buildLoginForm(PhabricatorAuthStartController $controller) {
return $this->renderLoginForm($controller->getRequest(), $mode = 'start');
}
abstract public function processLoginRequest(
PhabricatorAuthLoginController $controller);
public function buildLinkForm(
PhabricatorAuthLinkController $controller) {
public function buildLinkForm(PhabricatorAuthLinkController $controller) {
return $this->renderLoginForm($controller->getRequest(), $mode = 'link');
}
......@@ -177,9 +174,7 @@ abstract class PhabricatorAuthProvider {
return $this->renderLoginForm($controller->getRequest(), $mode = 'refresh');
}
protected function renderLoginForm(
AphrontRequest $request,
$mode) {
protected function renderLoginForm(AphrontRequest $request, $mode) {
throw new PhutilMethodNotImplementedException();
}
......@@ -197,8 +192,7 @@ abstract class PhabricatorAuthProvider {
protected function loadOrCreateAccount($account_id) {
if (!strlen($account_id)) {
throw new Exception(
'loadOrCreateAccount(...): empty account ID!');
throw new Exception('loadOrCreateAccount(...): empty account ID!');
}
$adapter = $this->getAdapter();
......@@ -265,14 +259,14 @@ abstract class PhabricatorAuthProvider {
$this->willSaveAccount($account);
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$account->save();
$account->save();
unset($unguarded);
return $account;
}
public function getLoginURI() {
$app = PhabricatorApplication::getByClass('PhabricatorApplicationAuth');
$app = PhabricatorApplication::getByClass('PhabricatorAuthApplication');
return $app->getApplicationURI('/login/'.$this->getProviderKey().'/');
}
......@@ -281,7 +275,7 @@ abstract class PhabricatorAuthProvider {
}
public function getStartURI() {
$app = PhabricatorApplication::getByClass('PhabricatorApplicationAuth');
$app = PhabricatorApplication::getByClass('PhabricatorAuthApplication');
$uri = $app->getApplicationURI('/start/');
return $uri;
}
......@@ -339,6 +333,7 @@ abstract class PhabricatorAuthProvider {
AphrontFormView $form,
array $values,
array $issues) {
return;
}
......@@ -360,7 +355,6 @@ abstract class PhabricatorAuthProvider {
$account_view));
}
/**
* Return true to use a two-step configuration (setup, configure) instead of
* the default single-step configuration. In practice, this means that
......@@ -373,7 +367,6 @@ abstract class PhabricatorAuthProvider {
return false;
}
/**
* Render a standard login/register button element.
*
......
......@@ -97,7 +97,7 @@ final class PhabricatorAuthProviderConfigQuery
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationAuth';
return 'PhabricatorAuthApplication';
}
}
......@@ -106,7 +106,7 @@ final class PhabricatorAuthSessionQuery
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationAuth';
return 'PhabricatorAuthApplication';
}
}
......@@ -100,7 +100,7 @@ final class PhabricatorAuthTemporaryTokenQuery
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationAuth';
return 'PhabricatorAuthApplication';
}
}
<?php
/**
* NOTE: When loading ExternalAccounts for use in an authetication context (that
* is, you're going to act as the account or link identities or anything like
* that) you should require CAN_EDIT capability even if you aren't actually
* NOTE: When loading ExternalAccounts for use in an authentication context
* (that is, you're going to act as the account or link identities or anything
* like that) you should require CAN_EDIT capability even if you aren't actually
* editing the ExternalAccount.
*
* ExternalAccounts have a permissive CAN_VIEW policy (like users) because they
......@@ -174,7 +174,7 @@ final class PhabricatorExternalAccountQuery
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationPeople';
return 'PhabricatorPeopleApplication';
}
/**
......
......@@ -28,7 +28,22 @@ abstract class PhabricatorApplication implements PhabricatorPolicyInterface {
public function getName() {
return substr(get_class($this), strlen('PhabricatorApplication'));
// TODO: This is sort of gross.
$match = null;
$regex = '/^Phabricator([A-Z][a-zA-Z]*)Application$/';
if (preg_match($regex, get_class($this), $match)) {
return $match[1];
}
$regex = '/^PhabricatorApplication([A-Z][a-zA-Z]*)$/';
if (preg_match($regex, get_class($this), $match)) {
return $match[1];
}
throw new Exception('Unable to determine application name automagically.');
}
public function getShortDescription() {
......
......@@ -159,7 +159,7 @@ abstract class PhabricatorController extends AphrontController {
return $this->delegateToController($checker_controller);
}
$auth_class = 'PhabricatorApplicationAuth';
$auth_class = 'PhabricatorAuthApplication';
$auth_application = PhabricatorApplication::getByClass($auth_class);
// Require partial sessions to finish login before doing anything.
......@@ -231,7 +231,6 @@ abstract class PhabricatorController extends AphrontController {
if ($this->shouldRequireAdmin() && !$user->getIsAdmin()) {
return new Aphront403Response();
}
}
public function buildStandardPageView() {
......@@ -319,7 +318,6 @@ abstract class PhabricatorController extends AphrontController {
$seen = array();
while ($response instanceof AphrontProxyResponse) {
$hash = spl_object_hash($response);
if (isset($seen[$hash])) {
$seen[] = get_class($response);
......@@ -403,7 +401,6 @@ abstract class PhabricatorController extends AphrontController {
->execute();
}
/**
* Render a list of links to handles, identified by PHIDs. The handles must
* already be loaded.
......@@ -433,7 +430,6 @@ abstract class PhabricatorController extends AphrontController {
}
protected function buildApplicationCrumbs() {
$crumbs = array();
$application = $this->getCurrentApplication();
......@@ -516,7 +512,6 @@ abstract class PhabricatorController extends AphrontController {
return 'phabricator';
}
/**
* Create a new @{class:AphrontDialogView} with defaults filled in.
*
......
<?php
final class PhabricatorAccessControlTestCase
extends PhabricatorTestCase {
final class PhabricatorAccessControlTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
......@@ -201,7 +200,7 @@ final class PhabricatorAccessControlTestCase
$env->overrideEnvConfig('policy.allow-public', false);
$app = PhabricatorApplication::getByClass('PhabricatorApplicationTest');
$app = PhabricatorApplication::getByClass('PhabricatorTestApplication');
$app->reset();
$app->setPolicy(
PhabricatorPolicyCapability::CAN_VIEW,
......
<?php
final class PhabricatorApplicationTest extends PhabricatorApplication {
final class PhabricatorTestApplication extends PhabricatorApplication {
private $policies = array();
......@@ -30,8 +30,7 @@ final class PhabricatorApplicationTest extends PhabricatorApplication {
}
public function getRoutes() {
return array(
);
return array();
}
}
<?php
final class PhabricatorApplicationCalendar extends PhabricatorApplication {
final class PhabricatorCalendarApplication extends PhabricatorApplication {
public function getShortDescription() {
return pht('Upcoming Events');
......@@ -34,16 +34,16 @@ final class PhabricatorApplicationCalendar extends PhabricatorApplication {
'' => 'PhabricatorCalendarViewController',
'all/' => 'PhabricatorCalendarBrowseController',
'event/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' =>
'PhabricatorCalendarEventListController',
'create/' =>
'PhabricatorCalendarEventEditController',
'edit/(?P<id>[1-9]\d*)/' =>
'PhabricatorCalendarEventEditController',
'delete/(?P<id>[1-9]\d*)/' =>
'PhabricatorCalendarEventDeleteController',
'view/(?P<id>[1-9]\d*)/' =>
'PhabricatorCalendarEventViewController',
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorCalendarEventListController',
'create/'
=> 'PhabricatorCalendarEventEditController',
'edit/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventEditController',
'delete/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventDeleteController',
'view/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventViewController',
),
),
);
......
......@@ -105,7 +105,7 @@ final class PhabricatorCalendarEventQuery
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationCalendar';
return 'PhabricatorCalendarApplication';
}
}
......@@ -8,7 +8,7 @@ final class PhabricatorCalendarEventSearchEngine
}
public function getApplicationClassName() {
return 'PhabricatorApplicationCalendar';
return 'PhabricatorCalendarApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
......@@ -137,7 +137,6 @@ final class PhabricatorCalendarEventSearchEngine
1,
pht('Show only upcoming events.'),
$upcoming));
}
protected function getURI($path) {
......@@ -147,14 +146,13 @@ final class PhabricatorCalendarEventSearchEngine