Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php b/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
index fc7cee52ce..db5d4b9fcb 100644
--- a/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
+++ b/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
@@ -1,158 +1,170 @@
<?php
final class DiffusionPullLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Pull Logs');
}
public function getApplicationClassName() {
return 'PhabricatorDiffusionApplication';
}
public function newQuery() {
return new PhabricatorRepositoryPullEventQuery();
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['repositoryPHIDs']) {
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
}
if ($map['pullerPHIDs']) {
$query->withPullerPHIDs($map['pullerPHIDs']);
}
+ if ($map['createdStart'] || $map['createdEnd']) {
+ $query->withEpochBetween(
+ $map['createdStart'],
+ $map['createdEnd']);
+ }
+
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchDatasourceField())
->setDatasource(new DiffusionRepositoryDatasource())
->setKey('repositoryPHIDs')
->setAliases(array('repository', 'repositories', 'repositoryPHID'))
->setLabel(pht('Repositories'))
->setDescription(
pht('Search for pull logs for specific repositories.')),
id(new PhabricatorUsersSearchField())
->setKey('pullerPHIDs')
->setAliases(array('puller', 'pullers', 'pullerPHID'))
->setLabel(pht('Pullers'))
->setDescription(
pht('Search for pull logs by specific users.')),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created After'))
+ ->setKey('createdStart'),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created Before'))
+ ->setKey('createdEnd'),
);
}
protected function newExportFields() {
return array(
id(new PhabricatorPHIDExportField())
->setKey('repositoryPHID')
->setLabel(pht('Repository PHID')),
id(new PhabricatorStringExportField())
->setKey('repository')
->setLabel(pht('Repository')),
id(new PhabricatorPHIDExportField())
->setKey('pullerPHID')
->setLabel(pht('Puller PHID')),
id(new PhabricatorStringExportField())
->setKey('puller')
->setLabel(pht('Puller')),
id(new PhabricatorStringExportField())
->setKey('protocol')
->setLabel(pht('Protocol')),
id(new PhabricatorStringExportField())
->setKey('result')
->setLabel(pht('Result')),
id(new PhabricatorIntExportField())
->setKey('code')
->setLabel(pht('Code')),
id(new PhabricatorEpochExportField())
->setKey('date')
->setLabel(pht('Date')),
);
}
protected function newExportData(array $events) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($events as $event) {
if ($event->getPullerPHID()) {
$phids[] = $event->getPullerPHID();
}
}
$handles = $viewer->loadHandles($phids);
$export = array();
foreach ($events as $event) {
$repository = $event->getRepository();
if ($repository) {
$repository_phid = $repository->getPHID();
$repository_name = $repository->getDisplayName();
} else {
$repository_phid = null;
$repository_name = null;
}
$puller_phid = $event->getPullerPHID();
if ($puller_phid) {
$puller_name = $handles[$puller_phid]->getName();
} else {
$puller_name = null;
}
$export[] = array(
'repositoryPHID' => $repository_phid,
'repository' => $repository_name,
'pullerPHID' => $puller_phid,
'puller' => $puller_name,
'protocol' => $event->getRemoteProtocol(),
'result' => $event->getResultType(),
'code' => $event->getResultCode(),
'date' => $event->getEpoch(),
);
}
return $export;
}
protected function getURI($path) {
return '/diffusion/pulllog/'.$path;
}
protected function getBuiltinQueryNames() {
return array(
'all' => pht('All Pull Logs'),
);
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $logs,
PhabricatorSavedQuery $query,
array $handles) {
$table = id(new DiffusionPullLogListView())
->setViewer($this->requireViewer())
->setLogs($logs);
return id(new PhabricatorApplicationSearchResultView())
->setTable($table);
}
}
diff --git a/src/applications/people/query/PhabricatorPeopleLogQuery.php b/src/applications/people/query/PhabricatorPeopleLogQuery.php
index e6e2506bee..fc6a87b335 100644
--- a/src/applications/people/query/PhabricatorPeopleLogQuery.php
+++ b/src/applications/people/query/PhabricatorPeopleLogQuery.php
@@ -1,104 +1,126 @@
<?php
final class PhabricatorPeopleLogQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $actorPHIDs;
private $userPHIDs;
private $relatedPHIDs;
private $sessionKeys;
private $actions;
private $remoteAddressPrefix;
+ private $dateCreatedMin;
+ private $dateCreatedMax;
public function withActorPHIDs(array $actor_phids) {
$this->actorPHIDs = $actor_phids;
return $this;
}
public function withUserPHIDs(array $user_phids) {
$this->userPHIDs = $user_phids;
return $this;
}
public function withRelatedPHIDs(array $related_phids) {
$this->relatedPHIDs = $related_phids;
return $this;
}
public function withSessionKeys(array $session_keys) {
$this->sessionKeys = $session_keys;
return $this;
}
public function withActions(array $actions) {
$this->actions = $actions;
return $this;
}
public function withRemoteAddressPrefix($remote_address_prefix) {
$this->remoteAddressPrefix = $remote_address_prefix;
return $this;
}
+ public function withDateCreatedBetween($min, $max) {
+ $this->dateCreatedMin = $min;
+ $this->dateCreatedMax = $max;
+ return $this;
+ }
+
public function newResultObject() {
return new PhabricatorUserLog();
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->actorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'actorPHID IN (%Ls)',
$this->actorPHIDs);
}
if ($this->userPHIDs !== null) {
$where[] = qsprintf(
$conn,
'userPHID IN (%Ls)',
$this->userPHIDs);
}
if ($this->relatedPHIDs !== null) {
$where[] = qsprintf(
$conn,
'(actorPHID IN (%Ls) OR userPHID IN (%Ls))',
$this->relatedPHIDs,
$this->relatedPHIDs);
}
if ($this->sessionKeys !== null) {
$where[] = qsprintf(
$conn,
'session IN (%Ls)',
$this->sessionKeys);
}
if ($this->actions !== null) {
$where[] = qsprintf(
$conn,
'action IN (%Ls)',
$this->actions);
}
if ($this->remoteAddressPrefix !== null) {
$where[] = qsprintf(
$conn,
'remoteAddr LIKE %>',
$this->remoteAddressPrefix);
}
+ if ($this->dateCreatedMin !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'dateCreated >= %d',
+ $this->dateCreatedMin);
+ }
+
+ if ($this->dateCreatedMax !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'dateCreated <= %d',
+ $this->dateCreatedMax);
+ }
+
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorPeopleApplication';
}
}
diff --git a/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php b/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php
index 1a3ae4dea1..b052456cd3 100644
--- a/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php
+++ b/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php
@@ -1,229 +1,241 @@
<?php
final class PhabricatorPeopleLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Account Activity');
}
public function getApplicationClassName() {
return 'PhabricatorPeopleApplication';
}
public function getPageSize(PhabricatorSavedQuery $saved) {
return 500;
}
public function newQuery() {
$query = new PhabricatorPeopleLogQuery();
// NOTE: If the viewer isn't an administrator, always restrict the query to
// related records. This echoes the policy logic of these logs. This is
// mostly a performance optimization, to prevent us from having to pull
// large numbers of logs that the user will not be able to see and filter
// them in-process.
$viewer = $this->requireViewer();
if (!$viewer->getIsAdmin()) {
$query->withRelatedPHIDs(array($viewer->getPHID()));
}
return $query;
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['userPHIDs']) {
$query->withUserPHIDs($map['userPHIDs']);
}
if ($map['actorPHIDs']) {
$query->withActorPHIDs($map['actorPHIDs']);
}
if ($map['actions']) {
$query->withActions($map['actions']);
}
if (strlen($map['ip'])) {
$query->withRemoteAddressPrefix($map['ip']);
}
if ($map['sessions']) {
$query->withSessionKeys($map['sessions']);
}
+ if ($map['createdStart'] || $map['createdEnd']) {
+ $query->withDateCreatedBetween(
+ $map['createdStart'],
+ $map['createdEnd']);
+ }
+
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorUsersSearchField())
->setKey('userPHIDs')
->setAliases(array('users', 'user', 'userPHID'))
->setLabel(pht('Users'))
->setDescription(pht('Search for activity affecting specific users.')),
id(new PhabricatorUsersSearchField())
->setKey('actorPHIDs')
->setAliases(array('actors', 'actor', 'actorPHID'))
->setLabel(pht('Actors'))
->setDescription(pht('Search for activity by specific users.')),
id(new PhabricatorSearchCheckboxesField())
->setKey('actions')
->setLabel(pht('Actions'))
->setDescription(pht('Search for particular types of activity.'))
->setOptions(PhabricatorUserLog::getActionTypeMap()),
id(new PhabricatorSearchTextField())
->setKey('ip')
->setLabel(pht('Filter IP'))
->setDescription(pht('Search for actions by remote address.')),
id(new PhabricatorSearchStringListField())
->setKey('sessions')
->setLabel(pht('Sessions'))
->setDescription(pht('Search for activity in particular sessions.')),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created After'))
+ ->setKey('createdStart'),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created Before'))
+ ->setKey('createdEnd'),
);
}
protected function getURI($path) {
return '/people/logs/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $logs,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($logs, 'PhabricatorUserLog');
$viewer = $this->requireViewer();
$table = id(new PhabricatorUserLogView())
->setUser($viewer)
->setLogs($logs);
if ($viewer->getIsAdmin()) {
$table->setSearchBaseURI($this->getApplicationURI('logs/'));
}
return id(new PhabricatorApplicationSearchResultView())
->setTable($table);
}
protected function newExportFields() {
$viewer = $this->requireViewer();
$fields = array(
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('actorPHID')
->setLabel(pht('Actor PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('actor')
->setLabel(pht('Actor')),
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('userPHID')
->setLabel(pht('User PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('user')
->setLabel(pht('User')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('action')
->setLabel(pht('Action')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('actionName')
->setLabel(pht('Action Name')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('session')
->setLabel(pht('Session')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('old')
->setLabel(pht('Old Value')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('new')
->setLabel(pht('New Value')),
);
if ($viewer->getIsAdmin()) {
$fields[] = id(new PhabricatorStringExportField())
->setKey('remoteAddress')
->setLabel(pht('Remote Address'));
}
return $fields;
}
protected function newExportData(array $logs) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($logs as $log) {
$phids[] = $log->getUserPHID();
$phids[] = $log->getActorPHID();
}
$handles = $viewer->loadHandles($phids);
$action_map = PhabricatorUserLog::getActionTypeMap();
$export = array();
foreach ($logs as $log) {
$user_phid = $log->getUserPHID();
if ($user_phid) {
$user_name = $handles[$user_phid]->getName();
} else {
$user_name = null;
}
$actor_phid = $log->getActorPHID();
if ($actor_phid) {
$actor_name = $handles[$actor_phid]->getName();
} else {
$actor_name = null;
}
$action = $log->getAction();
$action_name = idx($action_map, $action, pht('Unknown ("%s")', $action));
$map = array(
'actorPHID' => $actor_phid,
'actor' => $actor_name,
'userPHID' => $user_phid,
'user' => $user_name,
'action' => $action,
'actionName' => $action_name,
'session' => substr($log->getSession(), 0, 6),
'old' => $log->getOldValue(),
'new' => $log->getNewValue(),
);
if ($viewer->getIsAdmin()) {
$map['remoteAddress'] = $log->getRemoteAddr();
}
$export[] = $map;
}
return $export;
}
}
diff --git a/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php b/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php
index af60ee0383..ce14a6f831 100644
--- a/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php
+++ b/src/applications/repository/query/PhabricatorRepositoryPullEventQuery.php
@@ -1,113 +1,135 @@
<?php
final class PhabricatorRepositoryPullEventQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $repositoryPHIDs;
private $pullerPHIDs;
+ private $epochMin;
+ private $epochMax;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withRepositoryPHIDs(array $repository_phids) {
$this->repositoryPHIDs = $repository_phids;
return $this;
}
public function withPullerPHIDs(array $puller_phids) {
$this->pullerPHIDs = $puller_phids;
return $this;
}
+ public function withEpochBetween($min, $max) {
+ $this->epochMin = $min;
+ $this->epochMax = $max;
+ return $this;
+ }
+
public function newResultObject() {
return new PhabricatorRepositoryPullEvent();
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $events) {
// If a pull targets an invalid repository or fails before authenticating,
// it may not have an associated repository.
$repository_phids = mpull($events, 'getRepositoryPHID');
$repository_phids = array_filter($repository_phids);
if ($repository_phids) {
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($this->getViewer())
->withPHIDs($repository_phids)
->execute();
$repositories = mpull($repositories, null, 'getPHID');
} else {
$repositories = array();
}
foreach ($events as $key => $event) {
$phid = $event->getRepositoryPHID();
if (!$phid) {
$event->attachRepository(null);
continue;
}
if (empty($repositories[$phid])) {
unset($events[$key]);
$this->didRejectResult($event);
continue;
}
$event->attachRepository($repositories[$phid]);
}
return $events;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'phid IN (%Ls)',
$this->phids);
}
if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf(
$conn,
'repositoryPHID IN (%Ls)',
$this->repositoryPHIDs);
}
if ($this->pullerPHIDs !== null) {
$where[] = qsprintf(
$conn,
'pullerPHID in (%Ls)',
$this->pullerPHIDs);
}
+ if ($this->epochMin !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'epoch >= %d',
+ $this->epochMin);
+ }
+
+ if ($this->epochMax !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'epoch <= %d',
+ $this->epochMax);
+ }
+
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorDiffusionApplication';
}
}
diff --git a/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php b/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php
index 2c5f7b0d0d..cb097fae2f 100644
--- a/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php
+++ b/src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php
@@ -1,137 +1,159 @@
<?php
final class PhabricatorRepositoryPushLogQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $repositoryPHIDs;
private $pusherPHIDs;
private $refTypes;
private $newRefs;
private $pushEventPHIDs;
+ private $epochMin;
+ private $epochMax;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withRepositoryPHIDs(array $repository_phids) {
$this->repositoryPHIDs = $repository_phids;
return $this;
}
public function withPusherPHIDs(array $pusher_phids) {
$this->pusherPHIDs = $pusher_phids;
return $this;
}
public function withRefTypes(array $ref_types) {
$this->refTypes = $ref_types;
return $this;
}
public function withNewRefs(array $new_refs) {
$this->newRefs = $new_refs;
return $this;
}
public function withPushEventPHIDs(array $phids) {
$this->pushEventPHIDs = $phids;
return $this;
}
+ public function withEpochBetween($min, $max) {
+ $this->epochMin = $min;
+ $this->epochMax = $max;
+ return $this;
+ }
+
public function newResultObject() {
return new PhabricatorRepositoryPushLog();
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $logs) {
$event_phids = mpull($logs, 'getPushEventPHID');
$events = id(new PhabricatorObjectQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($event_phids)
->execute();
$events = mpull($events, null, 'getPHID');
foreach ($logs as $key => $log) {
$event = idx($events, $log->getPushEventPHID());
if (!$event) {
unset($logs[$key]);
continue;
}
$log->attachPushEvent($event);
}
return $logs;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'phid IN (%Ls)',
$this->phids);
}
if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf(
$conn,
'repositoryPHID IN (%Ls)',
$this->repositoryPHIDs);
}
if ($this->pusherPHIDs !== null) {
$where[] = qsprintf(
$conn,
'pusherPHID in (%Ls)',
$this->pusherPHIDs);
}
if ($this->pushEventPHIDs !== null) {
$where[] = qsprintf(
$conn,
'pushEventPHID in (%Ls)',
$this->pushEventPHIDs);
}
if ($this->refTypes !== null) {
$where[] = qsprintf(
$conn,
'refType IN (%Ls)',
$this->refTypes);
}
if ($this->newRefs !== null) {
$where[] = qsprintf(
$conn,
'refNew IN (%Ls)',
$this->newRefs);
}
+ if ($this->epochMin !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'epoch >= %d',
+ $this->epochMin);
+ }
+
+ if ($this->epochMax !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'epoch <= %d',
+ $this->epochMax);
+ }
+
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorDiffusionApplication';
}
}
diff --git a/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php b/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php
index b2234ab6c7..8ad76987f9 100644
--- a/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php
+++ b/src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php
@@ -1,227 +1,239 @@
<?php
final class PhabricatorRepositoryPushLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Push Logs');
}
public function getApplicationClassName() {
return 'PhabricatorDiffusionApplication';
}
public function newQuery() {
return new PhabricatorRepositoryPushLogQuery();
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['repositoryPHIDs']) {
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
}
if ($map['pusherPHIDs']) {
$query->withPusherPHIDs($map['pusherPHIDs']);
}
+ if ($map['createdStart'] || $map['createdEnd']) {
+ $query->withEpochBetween(
+ $map['createdStart'],
+ $map['createdEnd']);
+ }
+
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchDatasourceField())
->setDatasource(new DiffusionRepositoryDatasource())
->setKey('repositoryPHIDs')
->setAliases(array('repository', 'repositories', 'repositoryPHID'))
->setLabel(pht('Repositories'))
->setDescription(
pht('Search for pull logs for specific repositories.')),
id(new PhabricatorUsersSearchField())
->setKey('pusherPHIDs')
->setAliases(array('pusher', 'pushers', 'pusherPHID'))
->setLabel(pht('Pushers'))
->setDescription(
pht('Search for pull logs by specific users.')),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created After'))
+ ->setKey('createdStart'),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created Before'))
+ ->setKey('createdEnd'),
);
}
protected function getURI($path) {
return '/diffusion/pushlog/'.$path;
}
protected function getBuiltinQueryNames() {
return array(
'all' => pht('All Push Logs'),
);
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $logs,
PhabricatorSavedQuery $query,
array $handles) {
$table = id(new DiffusionPushLogListView())
->setViewer($this->requireViewer())
->setLogs($logs);
return id(new PhabricatorApplicationSearchResultView())
->setTable($table);
}
protected function newExportFields() {
$viewer = $this->requireViewer();
$fields = array(
$fields[] = id(new PhabricatorIDExportField())
->setKey('pushID')
->setLabel(pht('Push ID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('protocol')
->setLabel(pht('Protocol')),
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('repositoryPHID')
->setLabel(pht('Repository PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('repository')
->setLabel(pht('Repository')),
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('pusherPHID')
->setLabel(pht('Pusher PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('pusher')
->setLabel(pht('Pusher')),
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('devicePHID')
->setLabel(pht('Device PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('device')
->setLabel(pht('Device')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('type')
->setLabel(pht('Ref Type')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('name')
->setLabel(pht('Ref Name')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('old')
->setLabel(pht('Ref Old')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('new')
->setLabel(pht('Ref New')),
$fields[] = id(new PhabricatorIntExportField())
->setKey('flags')
->setLabel(pht('Flags')),
$fields[] = id(new PhabricatorStringListExportField())
->setKey('flagNames')
->setLabel(pht('Flag Names')),
$fields[] = id(new PhabricatorIntExportField())
->setKey('result')
->setLabel(pht('Result')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('resultName')
->setLabel(pht('Result Name')),
);
if ($viewer->getIsAdmin()) {
$fields[] = id(new PhabricatorStringExportField())
->setKey('remoteAddress')
->setLabel(pht('Remote Address'));
}
return $fields;
}
protected function newExportData(array $logs) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($logs as $log) {
$phids[] = $log->getPusherPHID();
$phids[] = $log->getDevicePHID();
$phids[] = $log->getPushEvent()->getRepositoryPHID();
}
$handles = $viewer->loadHandles($phids);
$flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames();
$reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames();
$export = array();
foreach ($logs as $log) {
$event = $log->getPushEvent();
$repository_phid = $event->getRepositoryPHID();
if ($repository_phid) {
$repository_name = $handles[$repository_phid]->getName();
} else {
$repository_name = null;
}
$pusher_phid = $log->getPusherPHID();
if ($pusher_phid) {
$pusher_name = $handles[$pusher_phid]->getName();
} else {
$pusher_name = null;
}
$device_phid = $log->getDevicePHID();
if ($device_phid) {
$device_name = $handles[$device_phid]->getName();
} else {
$device_name = null;
}
$flags = $log->getChangeFlags();
$flag_names = array();
foreach ($flag_map as $flag_key => $flag_name) {
if (($flags & $flag_key) === $flag_key) {
$flag_names[] = $flag_name;
}
}
$result = $event->getRejectCode();
$result_name = idx($reject_map, $result, pht('Unknown ("%s")', $result));
$map = array(
'pushID' => $event->getID(),
'protocol' => $event->getRemoteProtocol(),
'repositoryPHID' => $repository_phid,
'repository' => $repository_name,
'pusherPHID' => $pusher_phid,
'pusher' => $pusher_name,
'devicePHID' => $device_phid,
'device' => $device_name,
'type' => $log->getRefType(),
'name' => $log->getRefName(),
'old' => $log->getRefOld(),
'new' => $log->getRefNew(),
'flags' => $flags,
'flagNames' => $flag_names,
'result' => $result,
'resultName' => $result_name,
);
if ($viewer->getIsAdmin()) {
$map['remoteAddress'] = $event->getRemoteAddress();
}
$export[] = $map;
}
return $export;
}
}
diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushLog.php b/src/applications/repository/storage/PhabricatorRepositoryPushLog.php
index 81a564a91f..c2d3456da6 100644
--- a/src/applications/repository/storage/PhabricatorRepositoryPushLog.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryPushLog.php
@@ -1,228 +1,231 @@
<?php
/**
* Records a push to a hosted repository. This allows us to store metadata
* about who pushed commits, when, and from where. We can also record the
* history of branches and tags, which is not normally persisted outside of
* the reflog.
*
* This log is written by commit hooks installed into hosted repositories.
* See @{class:DiffusionCommitHookEngine}.
*/
final class PhabricatorRepositoryPushLog
extends PhabricatorRepositoryDAO
implements PhabricatorPolicyInterface {
const REFTYPE_BRANCH = 'branch';
const REFTYPE_TAG = 'tag';
const REFTYPE_BOOKMARK = 'bookmark';
const REFTYPE_COMMIT = 'commit';
const CHANGEFLAG_ADD = 1;
const CHANGEFLAG_DELETE = 2;
const CHANGEFLAG_APPEND = 4;
const CHANGEFLAG_REWRITE = 8;
const CHANGEFLAG_DANGEROUS = 16;
const CHANGEFLAG_ENORMOUS = 32;
const REJECT_ACCEPT = 0;
const REJECT_DANGEROUS = 1;
const REJECT_HERALD = 2;
const REJECT_EXTERNAL = 3;
const REJECT_BROKEN = 4;
const REJECT_ENORMOUS = 5;
protected $repositoryPHID;
protected $epoch;
protected $pusherPHID;
protected $pushEventPHID;
protected $devicePHID;
protected $refType;
protected $refNameHash;
protected $refNameRaw;
protected $refNameEncoding;
protected $refOld;
protected $refNew;
protected $mergeBase;
protected $changeFlags;
private $dangerousChangeDescription = self::ATTACHABLE;
private $pushEvent = self::ATTACHABLE;
private $repository = self::ATTACHABLE;
public static function initializeNewLog(PhabricatorUser $viewer) {
return id(new PhabricatorRepositoryPushLog())
->setPusherPHID($viewer->getPHID());
}
public static function getFlagDisplayNames() {
return array(
self::CHANGEFLAG_ADD => pht('Create'),
self::CHANGEFLAG_DELETE => pht('Delete'),
self::CHANGEFLAG_APPEND => pht('Append'),
self::CHANGEFLAG_REWRITE => pht('Rewrite'),
self::CHANGEFLAG_DANGEROUS => pht('Dangerous'),
self::CHANGEFLAG_ENORMOUS => pht('Enormous'),
);
}
public static function getRejectCodeDisplayNames() {
return array(
self::REJECT_ACCEPT => pht('Accepted'),
self::REJECT_DANGEROUS => pht('Rejected: Dangerous'),
self::REJECT_HERALD => pht('Rejected: Herald'),
self::REJECT_EXTERNAL => pht('Rejected: External Hook'),
self::REJECT_BROKEN => pht('Rejected: Broken'),
self::REJECT_ENORMOUS => pht('Rejected: Enormous'),
);
}
public static function getHeraldChangeFlagConditionOptions() {
return array(
self::CHANGEFLAG_ADD =>
pht('change creates ref'),
self::CHANGEFLAG_DELETE =>
pht('change deletes ref'),
self::CHANGEFLAG_REWRITE =>
pht('change rewrites ref'),
self::CHANGEFLAG_DANGEROUS =>
pht('dangerous change'),
);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_BINARY => array(
'refNameRaw' => true,
),
self::CONFIG_COLUMN_SCHEMA => array(
'refType' => 'text12',
'refNameHash' => 'bytes12?',
'refNameRaw' => 'bytes?',
'refNameEncoding' => 'text16?',
'refOld' => 'text40?',
'refNew' => 'text40',
'mergeBase' => 'text40?',
'changeFlags' => 'uint32',
'devicePHID' => 'phid?',
),
self::CONFIG_KEY_SCHEMA => array(
'key_repository' => array(
'columns' => array('repositoryPHID'),
),
'key_ref' => array(
'columns' => array('repositoryPHID', 'refNew'),
),
'key_name' => array(
'columns' => array('repositoryPHID', 'refNameHash'),
),
'key_event' => array(
'columns' => array('pushEventPHID'),
),
'key_pusher' => array(
'columns' => array('pusherPHID'),
),
+ 'key_epoch' => array(
+ 'columns' => array('epoch'),
+ ),
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorRepositoryPushLogPHIDType::TYPECONST);
}
public function attachPushEvent(PhabricatorRepositoryPushEvent $push_event) {
$this->pushEvent = $push_event;
return $this;
}
public function getPushEvent() {
return $this->assertAttached($this->pushEvent);
}
public function getRefName() {
return $this->getUTF8StringFromStorage(
$this->getRefNameRaw(),
$this->getRefNameEncoding());
}
public function setRefName($ref_raw) {
$this->setRefNameRaw($ref_raw);
$this->setRefNameHash(PhabricatorHash::digestForIndex($ref_raw));
$this->setRefNameEncoding($this->detectEncodingForStorage($ref_raw));
return $this;
}
public function getRefOldShort() {
if ($this->getRepository()->isSVN()) {
return $this->getRefOld();
}
return substr($this->getRefOld(), 0, 12);
}
public function getRefNewShort() {
if ($this->getRepository()->isSVN()) {
return $this->getRefNew();
}
return substr($this->getRefNew(), 0, 12);
}
public function hasChangeFlags($mask) {
return ($this->changeFlags & $mask);
}
public function attachDangerousChangeDescription($description) {
$this->dangerousChangeDescription = $description;
return $this;
}
public function getDangerousChangeDescription() {
return $this->assertAttached($this->dangerousChangeDescription);
}
public function attachRepository(PhabricatorRepository $repository) {
// NOTE: Some gymnastics around this because of object construction order
// in the hook engine. Particularly, web build the logs before we build
// their push event.
$this->repository = $repository;
return $this;
}
public function getRepository() {
if ($this->repository == self::ATTACHABLE) {
return $this->getPushEvent()->getRepository();
}
return $this->assertAttached($this->repository);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
// NOTE: We're passing through the repository rather than the push event
// mostly because we need to do policy checks in Herald before we create
// the event. The two approaches are equivalent in practice.
return $this->getRepository()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getRepository()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return pht(
"A repository's push logs are visible to users who can see the ".
"repository.");
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Mar 14, 4:25 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72030
Default Alt Text
(37 KB)

Event Timeline