forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhragmentSnapshot.php
76 lines (60 loc) · 1.97 KB
/
PhragmentSnapshot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
final class PhragmentSnapshot extends PhragmentDAO
implements PhabricatorPolicyInterface {
protected $primaryFragmentPHID;
protected $name;
private $primaryFragment = self::ATTACHABLE;
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text128',
),
self::CONFIG_KEY_SCHEMA => array(
'key_name' => array(
'columns' => array('primaryFragmentPHID', 'name'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhragmentSnapshotPHIDType::TYPECONST);
}
public function getURI() {
return '/phragment/snapshot/view/'.$this->getID().'/';
}
public function getPrimaryFragment() {
return $this->assertAttached($this->primaryFragment);
}
public function attachPrimaryFragment(PhragmentFragment $fragment) {
return $this->primaryFragment = $fragment;
}
public function delete() {
$children = id(new PhragmentSnapshotChild())
->loadAllWhere('snapshotPHID = %s', $this->getPHID());
$this->openTransaction();
foreach ($children as $child) {
$child->delete();
}
$result = parent::delete();
$this->saveTransaction();
return $result;
}
/* -( Policy Interface )--------------------------------------------------- */
public function getCapabilities() {
return $this->getPrimaryFragment()->getCapabilities();
}
public function getPolicy($capability) {
return $this->getPrimaryFragment()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getPrimaryFragment()
->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return $this->getPrimaryFragment()
->describeAutomaticCapability($capability);
}
}