mongodb 字段检索
Phabricator is an incredibly well-coded PHP application but lacks a bit on the documentation side. Then again, what open source project isn't? Over the past months I've been slowly integrating Phabricator, a newish review tool, with Bugzilla, a much older tool. The most recent step saw me needing to add a custom field (DifferentialCommitMessageCustomField
class extension) to revisions:
Phabricator是一个编码非常出色PHP应用程序,但在文档方面缺乏一点。 再说一次,什么不是开源项目? 在过去的几个月中,我一直在缓慢地将Phabricator(一种新的查看工具)与一个较旧的工具Bugzilla集成在一起。 最近的步骤是我需要向修订添加一个自定义字段( DifferentialCommitMessageCustomField
类扩展):
Creating the DifferentialCommitMessageCustomField
extension was fairly simple but, due to the structure of DifferentialRevision
and other Phabricator classes, retrieving that field value isn't as easy as one would hope. After trying a variety of methods and combing through the classes chain source code, it was Aviv Eyal that provided a nice utility function for retrieving custom field data for a given Phabricator object type:
创建DifferentialCommitMessageCustomField
扩展非常简单,但是由于DifferentialRevision
和其他Phabricator类的结构,检索字段值并不像人们希望的那样容易。 在尝试了各种方法并梳理了类链的源代码之后,Aviv Eyal提供了一个很好的实用程序函数来检索给定Phabricator对象类型的自定义字段数据:
function get_custom_field_value($object, $key_field) { $field = PhabricatorCustomField::getObjectField( $object, PhabricatorCustomField::ROLE_DEFAULT, $key_field ); id(new PhabricatorCustomFieldStorageQuery()) ->addField($field) ->execute(); $value = $field->getValueForStorage(); return $value;}
In my case, the $object
was a DifferentialRevision
and the $key_field
is differential:bugzilla-bug-id
, defined within my DifferentialCommitMessageCustomField
extension. If you are adding a CustomField
of any kind to any Phabrication application, you can use this same method.
在我的情况下, $object
是DifferentialRevision
, $key_field
是differential:bugzilla-bug-id
,在我的DifferentialCommitMessageCustomField
扩展中定义。 如果要将任何CustomField
添加到任何Phabrication应用程序,则可以使用相同的方法。
When documentation is lacking and inheritance levels a dozen levels deep, it's great that community members can jump in to help each other -- it speaks volumes for the project.
当缺少文档并且继承层次很深时,社区成员可以互相帮助是一件很不错的事-它可以说是项目的重中之重。
翻译自:
mongodb 字段检索