Browse files

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
  • Loading branch information...
1 parent 413c65b commit 14569ae4918e1d8c024909fef89299842e24c5ca @epriestley epriestley committed Mar 4, 2013
View
3 .gitignore
@@ -27,3 +27,6 @@
# Impact Font
/resources/font/impact.ttf
+
+# User-accessible hook for adhoc debugging scripts
+/support/debug.php
View
4 src/__phutil_library_map__.php
@@ -831,6 +831,7 @@
'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 @@
'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 @@
'PhabricatorDaemonLogListController' => 'PhabricatorDaemonController',
'PhabricatorDaemonLogListView' => 'AphrontView',
'PhabricatorDaemonLogViewController' => 'PhabricatorDaemonController',
+ 'PhabricatorDebugController' => 'PhabricatorController',
'PhabricatorDefaultFileStorageEngineSelector' => 'PhabricatorFileStorageEngineSelector',
'PhabricatorDefaultSearchEngineSelector' => 'PhabricatorSearchEngineSelector',
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
View
2 src/aphront/configuration/AphrontDefaultApplicationConfiguration.php
@@ -109,6 +109,8 @@ public function getURIMap() {
'testpaymentform/' => 'PhortuneStripeTestPaymentFormController',
),
),
+
+ '/debug/' => 'PhabricatorDebugController',
);
}
View
39 src/applications/system/PhabricatorDebugController.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * This controller eases debugging of application problems that don't repro
+ * locally by allowing installs to add arbitrary debugging code easily. To use
+ * it:
+ *
+ * - Write some diagnostic script.
+ * - Instruct the user to install it in `/support/debug.php`.
+ * - Tell them to visit `/debug/`.
+ */
+final class PhabricatorDebugController extends PhabricatorController {
+
+ public function shouldRequireLogin() {
+ return false;
+ }
+
+ public function processRequest() {
+ if (!Filesystem::pathExists($this->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('<pre>%s</pre>', $out));
+ return $response;
+ }
+
+ private function getDebugFilePath() {
+ $root = dirname(phutil_get_library_root('phabricator'));
+ return $root.'/support/debug.php';
+ }
+}
View
0 ...ns/status/PhabricatorStatusController.php → ...ns/system/PhabricatorStatusController.php
File renamed without changes.

0 comments on commit 14569ae

Please sign in to comment.