From 9af376a7435632df71032a035ec6a4f83b0da11a Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 2 Feb 2015 14:19:10 -0800 Subject: [PATCH] Add a setup warning for calls to deprecated Conduit methods Summary: We probably can't land this yet, since `arc tasks` still uses `maniphest.find` and `arc close` still uses `differential.getrevision`. We should clean those up and wait at least 30 days before committing this (maybe). Test Plan: Saw setup issues for `maniphest.find` and `differential.getrevision` calls. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley, joshuaspence, FacebookPOC, aran Differential Revision: https://secure.phabricator.com/D6333 --- src/__phutil_library_map__.php | 2 + .../check/ConduitDeprecatedCallSetupCheck.php | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/applications/conduit/check/ConduitDeprecatedCallSetupCheck.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b0214c7b75..5f07bc88d1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -211,6 +211,7 @@ phutil_register_library_map(array( 'ConduitCallTestCase' => 'applications/conduit/call/__tests__/ConduitCallTestCase.php', 'ConduitConnectConduitAPIMethod' => 'applications/conduit/method/ConduitConnectConduitAPIMethod.php', 'ConduitConnectionGarbageCollector' => 'applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php', + 'ConduitDeprecatedCallSetupCheck' => 'applications/conduit/check/ConduitDeprecatedCallSetupCheck.php', 'ConduitException' => 'applications/conduit/protocol/exception/ConduitException.php', 'ConduitGetCapabilitiesConduitAPIMethod' => 'applications/conduit/method/ConduitGetCapabilitiesConduitAPIMethod.php', 'ConduitGetCertificateConduitAPIMethod' => 'applications/conduit/method/ConduitGetCertificateConduitAPIMethod.php', @@ -3321,6 +3322,7 @@ phutil_register_library_map(array( 'ConduitCallTestCase' => 'PhabricatorTestCase', 'ConduitConnectConduitAPIMethod' => 'ConduitAPIMethod', 'ConduitConnectionGarbageCollector' => 'PhabricatorGarbageCollector', + 'ConduitDeprecatedCallSetupCheck' => 'PhabricatorSetupCheck', 'ConduitException' => 'Exception', 'ConduitGetCapabilitiesConduitAPIMethod' => 'ConduitAPIMethod', 'ConduitGetCertificateConduitAPIMethod' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/check/ConduitDeprecatedCallSetupCheck.php b/src/applications/conduit/check/ConduitDeprecatedCallSetupCheck.php new file mode 100644 index 0000000000..464244d826 --- /dev/null +++ b/src/applications/conduit/check/ConduitDeprecatedCallSetupCheck.php @@ -0,0 +1,64 @@ +setViewer(PhabricatorUser::getOmnipotentUser()) + ->withIsDeprecated(true) + ->execute(); + if (!$methods) { + return; + } + + $method_names = mpull($methods, 'getAPIMethodName'); + + $table = new PhabricatorConduitMethodCallLog(); + $conn_r = $table->establishConnection('r'); + + $calls = queryfx_all( + $conn_r, + 'SELECT DISTINCT method FROM %T WHERE dateCreated > %d + AND method IN (%Ls)', + $table->getTableName(), + time() - (60 * 60 * 24 * 30), + $method_names); + $calls = ipull($calls, 'method', 'method'); + + foreach ($calls as $method_name) { + $method = $methods[$method_name]; + + $summary = pht( + 'Deprecated Conduit method `%s` was called in the last 30 days. '. + 'You should migrate away from use of this method: it will be '. + 'removed in a future version of Phabricator.', + $method_name); + + $uri = PhabricatorEnv::getURI('/conduit/log/?methods='.$method_name); + + $description = $method->getMethodStatusDescription(); + + $message = pht( + 'Deprecated Conduit method %s was called in the last 30 days. '. + 'You should migrate away from use of this method: it will be '. + 'removed in a future version of Phabricator.'. + "\n\n". + "%s: %s". + "\n\n". + 'If you have already migrated all callers away from this method, '. + 'you can safely ignore this setup issue.', + phutil_tag('tt', array(), $method_name), + phutil_tag('tt', array(), $method_name), + $description); + + $this + ->newIssue('conduit.deprecated.'.$method_name) + ->setShortName(pht('Deprecated Conduit Method')) + ->setName(pht('Deprecated Conduit Method "%s" In Use', $method_name)) + ->setSummary($summary) + ->setMessage($message) + ->addLink($uri, pht('View Method Call Logs')); + } + } + +}