Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / storage / PhabricatorRepositoryPushEvent.php
blobc0936e9c6e0ecc564beb0965f6209ec08103a79f
1 <?php
3 /**
4 * Groups a set of push logs corresponding to changes which were all pushed in
5 * the same transaction.
6 */
7 final class PhabricatorRepositoryPushEvent
8 extends PhabricatorRepositoryDAO
9 implements PhabricatorPolicyInterface {
11 protected $repositoryPHID;
12 protected $epoch;
13 protected $pusherPHID;
14 protected $requestIdentifier;
15 protected $remoteAddress;
16 protected $remoteProtocol;
17 protected $rejectCode;
18 protected $rejectDetails;
19 protected $writeWait;
20 protected $readWait;
21 protected $hostWait;
22 protected $hookWait;
24 private $repository = self::ATTACHABLE;
25 private $logs = self::ATTACHABLE;
27 public static function initializeNewEvent(PhabricatorUser $viewer) {
28 return id(new PhabricatorRepositoryPushEvent())
29 ->setPusherPHID($viewer->getPHID());
32 protected function getConfiguration() {
33 return array(
34 self::CONFIG_AUX_PHID => true,
35 self::CONFIG_TIMESTAMPS => false,
36 self::CONFIG_COLUMN_SCHEMA => array(
37 'requestIdentifier' => 'bytes12?',
38 'remoteAddress' => 'ipaddress?',
39 'remoteProtocol' => 'text32?',
40 'rejectCode' => 'uint32',
41 'rejectDetails' => 'text64?',
42 'writeWait' => 'uint64?',
43 'readWait' => 'uint64?',
44 'hostWait' => 'uint64?',
45 'hookWait' => 'uint64?',
47 self::CONFIG_KEY_SCHEMA => array(
48 'key_repository' => array(
49 'columns' => array('repositoryPHID'),
51 'key_identifier' => array(
52 'columns' => array('requestIdentifier'),
54 'key_reject' => array(
55 'columns' => array('rejectCode', 'rejectDetails'),
58 ) + parent::getConfiguration();
61 public function generatePHID() {
62 return PhabricatorPHID::generateNewPHID(
63 PhabricatorRepositoryPushEventPHIDType::TYPECONST);
66 public function attachRepository(PhabricatorRepository $repository) {
67 $this->repository = $repository;
68 return $this;
71 public function getRepository() {
72 return $this->assertAttached($this->repository);
75 public function attachLogs(array $logs) {
76 $this->logs = $logs;
77 return $this;
80 public function getLogs() {
81 return $this->assertAttached($this->logs);
84 public function saveWithLogs(array $logs) {
85 assert_instances_of($logs, 'PhabricatorRepositoryPushLog');
87 $this->openTransaction();
88 $this->save();
89 foreach ($logs as $log) {
90 $log->setPushEventPHID($this->getPHID());
91 $log->save();
93 $this->saveTransaction();
95 $this->attachLogs($logs);
97 return $this;
100 /* -( PhabricatorPolicyInterface )----------------------------------------- */
103 public function getCapabilities() {
104 return array(
105 PhabricatorPolicyCapability::CAN_VIEW,
109 public function getPolicy($capability) {
110 return $this->getRepository()->getPolicy($capability);
113 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
114 return $this->getRepository()->hasAutomaticCapability($capability, $viewer);
117 public function describeAutomaticCapability($capability) {
118 return pht(
119 "A repository's push events are visible to users who can see the ".
120 "repository.");