@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DarkConsoleController extends PhabricatorController {
4
5 protected $op;
6 protected $data;
7
8 public function shouldRequireLogin() {
9 return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
10 }
11
12 public function shouldRequireEnabledUser() {
13 return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
14 }
15
16 public function shouldAllowPartialSessions() {
17 return true;
18 }
19
20 public function handleRequest(AphrontRequest $request) {
21 $viewer = $this->getViewer();
22 $response = id(new AphrontAjaxResponse())->setDisableConsole(true);
23
24 if (!$viewer->isLoggedIn()) {
25 return $response;
26 }
27
28 // This should be '0' when closed and '1' when opened
29 $visible = $request->getStr('visible');
30 if (phutil_nonempty_string($visible)) {
31 $this->writeDarkConsoleSetting(
32 PhabricatorDarkConsoleVisibleSetting::SETTINGKEY,
33 (int)$visible);
34 return $response;
35 }
36
37 $tab = $request->getStr('tab');
38 if (phutil_nonempty_string($tab)) {
39 $this->writeDarkConsoleSetting(
40 PhabricatorDarkConsoleTabSetting::SETTINGKEY,
41 $tab);
42 return $response;
43 }
44
45 return new Aphront404Response();
46 }
47
48 private function writeDarkConsoleSetting($key, $value) {
49 $viewer = $this->getViewer();
50 $request = $this->getRequest();
51
52 $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer);
53
54 $editor = id(new PhabricatorUserPreferencesEditor())
55 ->setActor($viewer)
56 ->setContentSourceFromRequest($request)
57 ->setContinueOnNoEffect(true)
58 ->setContinueOnMissingFields(true);
59
60 $xactions = array();
61 $xactions[] = $preferences->newTransaction($key, $value);
62 $editor->applyTransactions($preferences, $xactions);
63
64 // Reload the user to regenerate their preferences cache. If we don't
65 // do this, the "Services" tab gets misleadingly spammed up with cache
66 // fills that are only filling because you toggled the console or switched
67 // tabs. This makes it harder to see what's really going on, so just force
68 // a cache regeneration here.
69 id(new PhabricatorPeopleQuery())
70 ->setViewer($viewer)
71 ->withPHIDs(array($viewer->getPHID()))
72 ->needUserSettings(true)
73 ->execute();
74 }
75
76}