Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F118854357
PhabricatorSearchWorker.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
Sun, Jun 22, 14:28
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Jun 24, 14:28 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
26911206
Attached To
rPH Phabricator
PhabricatorSearchWorker.php
View Options
<?php
final
class
PhabricatorSearchWorker
extends
PhabricatorWorker
{
public
static
function
queueDocumentForIndexing
(
$phid
,
$parameters
=
null
)
{
if
(
$parameters
===
null
)
{
$parameters
=
array
();
}
parent
::
scheduleTask
(
__CLASS__
,
array
(
'documentPHID'
=>
$phid
,
'parameters'
=>
$parameters
,
),
array
(
'priority'
=>
parent
::
PRIORITY_IMPORT
,
));
}
protected
function
doWork
()
{
$data
=
$this
->
getTaskData
();
$object_phid
=
idx
(
$data
,
'documentPHID'
);
$object
=
$this
->
loadObjectForIndexing
(
$object_phid
);
$engine
=
id
(
new
PhabricatorIndexEngine
())
->
setObject
(
$object
);
$parameters
=
idx
(
$data
,
'parameters'
,
array
());
$engine
->
setParameters
(
$parameters
);
if
(!
$engine
->
shouldIndexObject
())
{
return
;
}
$key
=
"index.{$object_phid}"
;
$lock
=
PhabricatorGlobalLock
::
newLock
(
$key
);
$lock
->
lock
(
1
);
try
{
// Reload the object now that we have a lock, to make sure we have the
// most current version.
$object
=
$this
->
loadObjectForIndexing
(
$object
->
getPHID
());
$engine
->
setObject
(
$object
);
$engine
->
indexObject
();
}
catch
(
Exception
$ex
)
{
$lock
->
unlock
();
if
(!(
$ex
instanceof
PhabricatorWorkerPermanentFailureException
))
{
$ex
=
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Failed to update search index for document "%s": %s'
,
$object_phid
,
$ex
->
getMessage
()));
}
throw
$ex
;
}
$lock
->
unlock
();
}
private
function
loadObjectForIndexing
(
$phid
)
{
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$object
=
id
(
new
PhabricatorObjectQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$phid
))
->
executeOne
();
if
(!
$object
)
{
throw
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Unable to load object "%s" to rebuild indexes.'
,
$phid
));
}
return
$object
;
}
}
Event Timeline
Log In to Comment