Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96168924
ConduitAPI_phragment_queryfragments_Method.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
Mon, Dec 23, 09:48
Size
2 KB
Mime Type
text/x-php
Expires
Wed, Dec 25, 09:48 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
23137322
Attached To
rPH Phabricator
ConduitAPI_phragment_queryfragments_Method.php
View Options
<?php
/**
* @group conduit
*/
final
class
ConduitAPI_phragment_queryfragments_Method
extends
ConduitAPI_phragment_Method
{
public
function
getMethodStatus
()
{
return
self
::
METHOD_STATUS_UNSTABLE
;
}
public
function
getMethodDescription
()
{
return
pht
(
"Query fragments based on their paths."
);
}
public
function
defineParamTypes
()
{
return
array
(
'paths'
=>
'required list<string>'
,
);
}
public
function
defineReturnType
()
{
return
'nonempty dict'
;
}
public
function
defineErrorTypes
()
{
return
array
(
'ERR_BAD_FRAGMENT'
=>
'No such fragment exists'
,
);
}
protected
function
execute
(
ConduitAPIRequest
$request
)
{
$paths
=
$request
->
getValue
(
'paths'
);
$fragments
=
id
(
new
PhragmentFragmentQuery
())
->
setViewer
(
$request
->
getUser
())
->
withPaths
(
$paths
)
->
execute
();
$fragments
=
mpull
(
$fragments
,
null
,
'getPath'
);
foreach
(
$paths
as
$path
)
{
if
(!
array_key_exists
(
$path
,
$fragments
))
{
throw
new
ConduitException
(
'ERR_BAD_FRAGMENT'
);
}
}
$results
=
array
();
foreach
(
$fragments
as
$path
=>
$fragment
)
{
$mappings
=
$fragment
->
getFragmentMappings
(
$request
->
getUser
(),
$fragment
->
getPath
());
$file_phids
=
mpull
(
mpull
(
$mappings
,
'getLatestVersion'
),
'getFilePHID'
);
$files
=
id
(
new
PhabricatorFileQuery
())
->
setViewer
(
$request
->
getUser
())
->
withPHIDs
(
$file_phids
)
->
execute
();
$files
=
mpull
(
$files
,
null
,
'getPHID'
);
$result
=
array
();
foreach
(
$mappings
as
$cpath
=>
$child
)
{
$file_phid
=
$child
->
getLatestVersion
()->
getFilePHID
();
if
(!
isset
(
$files
[
$file_phid
]))
{
// Skip any files we don't have permission to access.
continue
;
}
$file
=
$files
[
$file_phid
];
$cpath
=
substr
(
$child
->
getPath
(),
strlen
(
$fragment
->
getPath
())
+
1
);
$result
[]
=
array
(
'phid'
=>
$child
->
getPHID
(),
'phidVersion'
=>
$child
->
getLatestVersionPHID
(),
'path'
=>
$cpath
,
'hash'
=>
$file
->
getContentHash
(),
'version'
=>
$child
->
getLatestVersion
()->
getSequence
(),
'uri'
=>
$file
->
getViewURI
());
}
$results
[
$path
]
=
$result
;
}
return
$results
;
}
}
Event Timeline
Log In to Comment