mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Show Deprecation Warnings as Setup Warnings
Summary: Capture Deprecation Warnings, collect them into cache, and show them as a Setup Issue for admins to see and report back to us. This only captures a sample of the traces, so not to overwhelm users (and RAM. and us) with reports. Requires D25388. Refs T15554. Test Plan: Run some flows that are known to bring up Deprecation Warnings. See them as a Setup Issue! Click little triangles to see details. Reviewers: O1 Blessed Committers, Matthew Reviewed By: O1 Blessed Committers, Matthew Subscribers: revi, Sten, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15554 Differential Revision: https://we.phorge.it/D25440
This commit is contained in:
parent
c49eeb235e
commit
2ba2cbaf9b
4 changed files with 144 additions and 0 deletions
|
@ -5387,6 +5387,8 @@ phutil_register_library_map(array(
|
|||
'PholioTransactionType' => 'applications/pholio/xaction/PholioTransactionType.php',
|
||||
'PholioTransactionView' => 'applications/pholio/view/PholioTransactionView.php',
|
||||
'PholioUploadedImageView' => 'applications/pholio/view/PholioUploadedImageView.php',
|
||||
'PhorgeCodeWarningSetupCheck' => 'applications/config/check/PhorgeCodeWarningSetupCheck.php',
|
||||
'PhorgeSystemDeprecationWarningListener' => 'applications/system/events/PhorgeSystemDeprecationWarningListener.php',
|
||||
'PhortuneAccount' => 'applications/phortune/storage/PhortuneAccount.php',
|
||||
'PhortuneAccountAddManagerController' => 'applications/phortune/controller/account/PhortuneAccountAddManagerController.php',
|
||||
'PhortuneAccountBillingAddressTransaction' => 'applications/phortune/xaction/PhortuneAccountBillingAddressTransaction.php',
|
||||
|
@ -12208,6 +12210,8 @@ phutil_register_library_map(array(
|
|||
'PholioTransactionType' => 'PhabricatorModularTransactionType',
|
||||
'PholioTransactionView' => 'PhabricatorApplicationTransactionView',
|
||||
'PholioUploadedImageView' => 'AphrontView',
|
||||
'PhorgeCodeWarningSetupCheck' => 'PhabricatorSetupCheck',
|
||||
'PhorgeSystemDeprecationWarningListener' => 'PhabricatorEventListener',
|
||||
'PhortuneAccount' => array(
|
||||
'PhortuneDAO',
|
||||
'PhabricatorApplicationTransactionInterface',
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
final class PhorgeCodeWarningSetupCheck extends PhabricatorSetupCheck {
|
||||
|
||||
public function getExecutionOrder() {
|
||||
return 2000;
|
||||
}
|
||||
|
||||
public function getDefaultGroup() {
|
||||
return self::GROUP_OTHER;
|
||||
}
|
||||
|
||||
protected function executeChecks() {
|
||||
$warnings = (new PhorgeSystemDeprecationWarningListener())->getWarnings();
|
||||
if (!$warnings) {
|
||||
return;
|
||||
}
|
||||
|
||||
$link = phutil_tag(
|
||||
'a',
|
||||
array('href' => 'https://we.phorge.it/w/docs/report-warnings/'),
|
||||
pht('%s\'s home page', PlatformSymbols::getPlatformServerName()));
|
||||
|
||||
$message = pht(
|
||||
'There is some deprecated code found in the %s code-base.'.
|
||||
"\n\n".
|
||||
"This isn't a problem yet, but it means that %s might stop working if ".
|
||||
'you upgrade PHP version.'.
|
||||
"\n\n".
|
||||
'This page records a sample of the cases since last server restart. '.
|
||||
"\n\n".
|
||||
'To solve this issue, either:'.
|
||||
"\n\n".
|
||||
'- Visit %s, file bug report with the information below, or'.
|
||||
"\n".
|
||||
'- Ignore this issue using the `Ignore` button below.'.
|
||||
"\n\n",
|
||||
PlatformSymbols::getPlatformServerName(),
|
||||
PlatformSymbols::getPlatformServerName(),
|
||||
$link);
|
||||
$message = array($message);
|
||||
|
||||
$message[] = pht('PHP version: %s', phpversion());
|
||||
$message[] = "\n\n";
|
||||
|
||||
$message[] = pht('Recorded items (sample):');
|
||||
$list = array();
|
||||
$warnings = array_reverse(isort($warnings, 'counter'));
|
||||
foreach ($warnings as $key => $data) {
|
||||
$summary = pht(
|
||||
'%s, occurrences: %s',
|
||||
$key,
|
||||
$data['counter']);
|
||||
|
||||
$trace = phutil_tag('tt', array(),
|
||||
array($data['message'] , "\n", $data['trace']));
|
||||
|
||||
$list[] = phutil_tag(
|
||||
'li',
|
||||
array(),
|
||||
phutil_tag(
|
||||
'details',
|
||||
array(),
|
||||
array(
|
||||
phutil_tag('summary', array(), $summary),
|
||||
$trace,
|
||||
)));
|
||||
}
|
||||
$message[] = phutil_tag('ul', array(), $list);
|
||||
|
||||
|
||||
$this->newIssue('deprecations')
|
||||
->setName(pht('Deprecated Code'))
|
||||
->setMessage($message)
|
||||
->setSummary(pht('There is some deprecated code found in the code-base.'))
|
||||
->addLink(
|
||||
'https://we.phorge.it/w/docs/report-warnings/',
|
||||
'More Details on the website');
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ final class PhabricatorSystemApplication extends PhabricatorApplication {
|
|||
public function getEventListeners() {
|
||||
return array(
|
||||
new PhabricatorSystemDebugUIEventListener(),
|
||||
new PhorgeSystemDeprecationWarningListener(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
final class PhorgeSystemDeprecationWarningListener
|
||||
extends PhabricatorEventListener {
|
||||
|
||||
const CACHE_KEY = 'setup-check:deprecation-warnings';
|
||||
const MAX_ENTRIES = 5;
|
||||
|
||||
public function handleEvent(PhutilEvent $event) {
|
||||
// we're not an actual PhutilEventListener - we're just using the `register`
|
||||
// part of that framework.
|
||||
}
|
||||
|
||||
public function register() {
|
||||
PhutilErrorHandler::addErrorListener(
|
||||
array($this, 'handleErrors'));
|
||||
}
|
||||
|
||||
public function handleErrors($event, $value, $metadata) {
|
||||
|
||||
if ($event !== PhutilErrorHandler::DEPRECATED) {
|
||||
return;
|
||||
}
|
||||
|
||||
$trace_key = sprintf(
|
||||
'%s:%s',
|
||||
basename($metadata['file']),
|
||||
$metadata['line']);
|
||||
|
||||
$cache = PhabricatorCaches::getRuntimeCache();
|
||||
$cache_entry = $cache->getKey(self::CACHE_KEY);
|
||||
|
||||
if (!$cache_entry) {
|
||||
$cache_entry = array();
|
||||
}
|
||||
|
||||
$trace_entry = idx($cache_entry, $trace_key);
|
||||
|
||||
if ($trace_entry) {
|
||||
$trace_entry['counter']++;
|
||||
} else {
|
||||
$trace_entry = array(
|
||||
'counter' => 1,
|
||||
'message' => $value,
|
||||
'trace' => PhutilErrorHandler::formatStacktrace($metadata['trace']),
|
||||
);
|
||||
}
|
||||
$cache_entry[$trace_key] = $trace_entry;
|
||||
|
||||
$cache->setKey(self::CACHE_KEY , $cache_entry);
|
||||
}
|
||||
|
||||
public function getWarnings() {
|
||||
$cache = PhabricatorCaches::getRuntimeCache();
|
||||
return $cache->getKey(self::CACHE_KEY);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue