Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/storage/HarbormasterBuildMessage.php
12256 views
1
<?php
2
3
/**
4
* A message sent to an executing build target by an external system. We
5
* capture these messages and process them asynchronously to avoid race
6
* conditions where we receive a message before a build plan is ready to
7
* accept it.
8
*/
9
final class HarbormasterBuildMessage
10
extends HarbormasterDAO
11
implements
12
PhabricatorPolicyInterface,
13
PhabricatorDestructibleInterface {
14
15
protected $authorPHID;
16
protected $receiverPHID;
17
protected $type;
18
protected $isConsumed;
19
20
private $receiver = self::ATTACHABLE;
21
22
public static function initializeNewMessage(PhabricatorUser $actor) {
23
$actor_phid = $actor->getPHID();
24
if (!$actor_phid) {
25
$actor_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
26
}
27
28
return id(new HarbormasterBuildMessage())
29
->setAuthorPHID($actor_phid)
30
->setIsConsumed(0);
31
}
32
33
protected function getConfiguration() {
34
return array(
35
self::CONFIG_COLUMN_SCHEMA => array(
36
'type' => 'text16',
37
'isConsumed' => 'bool',
38
),
39
self::CONFIG_KEY_SCHEMA => array(
40
'key_receiver' => array(
41
'columns' => array('receiverPHID'),
42
),
43
),
44
) + parent::getConfiguration();
45
}
46
47
public function getReceiver() {
48
return $this->assertAttached($this->receiver);
49
}
50
51
public function attachReceiver($receiver) {
52
$this->receiver = $receiver;
53
return $this;
54
}
55
56
57
/* -( PhabricatorPolicyInterface )----------------------------------------- */
58
59
60
public function getCapabilities() {
61
return array(
62
PhabricatorPolicyCapability::CAN_VIEW,
63
);
64
}
65
66
public function getPolicy($capability) {
67
return $this->getReceiver()->getPolicy($capability);
68
}
69
70
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
71
return $this->getReceiver()->hasAutomaticCapability(
72
$capability,
73
$viewer);
74
}
75
76
public function describeAutomaticCapability($capability) {
77
return pht('Build messages have the same policies as their receivers.');
78
}
79
80
81
/* -( PhabricatorDestructibleInterface )----------------------------------- */
82
83
84
public function destroyObjectPermanently(
85
PhabricatorDestructionEngine $engine) {
86
$this->delete();
87
}
88
89
}
90
91