Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98060635
NuanceItemUpdateWorker.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
Thu, Jan 9, 04:52
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Jan 11, 04:52 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23491031
Attached To
rPH Phabricator
NuanceItemUpdateWorker.php
View Options
<?php
final
class
NuanceItemUpdateWorker
extends
NuanceWorker
{
protected
function
doWork
()
{
$item_phid
=
$this
->
getTaskDataValue
(
'itemPHID'
);
$hash
=
PhabricatorHash
::
digestForIndex
(
$item_phid
);
$lock_key
=
"nuance.item.{$hash}"
;
$lock
=
PhabricatorGlobalLock
::
newLock
(
$lock_key
);
$lock
->
lock
(
1
);
try
{
$item
=
$this
->
loadItem
(
$item_phid
);
$this
->
updateItem
(
$item
);
$this
->
routeItem
(
$item
);
$this
->
applyCommands
(
$item
);
}
catch
(
Exception
$ex
)
{
$lock
->
unlock
();
throw
$ex
;
}
$lock
->
unlock
();
}
private
function
updateItem
(
NuanceItem
$item
)
{
$impl
=
$item
->
getImplementation
();
if
(!
$impl
->
canUpdateItems
())
{
return
null
;
}
$viewer
=
$this
->
getViewer
();
$impl
->
setViewer
(
$viewer
);
$impl
->
updateItem
(
$item
);
}
private
function
routeItem
(
NuanceItem
$item
)
{
$status
=
$item
->
getStatus
();
if
(
$status
!=
NuanceItem
::
STATUS_ROUTING
)
{
return
;
}
$source
=
$item
->
getSource
();
// For now, always route items into the source's default queue.
$item
->
setQueuePHID
(
$source
->
getDefaultQueuePHID
())
->
setStatus
(
NuanceItem
::
STATUS_OPEN
)
->
save
();
}
private
function
applyCommands
(
NuanceItem
$item
)
{
$viewer
=
$this
->
getViewer
();
$impl
=
$item
->
getImplementation
();
$impl
->
setViewer
(
$viewer
);
$commands
=
id
(
new
NuanceItemCommandQuery
())
->
setViewer
(
$viewer
)
->
withItemPHIDs
(
array
(
$item
->
getPHID
()))
->
execute
();
$commands
=
msort
(
$commands
,
'getID'
);
foreach
(
$commands
as
$command
)
{
$impl
->
applyCommand
(
$item
,
$command
);
$command
->
delete
();
}
}
}
Event Timeline
Log In to Comment