From 08d9e5ec99ae7c57f19ffc22fdc7d87ac23dea0e Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 28 Apr 2014 15:44:52 -0700 Subject: [PATCH] Use initializeNewLog rather than instantiate the UserLog Summary: Use initializeNewLog rather than instantiate the UserLog, Closes T4912 Test Plan: Run install-certificate Reviewers: #blessed_reviewers, btrahan Reviewed By: #blessed_reviewers, btrahan Subscribers: epriestley Maniphest Tasks: T4912 Differential Revision: https://secure.phabricator.com/D8887 --- ...nduitAPI_conduit_getcertificate_Method.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php b/src/applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php index af31ac40c0..45115795cd 100644 --- a/src/applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php +++ b/src/applications/conduit/method/ConduitAPI_conduit_getcertificate_Method.php @@ -46,7 +46,7 @@ final class ConduitAPI_conduit_getcertificate_Method extends ConduitAPIMethod { 60 * 5); if (count($failed_attempts) > 5) { - $this->logFailure(); + $this->logFailure($request); throw new ConduitException('ERR-RATE-LIMIT'); } @@ -56,13 +56,13 @@ final class ConduitAPI_conduit_getcertificate_Method extends ConduitAPIMethod { trim($token)); if (!$info || $info->getDateCreated() < time() - (60 * 15)) { - $this->logFailure(); + $this->logFailure($request, $info); throw new ConduitException('ERR-BAD-TOKEN'); } else { - $log = id(new PhabricatorUserLog()) - ->setActorPHID($info->getUserPHID()) - ->setUserPHID($info->getUserPHID()) - ->setAction(PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE) + $log = PhabricatorUserLog::initializeNewLog( + $request->getUser(), + $info->getUserPHID(), + PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE) ->save(); } @@ -79,11 +79,14 @@ final class ConduitAPI_conduit_getcertificate_Method extends ConduitAPIMethod { ); } - private function logFailure() { + private function logFailure( + ConduitAPIRequest $request, + PhabricatorConduitCertificateToken $info = null) { - $log = id(new PhabricatorUserLog()) - ->setUserPHID('-') - ->setAction(PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE_FAILURE) + $log = PhabricatorUserLog::initializeNewLog( + $request->getUser(), + $info ? $info->getUserPHID() : '-', + PhabricatorUserLog::ACTION_CONDUIT_CERTIFICATE_FAILURE) ->save(); }