Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91213527
HeraldRuleIndexEngineExtension.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 9, 01:06
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Nov 11, 01:06 (2 d)
Engine
blob
Format
Raw Data
Handle
22221656
Attached To
rPH Phabricator
HeraldRuleIndexEngineExtension.php
View Options
<?php
final
class
HeraldRuleIndexEngineExtension
extends
PhabricatorIndexEngineExtension
{
const
EXTENSIONKEY
=
'herald.actions'
;
public
function
getExtensionName
()
{
return
pht
(
'Herald Actions'
);
}
public
function
shouldIndexObject
(
$object
)
{
if
(!(
$object
instanceof
HeraldRule
))
{
return
false
;
}
return
true
;
}
public
function
indexObject
(
PhabricatorIndexEngine
$engine
,
$object
)
{
$edge_type
=
HeraldRuleActionAffectsObjectEdgeType
::
EDGECONST
;
$old_edges
=
PhabricatorEdgeQuery
::
loadDestinationPHIDs
(
$object
->
getPHID
(),
$edge_type
);
$old_edges
=
array_fuse
(
$old_edges
);
$new_edges
=
$this
->
getPHIDsAffectedByActions
(
$object
);
$new_edges
=
array_fuse
(
$new_edges
);
$add_edges
=
array_diff_key
(
$new_edges
,
$old_edges
);
$rem_edges
=
array_diff_key
(
$old_edges
,
$new_edges
);
if
(!
$add_edges
&&
!
$rem_edges
)
{
return
;
}
$editor
=
new
PhabricatorEdgeEditor
();
foreach
(
$add_edges
as
$phid
)
{
$editor
->
addEdge
(
$object
->
getPHID
(),
$edge_type
,
$phid
);
}
foreach
(
$rem_edges
as
$phid
)
{
$editor
->
removeEdge
(
$object
->
getPHID
(),
$edge_type
,
$phid
);
}
$editor
->
save
();
}
public
function
getIndexVersion
(
$object
)
{
$phids
=
$this
->
getPHIDsAffectedByActions
(
$object
);
sort
(
$phids
);
$phids
=
implode
(
':'
,
$phids
);
return
PhabricatorHash
::
digestForIndex
(
$phids
);
}
private
function
getPHIDsAffectedByActions
(
HeraldRule
$rule
)
{
$viewer
=
$this
->
getViewer
();
$rule
=
id
(
new
HeraldRuleQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$rule
->
getID
()))
->
needConditionsAndActions
(
true
)
->
executeOne
();
if
(!
$rule
)
{
return
array
();
}
$phids
=
array
();
$actions
=
HeraldAction
::
getAllActions
();
foreach
(
$rule
->
getActions
()
as
$action_record
)
{
$action
=
idx
(
$actions
,
$action_record
->
getAction
());
if
(!
$action
)
{
continue
;
}
foreach
(
$action
->
getPHIDsAffectedByAction
(
$action_record
)
as
$phid
)
{
$phids
[]
=
$phid
;
}
}
$phids
=
array_fuse
(
$phids
);
return
array_keys
(
$phids
);
}
}
Event Timeline
Log In to Comment