@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

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

+144
+4
src/__phutil_library_map__.php
··· 5387 5387 'PholioTransactionType' => 'applications/pholio/xaction/PholioTransactionType.php', 5388 5388 'PholioTransactionView' => 'applications/pholio/view/PholioTransactionView.php', 5389 5389 'PholioUploadedImageView' => 'applications/pholio/view/PholioUploadedImageView.php', 5390 + 'PhorgeCodeWarningSetupCheck' => 'applications/config/check/PhorgeCodeWarningSetupCheck.php', 5391 + 'PhorgeSystemDeprecationWarningListener' => 'applications/system/events/PhorgeSystemDeprecationWarningListener.php', 5390 5392 'PhortuneAccount' => 'applications/phortune/storage/PhortuneAccount.php', 5391 5393 'PhortuneAccountAddManagerController' => 'applications/phortune/controller/account/PhortuneAccountAddManagerController.php', 5392 5394 'PhortuneAccountBillingAddressTransaction' => 'applications/phortune/xaction/PhortuneAccountBillingAddressTransaction.php', ··· 12208 12210 'PholioTransactionType' => 'PhabricatorModularTransactionType', 12209 12211 'PholioTransactionView' => 'PhabricatorApplicationTransactionView', 12210 12212 'PholioUploadedImageView' => 'AphrontView', 12213 + 'PhorgeCodeWarningSetupCheck' => 'PhabricatorSetupCheck', 12214 + 'PhorgeSystemDeprecationWarningListener' => 'PhabricatorEventListener', 12211 12215 'PhortuneAccount' => array( 12212 12216 'PhortuneDAO', 12213 12217 'PhabricatorApplicationTransactionInterface',
+81
src/applications/config/check/PhorgeCodeWarningSetupCheck.php
··· 1 + <?php 2 + 3 + final class PhorgeCodeWarningSetupCheck extends PhabricatorSetupCheck { 4 + 5 + public function getExecutionOrder() { 6 + return 2000; 7 + } 8 + 9 + public function getDefaultGroup() { 10 + return self::GROUP_OTHER; 11 + } 12 + 13 + protected function executeChecks() { 14 + $warnings = (new PhorgeSystemDeprecationWarningListener())->getWarnings(); 15 + if (!$warnings) { 16 + return; 17 + } 18 + 19 + $link = phutil_tag( 20 + 'a', 21 + array('href' => 'https://we.phorge.it/w/docs/report-warnings/'), 22 + pht('%s\'s home page', PlatformSymbols::getPlatformServerName())); 23 + 24 + $message = pht( 25 + 'There is some deprecated code found in the %s code-base.'. 26 + "\n\n". 27 + "This isn't a problem yet, but it means that %s might stop working if ". 28 + 'you upgrade PHP version.'. 29 + "\n\n". 30 + 'This page records a sample of the cases since last server restart. '. 31 + "\n\n". 32 + 'To solve this issue, either:'. 33 + "\n\n". 34 + '- Visit %s, file bug report with the information below, or'. 35 + "\n". 36 + '- Ignore this issue using the `Ignore` button below.'. 37 + "\n\n", 38 + PlatformSymbols::getPlatformServerName(), 39 + PlatformSymbols::getPlatformServerName(), 40 + $link); 41 + $message = array($message); 42 + 43 + $message[] = pht('PHP version: %s', phpversion()); 44 + $message[] = "\n\n"; 45 + 46 + $message[] = pht('Recorded items (sample):'); 47 + $list = array(); 48 + $warnings = array_reverse(isort($warnings, 'counter')); 49 + foreach ($warnings as $key => $data) { 50 + $summary = pht( 51 + '%s, occurrences: %s', 52 + $key, 53 + $data['counter']); 54 + 55 + $trace = phutil_tag('tt', array(), 56 + array($data['message'] , "\n", $data['trace'])); 57 + 58 + $list[] = phutil_tag( 59 + 'li', 60 + array(), 61 + phutil_tag( 62 + 'details', 63 + array(), 64 + array( 65 + phutil_tag('summary', array(), $summary), 66 + $trace, 67 + ))); 68 + } 69 + $message[] = phutil_tag('ul', array(), $list); 70 + 71 + 72 + $this->newIssue('deprecations') 73 + ->setName(pht('Deprecated Code')) 74 + ->setMessage($message) 75 + ->setSummary(pht('There is some deprecated code found in the code-base.')) 76 + ->addLink( 77 + 'https://we.phorge.it/w/docs/report-warnings/', 78 + 'More Details on the website'); 79 + } 80 + 81 + }
+1
src/applications/system/application/PhabricatorSystemApplication.php
··· 17 17 public function getEventListeners() { 18 18 return array( 19 19 new PhabricatorSystemDebugUIEventListener(), 20 + new PhorgeSystemDeprecationWarningListener(), 20 21 ); 21 22 } 22 23
+58
src/applications/system/events/PhorgeSystemDeprecationWarningListener.php
··· 1 + <?php 2 + 3 + final class PhorgeSystemDeprecationWarningListener 4 + extends PhabricatorEventListener { 5 + 6 + const CACHE_KEY = 'setup-check:deprecation-warnings'; 7 + const MAX_ENTRIES = 5; 8 + 9 + public function handleEvent(PhutilEvent $event) { 10 + // we're not an actual PhutilEventListener - we're just using the `register` 11 + // part of that framework. 12 + } 13 + 14 + public function register() { 15 + PhutilErrorHandler::addErrorListener( 16 + array($this, 'handleErrors')); 17 + } 18 + 19 + public function handleErrors($event, $value, $metadata) { 20 + 21 + if ($event !== PhutilErrorHandler::DEPRECATED) { 22 + return; 23 + } 24 + 25 + $trace_key = sprintf( 26 + '%s:%s', 27 + basename($metadata['file']), 28 + $metadata['line']); 29 + 30 + $cache = PhabricatorCaches::getRuntimeCache(); 31 + $cache_entry = $cache->getKey(self::CACHE_KEY); 32 + 33 + if (!$cache_entry) { 34 + $cache_entry = array(); 35 + } 36 + 37 + $trace_entry = idx($cache_entry, $trace_key); 38 + 39 + if ($trace_entry) { 40 + $trace_entry['counter']++; 41 + } else { 42 + $trace_entry = array( 43 + 'counter' => 1, 44 + 'message' => $value, 45 + 'trace' => PhutilErrorHandler::formatStacktrace($metadata['trace']), 46 + ); 47 + } 48 + $cache_entry[$trace_key] = $trace_entry; 49 + 50 + $cache->setKey(self::CACHE_KEY , $cache_entry); 51 + } 52 + 53 + public function getWarnings() { 54 + $cache = PhabricatorCaches::getRuntimeCache(); 55 + return $cache->getKey(self::CACHE_KEY); 56 + } 57 + 58 + }