mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Conduit: user.find
This commit is contained in:
parent
9f026d7892
commit
2bea542920
10 changed files with 155 additions and 33 deletions
|
@ -20,6 +20,7 @@ phutil_register_library_map(array(
|
|||
'AphrontFileResponse' => 'aphront/response/file',
|
||||
'AphrontFormControl' => 'view/form/control/base',
|
||||
'AphrontFormFileControl' => 'view/form/control/file',
|
||||
'AphrontFormMarkupControl' => 'view/form/control/markup',
|
||||
'AphrontFormSelectControl' => 'view/form/control/select',
|
||||
'AphrontFormStaticControl' => 'view/form/control/static',
|
||||
'AphrontFormSubmitControl' => 'view/form/control/submit',
|
||||
|
@ -50,6 +51,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_conduit_connect_Method' => 'applications/conduit/method/conduit/connect',
|
||||
'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/creatediff',
|
||||
'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload',
|
||||
'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find',
|
||||
'ConduitException' => 'applications/conduit/protocol/exception',
|
||||
'DifferentialAction' => 'applications/differential/constants/action',
|
||||
'DifferentialChangeType' => 'applications/differential/constants/changetype',
|
||||
|
@ -129,6 +131,7 @@ phutil_register_library_map(array(
|
|||
'AphrontFileResponse' => 'AphrontResponse',
|
||||
'AphrontFormControl' => 'AphrontView',
|
||||
'AphrontFormFileControl' => 'AphrontFormControl',
|
||||
'AphrontFormMarkupControl' => 'AphrontFormControl',
|
||||
'AphrontFormSelectControl' => 'AphrontFormControl',
|
||||
'AphrontFormStaticControl' => 'AphrontFormControl',
|
||||
'AphrontFormSubmitControl' => 'AphrontFormControl',
|
||||
|
@ -152,6 +155,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_conduit_connect_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_user_find_Method' => 'ConduitAPIMethod',
|
||||
'DifferentialChangeset' => 'DifferentialDAO',
|
||||
'DifferentialDAO' => 'PhabricatorLiskDAO',
|
||||
'DifferentialDiff' => 'DifferentialDAO',
|
||||
|
|
|
@ -59,15 +59,13 @@ class PhabricatorConduitConsoleController
|
|||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
->setLabel('Description')
|
||||
->setValue(
|
||||
phutil_escape_html($method_object->getMethodDescription())))
|
||||
->setValue($method_object->getMethodDescription()))
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
->setLabel('Returns')
|
||||
->setValue(
|
||||
phutil_escape_html($method_object->defineReturnType())))
|
||||
->setValue($method_object->defineReturnType()))
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setLabel('Errors')
|
||||
->setValue($error_description))
|
||||
->appendChild(
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class ConduitAPI_user_find_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Find user PHIDs which correspond to provided user aliases. ".
|
||||
"Returns NULL for aliases which do have any corresponding PHIDs.";
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'aliases' => 'required nonempty list<string>'
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'nonempty dict<string, phid>';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$users = id(new PhabricatorUser())->loadAllWhere(
|
||||
'username in (%Ls)',
|
||||
$request->getValue('aliases'));
|
||||
|
||||
return mpull($users, 'getPHID', 'getUsername');
|
||||
}
|
||||
|
||||
}
|
15
src/applications/conduit/method/user/find/__init__.php
Normal file
15
src/applications/conduit/method/user/find/__init__.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('ConduitAPI_user_find_Method.php');
|
|
@ -30,6 +30,8 @@ class DifferentialChangeset extends DifferentialDAO {
|
|||
protected $addLines;
|
||||
protected $delLines;
|
||||
|
||||
private $unsavedHunks = array();
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_SERIALIZATION => array(
|
||||
|
@ -60,27 +62,11 @@ class DifferentialChangeset extends DifferentialDAO {
|
|||
return $name;
|
||||
}
|
||||
|
||||
public function addHunk(DifferentialHunk $hunk) {
|
||||
if (!isset($this->_hunks)) {
|
||||
$this->_hunks = array();
|
||||
}
|
||||
$this->_hunks[] = $hunk;
|
||||
|
||||
public function addUnsavedHunk(DifferentialHunk $hunk) {
|
||||
$this->unsavedHunks[] = $hunk;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function attachHunks(array $hunks) {
|
||||
$this->_hunks = $hunks;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHunks() {
|
||||
if (!isset($this->_hunks)) {
|
||||
throw new Exception("You must load hunks before accessing them.");
|
||||
}
|
||||
return $this->_hunks;
|
||||
}
|
||||
|
||||
public function loadHunks() {
|
||||
if (!$this->getID()) {
|
||||
return array();
|
||||
|
@ -90,15 +76,26 @@ class DifferentialChangeset extends DifferentialDAO {
|
|||
$this->getID());
|
||||
}
|
||||
|
||||
public function save() {
|
||||
// TODO: Sort out transactions
|
||||
// $this->openTransaction();
|
||||
$ret = parent::save();
|
||||
foreach ($this->unsavedHunks as $hunk) {
|
||||
$hunk->setChangesetID($this->getID());
|
||||
$hunk->save();
|
||||
}
|
||||
// $this->saveTransaction();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->openTransaction();
|
||||
// $this->openTransaction();
|
||||
foreach ($this->loadHunks() as $hunk) {
|
||||
$hunk->delete();
|
||||
}
|
||||
$this->_hunks = array();
|
||||
$ret = parent::delete();
|
||||
$this->saveTransaction();
|
||||
// $this->saveTransaction();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,13 @@ class DifferentialDiff extends DifferentialDAO {
|
|||
protected $arcanistProject;
|
||||
protected $creationMethod;
|
||||
|
||||
private $unsavedChangesets = array();
|
||||
|
||||
public function addUnsavedChangeset(DifferentialChangeset $changeset) {
|
||||
$this->unsavedChangesets[] = $changeset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadChangesets() {
|
||||
if (!$this->getID()) {
|
||||
return array();
|
||||
|
@ -48,13 +55,25 @@ class DifferentialDiff extends DifferentialDAO {
|
|||
$this->getID());
|
||||
}
|
||||
|
||||
public function save() {
|
||||
// TODO: sort out transactions
|
||||
// $this->openTransaction();
|
||||
$ret = parent::save();
|
||||
foreach ($this->unsavedChangesets as $changeset) {
|
||||
// $changeset->setDiffID($this->getID());
|
||||
// $changeset->save();
|
||||
}
|
||||
// $this->saveTransaction();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->openTransaction();
|
||||
// $this->openTransaction();
|
||||
foreach ($this->loadChangesets() as $changeset) {
|
||||
$changeset->delete();
|
||||
}
|
||||
$ret = parent::delete();
|
||||
$this->saveTransaction();
|
||||
// $this->saveTransaction();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -67,21 +86,19 @@ class DifferentialDiff extends DifferentialDAO {
|
|||
$add_lines = 0;
|
||||
$del_lines = 0;
|
||||
foreach ($change->getHunks() as $hunk) {
|
||||
$dhunk = new Hunk();
|
||||
$dhunk = new DifferentialHunk();
|
||||
$dhunk->setOldOffset($hunk->getOldOffset());
|
||||
$dhunk->setOldLen($hunk->getOldLength());
|
||||
$dhunk->setNewOffset($hunk->getNewOffset());
|
||||
$dhunk->setNewLen($hunk->getNewLength());
|
||||
$dhunk->setChanges($hunk->getCorpus());
|
||||
$changeset->addHunk($dhunk);
|
||||
$changeset->addUnsavedHunk($dhunk);
|
||||
$add_lines += $hunk->getAddLines();
|
||||
$del_lines += $hunk->getDelLines();
|
||||
$lines += $add_lines + $del_lines;
|
||||
}
|
||||
$changeset->setHunkCount(count($change->getHunks()));
|
||||
|
||||
$changeset->setOldFile($change->getOldPath());
|
||||
$changeset->setNewFile($change->getCurrentPath());
|
||||
$changeset->setFilename($change->getCurrentPath());
|
||||
$changeset->setChangeType($change->getType());
|
||||
|
||||
|
@ -93,7 +110,7 @@ class DifferentialDiff extends DifferentialDAO {
|
|||
$changeset->setAddLines($add_lines);
|
||||
$changeset->setDelLines($del_lines);
|
||||
|
||||
$diff->addChangeset($changeset);
|
||||
$diff->addUnsavedChangeset($changeset);
|
||||
}
|
||||
$diff->setLineCount($lines);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/base');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/changeset');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/hunk');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ abstract class LiskDAO {
|
|||
if (!isset($properties)) {
|
||||
$class = new ReflectionClass(get_class($this));
|
||||
$properties = array();
|
||||
foreach ($class->getProperties() as $p) {
|
||||
foreach ($class->getProperties(ReflectionProperty::IS_PROTECTED) as $p) {
|
||||
$properties[strtolower($p->getName())] = $p->getName();
|
||||
}
|
||||
|
||||
|
|
29
src/view/form/control/markup/AphrontFormMarkupControl.php
Executable file
29
src/view/form/control/markup/AphrontFormMarkupControl.php
Executable file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class AphrontFormMarkupControl extends AphrontFormControl {
|
||||
|
||||
protected function getCustomControlClass() {
|
||||
return 'aphront-form-control-markup';
|
||||
}
|
||||
|
||||
protected function renderInput() {
|
||||
return $this->getValue();
|
||||
}
|
||||
|
||||
}
|
12
src/view/form/control/markup/__init__.php
Normal file
12
src/view/form/control/markup/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'view/form/control/base');
|
||||
|
||||
|
||||
phutil_require_source('AphrontFormMarkupControl.php');
|
Loading…
Reference in a new issue