From 14569ae4918e1d8c024909fef89299842e24c5ca Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 4 Mar 2013 13:45:51 -0800 Subject: [PATCH] Add a user-accessible hook for dumping debug code into an install Summary: Currently, there's no easy way for me to tell a user "run this code from the webserver and tell me what it says". Sometimes installs can add new .php files to, e.g., `webroot/rsrc/`, but this is setup-dependent and not universal. Generally I resort to saying "put this into index.php", but that's error prone and not acceptable on active installs. Add a "debug" controller so I can instead say "put this into support/debug.php, then visit /debug/". Test Plan: Visited /debug/ with and without support/debug.php files. Visited /staus/. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D5212 --- .gitignore | 3 ++ src/__phutil_library_map__.php | 4 +- ...AphrontDefaultApplicationConfiguration.php | 2 + .../system/PhabricatorDebugController.php | 39 +++++++++++++++++++ .../PhabricatorStatusController.php | 0 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/applications/system/PhabricatorDebugController.php rename src/applications/{status => system}/PhabricatorStatusController.php (100%) diff --git a/.gitignore b/.gitignore index d176eb3a03..1389147b3b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ # Impact Font /resources/font/impact.ttf + +# User-accessible hook for adhoc debugging scripts +/support/debug.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f9098d0322..fb189ffb9a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -831,6 +831,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonLogListView' => 'applications/daemon/view/PhabricatorDaemonLogListView.php', 'PhabricatorDaemonLogViewController' => 'applications/daemon/controller/PhabricatorDaemonLogViewController.php', 'PhabricatorDaemonReference' => 'infrastructure/daemon/control/PhabricatorDaemonReference.php', + 'PhabricatorDebugController' => 'applications/system/PhabricatorDebugController.php', 'PhabricatorDefaultFileStorageEngineSelector' => 'applications/files/engineselector/PhabricatorDefaultFileStorageEngineSelector.php', 'PhabricatorDefaultSearchEngineSelector' => 'applications/search/selector/PhabricatorDefaultSearchEngineSelector.php', 'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php', @@ -1307,7 +1308,7 @@ phutil_register_library_map(array( 'PhabricatorSortTableExample' => 'applications/uiexample/examples/PhabricatorSortTableExample.php', 'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php', 'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php', - 'PhabricatorStatusController' => 'applications/status/PhabricatorStatusController.php', + 'PhabricatorStatusController' => 'applications/system/PhabricatorStatusController.php', 'PhabricatorStorageFixtureScopeGuard' => 'infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php', 'PhabricatorStorageManagementAPI' => 'infrastructure/storage/management/PhabricatorStorageManagementAPI.php', 'PhabricatorStorageManagementDatabasesWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementDatabasesWorkflow.php', @@ -2337,6 +2338,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonLogListController' => 'PhabricatorDaemonController', 'PhabricatorDaemonLogListView' => 'AphrontView', 'PhabricatorDaemonLogViewController' => 'PhabricatorDaemonController', + 'PhabricatorDebugController' => 'PhabricatorController', 'PhabricatorDefaultFileStorageEngineSelector' => 'PhabricatorFileStorageEngineSelector', 'PhabricatorDefaultSearchEngineSelector' => 'PhabricatorSearchEngineSelector', 'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions', diff --git a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php index df85f35030..2b905038dd 100644 --- a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php @@ -109,6 +109,8 @@ class AphrontDefaultApplicationConfiguration 'testpaymentform/' => 'PhortuneStripeTestPaymentFormController', ), ), + + '/debug/' => 'PhabricatorDebugController', ); } diff --git a/src/applications/system/PhabricatorDebugController.php b/src/applications/system/PhabricatorDebugController.php new file mode 100644 index 0000000000..e26dd0e6c9 --- /dev/null +++ b/src/applications/system/PhabricatorDebugController.php @@ -0,0 +1,39 @@ +getDebugFilePath())) { + return new Aphront404Response(); + } + + $request = $this->getRequest(); + $user = $request->getUser(); + + ob_start(); + require_once $this->getDebugFilePath(); + $out = ob_get_clean(); + + $response = new AphrontWebpageResponse(); + $response->setContent(hsprintf('
%s
', $out)); + return $response; + } + + private function getDebugFilePath() { + $root = dirname(phutil_get_library_root('phabricator')); + return $root.'/support/debug.php'; + } +} diff --git a/src/applications/status/PhabricatorStatusController.php b/src/applications/system/PhabricatorStatusController.php similarity index 100% rename from src/applications/status/PhabricatorStatusController.php rename to src/applications/system/PhabricatorStatusController.php