@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3abstract class PhabricatorUnlockEngine
4 extends Phobject {
5
6 final public static function newUnlockEngineForObject($object) {
7 if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
8 throw new Exception(
9 pht(
10 'Object ("%s") does not implement interface "%s", so this type '.
11 'of object can not be unlocked.',
12 phutil_describe_type($object),
13 'PhabricatorApplicationTransactionInterface'));
14 }
15
16 if ($object instanceof PhabricatorUnlockableInterface) {
17 $engine = $object->newUnlockEngine();
18 } else {
19 $engine = new PhabricatorDefaultUnlockEngine();
20 }
21
22 return $engine;
23 }
24
25 public function newUnlockViewTransactions($object, $user) {
26 $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
27
28 if (!$this->canApplyTransactionType($object, $type_view)) {
29 throw new Exception(
30 pht(
31 'Object view policy can not be unlocked because this object '.
32 'does not have a mutable view policy.'));
33 }
34
35 return array(
36 $this->newTransaction($object)
37 ->setTransactionType($type_view)
38 ->setNewValue($user->getPHID()),
39 );
40 }
41
42 public function newUnlockEditTransactions($object, $user) {
43 $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
44
45 if (!$this->canApplyTransactionType($object, $type_edit)) {
46 throw new Exception(
47 pht(
48 'Object edit policy can not be unlocked because this object '.
49 'does not have a mutable edit policy.'));
50 }
51
52 return array(
53 $this->newTransaction($object)
54 ->setTransactionType($type_edit)
55 ->setNewValue($user->getPHID()),
56 );
57 }
58
59 public function newUnlockOwnerTransactions($object, $user) {
60 throw new Exception(
61 pht(
62 'Object owner can not be unlocked: the unlocking engine ("%s") for '.
63 'this object does not implement an owner unlocking mechanism.',
64 get_class($this)));
65 }
66
67 final protected function canApplyTransactionType($object, $type) {
68 $xaction_types = $object->getApplicationTransactionEditor()
69 ->getTransactionTypesForObject($object);
70
71 $xaction_types = array_fuse($xaction_types);
72
73 return isset($xaction_types[$type]);
74 }
75
76 final protected function newTransaction($object) {
77 return $object->getApplicationTransactionTemplate();
78 }
79
80
81}