Summary: Starting with a new instance running PHP 8.2, address all exceptions that come up through some basic browsing/usage. For `strlen(null)` issues I generally tried to resolve if the value should be non-null at the point of issue, and attempt to address at earlier call-site. There were not many of these that I could determine. In the rest of those cases I would replace with a null-and-strlen check, or use `phutil_nonempty_string` if I was certain the value was a string and it was more convenient. Hitting all code-paths is challenging, so I would search for `strlen` within radius of files I was modifying and evaluate to address those uses in the same manner. Notes: - `AphrontRequest::getStr` only ever returns a string, and is safe to use `phutil_nonempty_string`. - `PhabricatorEnv::getEnvConfig` can return non-string things so any values coming from there should never use `phutil_nonempty_string`. - `AphrontRequest::getHTTPHeader` indicates it could return wild so `phutil_nonempty_string` should not be used. - `AphrontRequest::getURIData` isn't clear if it could return non-string data, so never use `phutil_nonempty_string`. Refs T13588 Test Plan: I'm running an instance on 8.2 and went through the basic setup/installation, startup and usage, including setup issues and configurations/settings. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: aklapper, Korvin, epriestley Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21862
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
final class DarkConsoleController extends PhabricatorController {
|
|
|
|
protected $op;
|
|
protected $data;
|
|
|
|
public function shouldRequireLogin() {
|
|
return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
|
|
}
|
|
|
|
public function shouldRequireEnabledUser() {
|
|
return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
|
|
}
|
|
|
|
public function shouldAllowPartialSessions() {
|
|
return true;
|
|
}
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $this->getViewer();
|
|
$response = id(new AphrontAjaxResponse())->setDisableConsole(true);
|
|
|
|
if (!$viewer->isLoggedIn()) {
|
|
return $response;
|
|
}
|
|
|
|
$visible = $request->getStr('visible');
|
|
if (phutil_nonempty_string($visible)) {
|
|
$this->writeDarkConsoleSetting(
|
|
PhabricatorDarkConsoleVisibleSetting::SETTINGKEY,
|
|
(int)$visible);
|
|
return $response;
|
|
}
|
|
|
|
$tab = $request->getStr('tab');
|
|
if (phutil_nonempty_string($tab)) {
|
|
$this->writeDarkConsoleSetting(
|
|
PhabricatorDarkConsoleTabSetting::SETTINGKEY,
|
|
$tab);
|
|
return $response;
|
|
}
|
|
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
private function writeDarkConsoleSetting($key, $value) {
|
|
$viewer = $this->getViewer();
|
|
$request = $this->getRequest();
|
|
|
|
$preferences = PhabricatorUserPreferences::loadUserPreferences($viewer);
|
|
|
|
$editor = id(new PhabricatorUserPreferencesEditor())
|
|
->setActor($viewer)
|
|
->setContentSourceFromRequest($request)
|
|
->setContinueOnNoEffect(true)
|
|
->setContinueOnMissingFields(true);
|
|
|
|
$xactions = array();
|
|
$xactions[] = $preferences->newTransaction($key, $value);
|
|
$editor->applyTransactions($preferences, $xactions);
|
|
|
|
// Reload the user to regenerate their preferences cache. If we don't
|
|
// do this, the "Services" tab gets misleadingly spammed up with cache
|
|
// fills that are only filling because you toggled the console or switched
|
|
// tabs. This makes it harder to see what's really going on, so just force
|
|
// a cache regeneration here.
|
|
id(new PhabricatorPeopleQuery())
|
|
->setViewer($viewer)
|
|
->withPHIDs(array($viewer->getPHID()))
|
|
->needUserSettings(true)
|
|
->execute();
|
|
}
|
|
|
|
}
|