Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98718845
ConpherenceThreadIndexer.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
Wed, Jan 15, 22:06
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Jan 17, 22:06 (2 d)
Engine
blob
Format
Raw Data
Handle
23633118
Attached To
rPH Phabricator
ConpherenceThreadIndexer.php
View Options
<?php
final
class
ConpherenceThreadIndexer
extends
PhabricatorSearchDocumentIndexer
{
public
function
getIndexableObject
()
{
return
new
ConpherenceThread
();
}
protected
function
loadDocumentByPHID
(
$phid
)
{
$object
=
id
(
new
ConpherenceThreadQuery
())
->
setViewer
(
$this
->
getViewer
())
->
withPHIDs
(
array
(
$phid
))
->
executeOne
();
if
(!
$object
)
{
throw
new
Exception
(
pht
(
'No thread "%s" exists!'
,
$phid
));
}
return
$object
;
}
protected
function
buildAbstractDocumentByPHID
(
$phid
)
{
$thread
=
$this
->
loadDocumentByPHID
(
$phid
);
// NOTE: We're explicitly not building a document here, only rebuilding
// the Conpherence search index.
$context
=
nonempty
(
$this
->
getContext
(),
array
());
$comment_phids
=
idx
(
$context
,
'commentPHIDs'
);
if
(
is_array
(
$comment_phids
)
&&
!
$comment_phids
)
{
// If this property is set, but empty, the transaction did not
// include any chat text. For example, a user might have left the
// conversation.
return
null
;
}
$query
=
id
(
new
ConpherenceTransactionQuery
())
->
setViewer
(
$this
->
getViewer
())
->
withObjectPHIDs
(
array
(
$thread
->
getPHID
()))
->
withTransactionTypes
(
array
(
PhabricatorTransactions
::
TYPE_COMMENT
))
->
needComments
(
true
);
if
(
$comment_phids
!==
null
)
{
$query
->
withPHIDs
(
$comment_phids
);
}
$xactions
=
$query
->
execute
();
foreach
(
$xactions
as
$xaction
)
{
$this
->
indexComment
(
$thread
,
$xaction
);
}
return
null
;
}
private
function
indexComment
(
ConpherenceThread
$thread
,
ConpherenceTransaction
$xaction
)
{
$previous
=
id
(
new
ConpherenceTransactionQuery
())
->
setViewer
(
$this
->
getViewer
())
->
withObjectPHIDs
(
array
(
$thread
->
getPHID
()))
->
withTransactionTypes
(
array
(
PhabricatorTransactions
::
TYPE_COMMENT
))
->
setAfterID
(
$xaction
->
getID
())
->
setLimit
(
1
)
->
executeOne
();
$index
=
id
(
new
ConpherenceIndex
())
->
setThreadPHID
(
$thread
->
getPHID
())
->
setTransactionPHID
(
$xaction
->
getPHID
())
->
setPreviousTransactionPHID
(
$previous
?
$previous
->
getPHID
()
:
null
)
->
setCorpus
(
$xaction
->
getComment
()->
getContent
());
queryfx
(
$index
->
establishConnection
(
'w'
),
'INSERT INTO %T
(threadPHID, transactionPHID, previousTransactionPHID, corpus)
VALUES (%s, %s, %ns, %s)
ON DUPLICATE KEY UPDATE corpus = VALUES(corpus)'
,
$index
->
getTableName
(),
$index
->
getThreadPHID
(),
$index
->
getTransactionPHID
(),
$index
->
getPreviousTransactionPHID
(),
$index
->
getCorpus
());
}
}
Event Timeline
Log In to Comment