Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/herald/controller/all/HeraldAllRulesController.php b/src/applications/herald/controller/all/HeraldAllRulesController.php
index f78ea70ab0..2e69d7bb9f 100644
--- a/src/applications/herald/controller/all/HeraldAllRulesController.php
+++ b/src/applications/herald/controller/all/HeraldAllRulesController.php
@@ -1,158 +1,171 @@
<?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 HeraldAllRulesController extends HeraldController {
private $view;
private $viewPHID;
+ private $filter;
+
+ public function getFilter() {
+ return $this->filter;
+ }
+ public function setFilter($filter) {
+ $this->filter = 'all/view/'.$filter;
+ return $this;
+ }
public function shouldRequireAdmin() {
return true;
}
public function willProcessRequest(array $data) {
$this->view = idx($data, 'view');
+ $this->setFilter($this->view);
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$this->viewPHID = nonempty($request->getStr('phid'), null);
if ($request->isFormPost()) {
$phid_arr = $request->getArr('view_user');
$view_target = head($phid_arr);
return id(new AphrontRedirectResponse())
->setURI($request->getRequestURI()->alter('phid', $view_target));
}
$map = HeraldContentTypeConfig::getContentTypeMap();
if (empty($map[$this->view])) {
reset($map);
$this->view = key($map);
}
$offset = $request->getInt('offset', 0);
$pager = new AphrontPagerView();
$pager->setPageSize(50);
$pager->setOffset($offset);
$pager->setURI($request->getRequestURI(), 'offset');
list($rules, $handles) = $this->queryRules($pager);
if (!$this->viewPHID) {
$view_users = array();
} else {
$view_users = array(
$this->viewPHID => $handles[$this->viewPHID]->getFullName(),
);
}
$filter_form = id(new AphrontFormView())
->setUser($user)
->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/users/')
->setLabel('View User')
->setName('view_user')
->setValue($view_users)
->setLimit(1));
$filter_view = new AphrontListFilterView();
$filter_view->appendChild($filter_form);
$list_view = id(new HeraldRuleListView())
->setRules($rules)
->setHandles($handles)
->setMap($map)
->setAllowCreation(false)
->setView($this->view);
$panel = $list_view->render();
$panel->appendChild($pager);
$sidenav = new AphrontSideNavView();
$sidenav->appendChild($filter_view);
$sidenav->appendChild($panel);
$query = '';
if ($this->viewPHID) {
$query = '?phid='.$this->viewPHID;
}
foreach ($map as $key => $value) {
$sidenav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/herald/all/view/'.$key.'/'.$query,
'class' => ($key == $this->view)
? 'aphront-side-nav-selected'
: null,
),
phutil_escape_html($value)));
}
return $this->buildStandardPageResponse(
- $sidenav,
+ array(
+ $filter_view,
+ $panel
+ ),
array(
'title' => 'Herald',
'tab' => 'all',
));
}
private function queryRules(AphrontPagerView $pager) {
$rule = new HeraldRule();
$conn_r = $rule->establishConnection('r');
$where_clause = qsprintf(
$conn_r,
'WHERE contentType = %s',
$this->view);
if ($this->viewPHID) {
$where_clause .= qsprintf(
$conn_r,
' AND authorPHID = %s',
$this->viewPHID);
}
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T
%Q
ORDER BY id DESC
LIMIT %d, %d',
$rule->getTableName(),
$where_clause,
$pager->getOffset(),
$pager->getPageSize() + 1);
$data = $pager->sliceResults($data);
$rules = $rule->loadAllFromArray($data);
$need_phids = mpull($rules, 'getAuthorPHID');
if ($this->viewPHID) {
$need_phids[] = $this->viewPHID;
}
$handles = id(new PhabricatorObjectHandleData($need_phids))
->loadHandles();
return array($rules, $handles);
}
}
diff --git a/src/applications/herald/controller/base/HeraldController.php b/src/applications/herald/controller/base/HeraldController.php
index fa70b204b7..7a9720b6e4 100644
--- a/src/applications/herald/controller/base/HeraldController.php
+++ b/src/applications/herald/controller/base/HeraldController.php
@@ -1,67 +1,81 @@
<?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.
*/
abstract class HeraldController extends PhabricatorController {
public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView();
$page->setApplicationName('Herald');
$page->setBaseURI('/herald/');
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x98\xBF");
- $page->appendChild($view);
$doclink = PhabricatorEnv::getDoclink('article/Herald_User_Guide.html');
+ $nav = new AphrontSideNavFilterView();
+ $nav
+ ->setBaseURI(new PhutilURI('/herald/'))
+ ->addLabel('Rules')
+ ->addFilter('new', 'Create Rule');
+ $rules_map = HeraldContentTypeConfig::getContentTypeMap();
+ $first_filter = null;
+ foreach ($rules_map as $key => $value) {
+ $nav->addFilter('view/'.$key, $value);
+ if (!$first_filter) {
+ $first_filter = 'view/'.$key;
+ }
+ }
+
+ $nav
+ ->addSpacer()
+ ->addLabel('Utilities')
+ ->addFilter('test', 'Test Console')
+ ->addFilter('transcript', 'Transcripts');
+
+ $user = $this->getRequest()->getUser();
+ if ($user->getIsAdmin()) {
+ $nav
+ ->addSpacer()
+ ->addLabel('Admin');
+ $view_PHID = nonempty($this->getRequest()->getStr('phid'), null);
+ foreach ($rules_map as $key => $value) {
+ $nav
+ ->addFilter('all/view/'.$key, $value);
+ }
+ }
+
+ $nav->selectFilter($this->getFilter(), $first_filter);
+ $nav->appendChild($view);
+ $page->appendChild($nav);
+
$tabs = array(
- 'rules' => array(
- 'href' => '/herald/',
- 'name' => 'Rules',
- ),
- 'test' => array(
- 'href' => '/herald/test/',
- 'name' => 'Test Console',
- ),
- 'transcripts' => array(
- 'href' => '/herald/transcript/',
- 'name' => 'Transcripts',
- ),
'help' => array(
'href' => $doclink,
'name' => 'Help',
),
);
-
- $user = $this->getRequest()->getUser();
- if ($user->getIsAdmin()) {
- $tabs['all'] = array(
- 'href' => '/herald/all',
- 'name' => 'All Rules',
- );
- }
-
- $page->setTabs(
- $tabs,
- idx($data, 'tab'));
+ $page->setTabs($tabs. null);
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());
}
+
+ abstract function getFilter();
}
diff --git a/src/applications/herald/controller/base/__init__.php b/src/applications/herald/controller/base/__init__.php
index d6e0098e21..409c873f20 100644
--- a/src/applications/herald/controller/base/__init__.php
+++ b/src/applications/herald/controller/base/__init__.php
@@ -1,16 +1,19 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/webpage');
phutil_require_module('phabricator', 'applications/base/controller/base');
+phutil_require_module('phabricator', 'applications/herald/config/contenttype');
phutil_require_module('phabricator', 'infrastructure/env');
+phutil_require_module('phabricator', 'view/layout/sidenavfilter');
+phutil_require_module('phutil', 'parser/uri');
phutil_require_module('phutil', 'utils');
phutil_require_source('HeraldController.php');
diff --git a/src/applications/herald/controller/delete/HeraldDeleteController.php b/src/applications/herald/controller/delete/HeraldDeleteController.php
index 291aed4196..fb5157fd47 100644
--- a/src/applications/herald/controller/delete/HeraldDeleteController.php
+++ b/src/applications/herald/controller/delete/HeraldDeleteController.php
@@ -1,64 +1,70 @@
<?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 HeraldDeleteController extends HeraldController {
private $id;
+ public function getFilter() {
+ // note this controller is only used from a dialog-context at the moment
+ // and there is actually no "delete" filter
+ return 'delete';
+ }
+
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$rule = id(new HeraldRule())->load($this->id);
if (!$rule) {
return new Aphront404Response();
}
$request = $this->getRequest();
$user = $request->getUser();
if ($user->getPHID() != $rule->getAuthorPHID() && !$user->getIsAdmin()) {
return new Aphront400Response();
}
if ($request->isFormPost()) {
$rule->delete();
if ($request->isAjax()) {
return new AphrontRedirectResponse();
} else {
return id(new AphrontRedirectResponse())->setURI('/herald/');
}
}
$dialog = new AphrontDialogView();
$dialog->setUser($request->getUser());
$dialog->setTitle('Really delete this rule?');
$dialog->appendChild(
"Are you sure you want to delete the rule ".
"'<strong>".phutil_escape_html($rule->getName())."</strong>'?");
$dialog->addSubmitButton('Delete');
$dialog->addCancelButton('/herald/');
$dialog->setSubmitURI($request->getPath());
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
diff --git a/src/applications/herald/controller/home/HeraldHomeController.php b/src/applications/herald/controller/home/HeraldHomeController.php
index 0a8293d552..9771c632a9 100644
--- a/src/applications/herald/controller/home/HeraldHomeController.php
+++ b/src/applications/herald/controller/home/HeraldHomeController.php
@@ -1,79 +1,72 @@
<?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 HeraldHomeController extends HeraldController {
private $view;
+ private $filter;
public function willProcessRequest(array $data) {
$this->view = idx($data, 'view');
+ $this->setFilter($this->view);
+ }
+
+ public function getFilter() {
+ return $this->filter;
+ }
+ public function setFilter($filter) {
+ $this->filter = 'view/'.$filter;
+ return $this;
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$map = HeraldContentTypeConfig::getContentTypeMap();
if (empty($map[$this->view])) {
reset($map);
$this->view = key($map);
}
$rules = id(new HeraldRule())->loadAllWhere(
'contentType = %s AND authorPHID = %s',
$this->view,
$user->getPHID());
$need_phids = mpull($rules, 'getAuthorPHID');
$handles = id(new PhabricatorObjectHandleData($need_phids))
->loadHandles();
$list_view = id(new HeraldRuleListView())
->setRules($rules)
->setHandles($handles)
->setMap($map)
->setAllowCreation(true)
->setView($this->view);
$panel = $list_view->render();
- $sidenav = new AphrontSideNavView();
- $sidenav->appendChild($panel);
-
- foreach ($map as $key => $value) {
- $sidenav->addNavItem(
- phutil_render_tag(
- 'a',
- array(
- 'href' => '/herald/view/'.$key.'/',
- 'class' => ($key == $this->view)
- ? 'aphront-side-nav-selected'
- : null,
- ),
- phutil_escape_html($value)));
- }
return $this->buildStandardPageResponse(
- $sidenav,
+ $panel,
array(
'title' => 'Herald',
- 'tab' => 'rules',
));
}
-
}
diff --git a/src/applications/herald/controller/home/__init__.php b/src/applications/herald/controller/home/__init__.php
index 336ecb982f..a4347e6adb 100644
--- a/src/applications/herald/controller/home/__init__.php
+++ b/src/applications/herald/controller/home/__init__.php
@@ -1,20 +1,18 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/herald/config/contenttype');
phutil_require_module('phabricator', 'applications/herald/controller/base');
phutil_require_module('phabricator', 'applications/herald/storage/rule');
phutil_require_module('phabricator', 'applications/herald/view/rulelist');
phutil_require_module('phabricator', 'applications/phid/handle/data');
-phutil_require_module('phabricator', 'view/layout/sidenav');
-phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('HeraldHomeController.php');
diff --git a/src/applications/herald/controller/new/HeraldNewController.php b/src/applications/herald/controller/new/HeraldNewController.php
index 54f765527b..71e34da1cc 100644
--- a/src/applications/herald/controller/new/HeraldNewController.php
+++ b/src/applications/herald/controller/new/HeraldNewController.php
@@ -1,64 +1,68 @@
<?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 HeraldNewController extends HeraldController {
private $type;
+ public function getFilter() {
+ return 'new';
+ }
+
public function willProcessRequest(array $data) {
$this->type = idx($data, 'type');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$map = HeraldContentTypeConfig::getContentTypeMap();
if (empty($map[$this->type])) {
reset($map);
$this->type = key($map);
}
$form = id(new AphrontFormView())
->setUser($user)
->setAction('/herald/rule/')
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('New rule for')
->setName('type')
->setValue($this->type)
->setOptions($map))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Create Rule')
->addCancelButton('/herald/view/'.$this->type.'/'));
$panel = new AphrontPanelView();
$panel->setHeader('Create New Herald Rule');
- $panel->setWidth(AphrontPanelView::WIDTH_FORM);
+ $panel->setWidth(AphrontPanelView::WIDTH_FULL);
$panel->appendChild($form);
return $this->buildStandardPageResponse(
$panel,
array(
'title' => 'Create Herald Rule',
));
}
}
diff --git a/src/applications/herald/controller/rule/HeraldRuleController.php b/src/applications/herald/controller/rule/HeraldRuleController.php
index 67de87388d..5b8a63d526 100644
--- a/src/applications/herald/controller/rule/HeraldRuleController.php
+++ b/src/applications/herald/controller/rule/HeraldRuleController.php
@@ -1,541 +1,550 @@
<?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 HeraldRuleController extends HeraldController {
private $id;
+ private $filter;
+
+ public function getFilter() {
+ return $this->filter;
+ }
+ public function setFilter($filter) {
+ $this->filter = 'view/'.$filter;
+ }
public function willProcessRequest(array $data) {
$this->id = (int)idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$content_type_map = HeraldContentTypeConfig::getContentTypeMap();
if ($this->id) {
$rule = id(new HeraldRule())->load($this->id);
if (!$rule) {
return new Aphront404Response();
}
if ($rule->getAuthorPHID() != $user->getPHID() && !$user->getIsAdmin()) {
throw new Exception("You don't own this rule and can't edit it.");
}
} else {
$rule = new HeraldRule();
$rule->setAuthorPHID($user->getPHID());
$rule->setMustMatchAll(true);
$type = $request->getStr('type');
if (!isset($content_type_map[$type])) {
$type = HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL;
}
$rule->setContentType($type);
}
+ $this->setFilter($rule->getContentType());
$local_version = id(new HeraldRule())->getConfigVersion();
if ($rule->getConfigVersion() > $local_version) {
throw new Exception(
"This rule was created with a newer version of Herald. You can not ".
"view or edit it in this older version. Try dev or wait for a push.");
}
// Upgrade rule version to our version, since we might add newly-defined
// conditions, etc.
$rule->setConfigVersion($local_version);
$rule_conditions = $rule->loadConditions();
$rule_actions = $rule->loadActions();
$rule->attachConditions($rule_conditions);
$rule->attachActions($rule_actions);
$e_name = true;
$errors = array();
if ($request->isFormPost() && $request->getStr('save')) {
list($e_name, $errors) = $this->saveRule($rule, $request);
if (!$errors) {
$uri = '/herald/view/'.$rule->getContentType().'/';
return id(new AphrontRedirectResponse())
->setURI($uri);
}
}
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle('Form Errors');
$error_view->setErrors($errors);
} else {
$error_view = null;
}
$must_match_selector = $this->getMustMatchSelector($rule);
$repetition_selector = $this->getRepetitionSelector($rule);
$handles = $this->loadHandles($rule);
require_celerity_resource('herald-css');
$type_name = $content_type_map[$rule->getContentType()];
$form = id(new AphrontFormView())
->setUser($user)
->setID('herald-rule-edit-form')
->addHiddenInput('type', $rule->getContentType())
->addHiddenInput('save', 1)
->appendChild(
// Build this explicitly so we can add a sigil to it.
javelin_render_tag(
'input',
array(
'type' => 'hidden',
'name' => 'rule',
'sigil' => 'rule',
)))
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Rule Name')
->setName('name')
->setError($e_name)
->setValue($rule->getName()))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Author')
->setValue($handles[$rule->getAuthorPHID()]->getName()))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue(
"This rule triggers for <strong>{$type_name}</strong>."))
->appendChild(
'<h1>Conditions</h1>'.
'<div class="aphront-form-inset">'.
'<div style="float: right;">'.
javelin_render_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'create-condition',
'mustcapture' => true,
),
'Create New Condition').
'</div>'.
'<p>When '.$must_match_selector.' these conditions are met:</p>'.
'<div style="clear: both;"></div>'.
javelin_render_tag(
'table',
array(
'sigil' => 'rule-conditions',
'class' => 'herald-condition-table',
),
'').
'</div>')
->appendChild(
'<h1>Action</h1>'.
'<div class="aphront-form-inset">'.
'<div style="float: right;">'.
javelin_render_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'create-action',
'mustcapture' => true,
),
'Create New Action').
'</div>'.
'<p>'.
'Take these actions '.$repetition_selector.' this rule matches:'.
'</p>'.
'<div style="clear: both;"></div>'.
javelin_render_tag(
'table',
array(
'sigil' => 'rule-actions',
'class' => 'herald-action-table',
),
'').
'</div>')
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Save Rule')
->addCancelButton('/herald/view/'.$rule->getContentType().'/'));
$this->setupEditorBehavior($rule, $handles);
$panel = new AphrontPanelView();
$panel->setHeader('Edit Herald Rule');
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
$panel->appendChild($form);
return $this->buildStandardPageResponse(
array(
$error_view,
$panel,
),
array(
'title' => 'Edit Rule',
));
}
private function saveRule($rule, $request) {
$rule->setName($request->getStr('name'));
$rule->setMustMatchAll(($request->getStr('must_match') == 'all'));
$repetition_policy_param = $request->getStr('repetition_policy');
$rule->setRepetitionPolicy(
HeraldRepetitionPolicyConfig::toInt($repetition_policy_param)
);
$e_name = true;
$errors = array();
if (!strlen($rule->getName())) {
$e_name = "Required";
$errors[] = "Rule must have a name.";
}
$data = json_decode($request->getStr('rule'), true);
if (!is_array($data) ||
!$data['conditions'] ||
!$data['actions']) {
throw new Exception("Failed to decode rule data.");
}
$conditions = array();
foreach ($data['conditions'] as $condition) {
if ($condition === null) {
// We manage this as a sparse array on the client, so may receive
// NULL if conditions have been removed.
continue;
}
$obj = new HeraldCondition();
$obj->setFieldName($condition[0]);
$obj->setFieldCondition($condition[1]);
if (is_array($condition[2])) {
$obj->setValue(array_keys($condition[2]));
} else {
$obj->setValue($condition[2]);
}
$cond_type = $obj->getFieldCondition();
if ($cond_type == HeraldConditionConfig::CONDITION_REGEXP) {
if (@preg_match($obj->getValue(), '') === false) {
$errors[] =
'The regular expression "'.$obj->getValue().'" is not valid. '.
'Regular expressions must have enclosing characters (e.g. '.
'"@/path/to/file@", not "/path/to/file") and be syntactically '.
'correct.';
}
}
if ($cond_type == HeraldConditionConfig::CONDITION_REGEXP_PAIR) {
$json = json_decode($obj->getValue(), true);
if (!is_array($json)) {
$errors[] =
'The regular expression pair "'.$obj->getValue().'" is not '.
'valid JSON. Enter a valid JSON array with two elements.';
} else {
if (count($json) != 2) {
$errors[] =
'The regular expression pair "'.$obj->getValue().'" must have '.
'exactly two elements.';
} else {
$key_regexp = array_shift($json);
$val_regexp = array_shift($json);
if (@preg_match($key_regexp, '') === false) {
$errors[] =
'The first regexp, "'.$key_regexp.'" in the regexp pair '.
'is not a valid regexp.';
}
if (@preg_match($val_regexp, '') === false) {
$errors[] =
'The second regexp, "'.$val_regexp.'" in the regexp pair '.
'is not a valid regexp.';
}
}
}
}
$conditions[] = $obj;
}
$actions = array();
foreach ($data['actions'] as $action) {
if ($action === null) {
// Sparse on the client; removals can give us NULLs.
continue;
}
$obj = new HeraldAction();
$obj->setAction($action[0]);
if (!isset($action[1])) {
// Legitimate for any action which doesn't need a target, like
// "Do nothing".
$action[1] = null;
}
if (is_array($action[1])) {
$obj->setTarget(array_keys($action[1]));
} else {
$obj->setTarget($action[1]);
}
$actions[] = $obj;
}
$rule->attachConditions($conditions);
$rule->attachActions($actions);
if (!$errors) {
try {
// TODO
// $rule->openTransaction();
$rule->save();
$rule->saveConditions($conditions);
$rule->saveActions($actions);
// $rule->saveTransaction();
} catch (AphrontQueryDuplicateKeyException $ex) {
$e_name = "Not Unique";
$errors[] = "Rule name is not unique. Choose a unique name.";
}
}
return array($e_name, $errors);
}
private function setupEditorBehavior($rule, $handles) {
$serial_conditions = array(
array('default', 'default', ''),
);
if ($rule->getConditions()) {
$serial_conditions = array();
foreach ($rule->getConditions() as $condition) {
$value = $condition->getValue();
if (is_array($value)) {
$value_map = array();
foreach ($value as $k => $fbid) {
$value_map[$fbid] = $handles[$fbid]->getName();
}
$value = $value_map;
}
$serial_conditions[] = array(
$condition->getFieldName(),
$condition->getFieldCondition(),
$value,
);
}
}
$serial_actions = array(
array('default', ''),
);
if ($rule->getActions()) {
$serial_actions = array();
foreach ($rule->getActions() as $action) {
$target_map = array();
foreach ((array)$action->getTarget() as $fbid) {
$target_map[$fbid] = $handles[$fbid]->getName();
}
$serial_actions[] = array(
$action->getAction(),
$target_map,
);
}
}
$all_rules = id(new HeraldRule())->loadAllWhere(
'authorPHID = %s AND contentType = %s',
$rule->getAuthorPHID(),
$rule->getContentType());
$all_rules = mpull($all_rules, 'getName', 'getID');
asort($all_rules);
unset($all_rules[$rule->getID()]);
$config_info = array();
$config_info['fields']
= HeraldFieldConfig::getFieldMapForContentType($rule->getContentType());
$config_info['conditions'] = HeraldConditionConfig::getConditionMap();
foreach ($config_info['fields'] as $field => $name) {
$config_info['conditionMap'][$field] = array_keys(
HeraldConditionConfig::getConditionMapForField($field));
}
foreach ($config_info['fields'] as $field => $fname) {
foreach ($config_info['conditions'] as $condition => $cname) {
$config_info['values'][$field][$condition] =
HeraldValueTypeConfig::getValueTypeForFieldAndCondition(
$field,
$condition);
}
}
$config_info['actions'] =
HeraldActionConfig::getActionMapForContentType($rule->getContentType());
foreach ($config_info['actions'] as $action => $name) {
$config_info['targets'][$action] =
HeraldValueTypeConfig::getValueTypeForAction($action);
}
Javelin::initBehavior(
'herald-rule-editor',
array(
'root' => 'herald-rule-edit-form',
'conditions' => (object)$serial_conditions,
'actions' => (object)$serial_actions,
'template' => $this->buildTokenizerTemplates() + array(
'rules' => $all_rules,
),
'info' => $config_info,
));
}
private function loadHandles($rule) {
$phids = array();
$phids[] = $rule->getAuthorPHID();
foreach ($rule->getActions() as $action) {
if (!is_array($action->getTarget())) {
continue;
}
foreach ($action->getTarget() as $target) {
$target = (array)$target;
foreach ($target as $phid) {
$phids[] = $phid;
}
}
}
foreach ($rule->getConditions() as $condition) {
$value = $condition->getValue();
if (is_array($value)) {
foreach ($value as $phid) {
$phids[] = $phid;
}
}
}
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
return $handles;
}
private function getMustMatchSelector($rule) {
$options = array(
'all' => 'all of',
'any' => 'any of',
);
$selected = $rule->getMustMatchAll() ? 'all' : 'any';
$must_match = array();
foreach ($options as $key => $option) {
$must_match[] = phutil_render_tag(
'option',
array(
'selected' => ($selected == $key) ? 'selected' : null,
'value' => $key,
),
phutil_escape_html($option));
}
$must_match =
'<select name="must_match">' .
implode("\n", $must_match) .
'</select>';
return $must_match;
}
private function getRepetitionSelector($rule) {
// Make the selector for choosing how often this rule should be repeated
$repetition_policy = HeraldRepetitionPolicyConfig::toString(
$rule->getRepetitionPolicy()
);
$repetition_options = HeraldRepetitionPolicyConfig::getMapForContentType(
$rule->getContentType()
);
if (empty($repetition_options)) {
// default option is 'every time'
$repetition_selector = idx(
HeraldRepetitionPolicyConfig::getMap(),
HeraldRepetitionPolicyConfig::EVERY
);
return $repetition_selector;
} else if (count($repetition_options) == 1) {
// if there's only 1 option, just pick it for the user
$repetition_selector = reset($repetition_options);
return $repetition_selector;
} else {
// give the user all the options for this rule type
$tags = array();
foreach ($repetition_options as $name => $option) {
$tags[] = phutil_render_tag(
'option',
array(
'selected' => ($repetition_policy == $name) ? 'selected' : null,
'value' => $name,
),
phutil_escape_html($option)
);
}
$repetition_selector =
'<select name="repetition_policy">' .
implode("\n", $tags) .
'</select>';
return $repetition_selector;
}
}
protected function buildTokenizerTemplates() {
$template = new AphrontTokenizerTemplateView();
$template = $template->render();
return array(
'source' => array(
'email' => '/typeahead/common/mailable/',
'user' => '/typeahead/common/users/',
'repository' => '/typeahead/common/repositories/',
'package' => '/typeahead/common/packages/',
/*
'tag' => '/datasource/tag/',
*/
),
'markup' => $template,
);
}
}
diff --git a/src/applications/herald/controller/test/HeraldTestConsoleController.php b/src/applications/herald/controller/test/HeraldTestConsoleController.php
index a62395c723..a8eb194e79 100644
--- a/src/applications/herald/controller/test/HeraldTestConsoleController.php
+++ b/src/applications/herald/controller/test/HeraldTestConsoleController.php
@@ -1,145 +1,149 @@
<?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 HeraldTestConsoleController extends HeraldController {
+ public function getFilter() {
+ return 'test';
+ }
+
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$request = $this->getRequest();
$object_name = trim($request->getStr('object_name'));
$e_name = true;
$errors = array();
if ($request->isFormPost()) {
if (!$object_name) {
$e_name = 'Required';
$errors[] = 'An object name is required.';
}
if (!$errors) {
$matches = null;
$object = null;
if (preg_match('/^D(\d+)$/', $object_name, $matches)) {
$object = id(new DifferentialRevision())->load($matches[1]);
if (!$object) {
$e_name = 'Invalid';
$errors[] = 'No Differential Revision with that ID exists.';
}
} else if (preg_match('/^r([A-Z]+)(\w+)$/', $object_name, $matches)) {
$repo = id(new PhabricatorRepository())->loadOneWhere(
'callsign = %s',
$matches[1]);
if (!$repo) {
$e_name = 'Invalid';
$errors[] = 'There is no repository with the callsign '.
$matches[1].'.';
}
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
'repositoryID = %d AND commitIdentifier = %s',
$repo->getID(),
$matches[2]);
if (!$commit) {
$e_name = 'Invalid';
$errors[] = 'There is no commit with that identifier.';
}
$object = $commit;
} else {
$e_name = 'Invalid';
$errors[] = 'This object name is not recognized.';
}
if (!$errors) {
if ($object instanceof DifferentialRevision) {
$adapter = new HeraldDifferentialRevisionAdapter(
$object,
$object->loadActiveDiff());
} else if ($object instanceof PhabricatorRepositoryCommit) {
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d',
$object->getID());
$adapter = new HeraldCommitAdapter(
$repo,
$object,
$data);
} else {
throw new Exception("Can not build adapter for object!");
}
$rules = HeraldRule::loadAllByContentTypeWithFullData(
$adapter->getHeraldTypeName());
$engine = new HeraldEngine();
$effects = $engine->applyRules($rules, $adapter);
$dry_run = new HeraldDryRunAdapter();
$engine->applyEffects($effects, $dry_run);
$xscript = $engine->getTranscript();
return id(new AphrontRedirectResponse())
->setURI('/herald/transcript/'.$xscript->getID().'/');
}
}
}
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle('Form Errors');
$error_view->setErrors($errors);
} else {
$error_view = null;
}
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(
'<p class="aphront-form-instructions">Enter an object to test rules '.
'for, like a Diffusion commit (e.g., <tt>rX123</tt>) or a '.
'Differential revision (e.g., <tt>D123</tt>). You will be shown the '.
'results of a dry run on the object.</p>')
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Object Name')
->setName('object_name')
->setError($e_name)
->setValue($object_name))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Test Rules'));
$panel = new AphrontPanelView();
$panel->setHeader('Test Herald Rules');
- $panel->setWidth(AphrontPanelView::WIDTH_FORM);
+ $panel->setWidth(AphrontPanelView::WIDTH_FULL);
$panel->appendChild($form);
return $this->buildStandardPageResponse(
array(
$error_view,
$panel,
),
array(
'title' => 'Test Console',
'tab' => 'test',
));
}
}
diff --git a/src/applications/herald/controller/transcript/HeraldTranscriptController.php b/src/applications/herald/controller/transcript/HeraldTranscriptController.php
index bf9f0fcd5d..4840352817 100644
--- a/src/applications/herald/controller/transcript/HeraldTranscriptController.php
+++ b/src/applications/herald/controller/transcript/HeraldTranscriptController.php
@@ -1,531 +1,535 @@
<?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 HeraldTranscriptController extends HeraldController {
const FILTER_AFFECTED = 'affected';
const FILTER_OWNED = 'owned';
const FILTER_ALL = 'all';
private $id;
private $filter;
private $handles;
+ public function getFilter() {
+ return 'transcript';
+ }
+
public function willProcessRequest(array $data) {
$this->id = $data['id'];
$map = $this->getFilterMap();
$this->filter = idx($data, 'filter');
if (empty($map[$this->filter])) {
$this->filter = self::FILTER_AFFECTED;
}
}
public function processRequest() {
$xscript = id(new HeraldTranscript())->load($this->id);
if (!$xscript) {
throw new Exception('Uknown transcript!');
}
require_celerity_resource('herald-test-css');
$nav = $this->buildSideNav();
$object_xscript = $xscript->getObjectTranscript();
if (!$object_xscript) {
$notice = id(new AphrontErrorView())
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
->setTitle('Old Transcript')
->appendChild(
'<p>Details of this transcript have been garbage collected.</p>');
$nav->appendChild($notice);
} else {
$filter = $this->getFilterPHIDs();
$this->filterTranscript($xscript, $filter);
$phids = array_merge($filter, $this->getTranscriptPHIDs($xscript));
$phids = array_unique($phids);
$phids = array_filter($phids);
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
$this->handles = $handles;
$apply_xscript_panel = $this->buildApplyTranscriptPanel(
$xscript);
$nav->appendChild($apply_xscript_panel);
$action_xscript_panel = $this->buildActionTranscriptPanel(
$xscript);
$nav->appendChild($action_xscript_panel);
$object_xscript_panel = $this->buildObjectTranscriptPanel(
$xscript);
$nav->appendChild($object_xscript_panel);
}
/*
TODO
$notice = null;
if ($xscript->getDryRun()) {
$notice =
<tools:notice title="Dry Run">
This was a dry run to test Herald rules, no actions were executed.
</tools:notice>;
}
*/
return $this->buildStandardPageResponse(
$nav,
array(
'title' => 'Transcript',
));
}
protected function renderConditionTestValue($condition, $handles) {
$value = $condition->getTestValue();
if (!is_scalar($value) && $value !== null) {
foreach ($value as $key => $phid) {
$handle = idx($handles, $phid);
if ($handle) {
$value[$key] = $handle->getName();
} else {
// This shouldn't ever really happen as we are supposed to have
// grabbed handles for everything, but be super liberal in what
// we accept here since we expect all sorts of weird issues as we
// version the system.
$value[$key] = 'Unknown Object #'.$phid;
}
}
sort($value);
$value = implode(', ', $value);
}
return
'<span class="condition-test-value">'.
phutil_escape_html($value).
'</span>';
}
private function buildSideNav() {
$nav = new AphrontSideNavView();
$items = array();
$filters = $this->getFilterMap();
foreach ($filters as $key => $name) {
$nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/herald/transcript/'.$this->id.'/'.$key.'/',
'class' =>
($key == $this->filter)
? 'aphront-side-nav-selected'
: null,
),
phutil_escape_html($name)));
}
return $nav;
}
protected function getFilterMap() {
return array(
self::FILTER_AFFECTED => 'Rules that Affected Me',
self::FILTER_OWNED => 'Rules I Own',
self::FILTER_ALL => 'All Rules',
);
}
protected function getFilterPHIDs() {
return array($this->getRequest()->getUser()->getPHID());
/* TODO
$viewer_id = $this->getRequest()->getUser()->getPHID();
$fbids = array();
if ($this->filter == self::FILTER_AFFECTED) {
$fbids[] = $viewer_id;
require_module_lazy('intern/subscriptions');
$datastore = new SubscriberDatabaseStore();
$lists = $datastore->getUserMailmanLists($viewer_id);
foreach ($lists as $list) {
$fbids[] = $list;
}
}
return $fbids;
*/
}
protected function getTranscriptPHIDs($xscript) {
$phids = array();
$object_xscript = $xscript->getObjectTranscript();
if (!$object_xscript) {
return array();
}
$phids[] = $object_xscript->getPHID();
foreach ($xscript->getApplyTranscripts() as $apply_xscript) {
// TODO: This is total hacks. Add another amazing layer of abstraction.
$target = (array)$apply_xscript->getTarget();
foreach ($target as $phid) {
if ($phid) {
$phids[] = $phid;
}
}
}
foreach ($xscript->getRuleTranscripts() as $rule_xscript) {
$phids[] = $rule_xscript->getRuleOwner();
}
$condition_xscripts = $xscript->getConditionTranscripts();
if ($condition_xscripts) {
$condition_xscripts = call_user_func_array(
'array_merge',
$condition_xscripts);
}
foreach ($condition_xscripts as $condition_xscript) {
$value = $condition_xscript->getTestValue();
// TODO: Also total hacks.
if (is_array($value)) {
foreach ($value as $phid) {
if ($phid) { // TODO: Probably need to make sure this "looks like" a
// PHID or decrease the level of hacks here; this used
// to be an is_numeric() check in Facebook land.
$phids[] = $phid;
}
}
}
}
return $phids;
}
protected function filterTranscript($xscript, $filter_phids) {
$filter_owned = ($this->filter == self::FILTER_OWNED);
$filter_affected = ($this->filter == self::FILTER_AFFECTED);
if (!$filter_owned && !$filter_affected) {
// No filtering to be done.
return;
}
if (!$xscript->getObjectTranscript()) {
return;
}
$user_phid = $this->getRequest()->getUser()->getPHID();
$keep_apply_xscripts = array();
$keep_rule_xscripts = array();
$filter_phids = array_fill_keys($filter_phids, true);
$rule_xscripts = $xscript->getRuleTranscripts();
foreach ($xscript->getApplyTranscripts() as $id => $apply_xscript) {
$rule_id = $apply_xscript->getRuleID();
if ($filter_owned) {
if (empty($rule_xscripts[$rule_id])) {
// No associated rule so you can't own this effect.
continue;
}
if ($rule_xscripts[$rule_id]->getRuleOwner() != $user_phid) {
continue;
}
} else if ($filter_affected) {
$targets = (array)$apply_xscript->getTarget();
if (!array_select_keys($filter_phids, $targets)) {
continue;
}
}
$keep_apply_xscripts[$id] = true;
if ($rule_id) {
$keep_rule_xscripts[$rule_id] = true;
}
}
foreach ($rule_xscripts as $rule_id => $rule_xscript) {
if ($filter_owned && $rule_xscript->getRuleOwner() == $user_phid) {
$keep_rule_xscripts[$rule_id] = true;
}
}
$xscript->setRuleTranscripts(
array_intersect_key(
$xscript->getRuleTranscripts(),
$keep_rule_xscripts));
$xscript->setApplyTranscripts(
array_intersect_key(
$xscript->getApplyTranscripts(),
$keep_apply_xscripts));
$xscript->setConditionTranscripts(
array_intersect_key(
$xscript->getConditionTranscripts(),
$keep_rule_xscripts));
}
private function buildApplyTranscriptPanel($xscript) {
$handles = $this->handles;
$action_names = HeraldActionConfig::getActionMap();
$rows = array();
foreach ($xscript->getApplyTranscripts() as $apply_xscript) {
// TODO: Hacks, this is an approximate guess at the target type.
$target = (array)$apply_xscript->getTarget();
if (!$target) {
if ($apply_xscript->getAction() == HeraldActionConfig::ACTION_NOTHING) {
$target = '';
} else {
$target = '<empty>';
}
} else {
foreach ($target as $k => $phid) {
$target[$k] = $handles[$phid]->getName();
}
$target = implode("\n", $target);
}
$target = phutil_escape_html($target);
if ($apply_xscript->getApplied()) {
$outcome = '<span class="outcome-success">SUCCESS</span>';
} else {
$outcome = '<span class="outcome-failure">FAILURE</span>';
}
$outcome .= ' '.phutil_escape_html($apply_xscript->getAppliedReason());
$rows[] = array(
phutil_escape_html($action_names[$apply_xscript->getAction()]),
$target,
'<strong>Taken because:</strong> '.
phutil_escape_html($apply_xscript->getReason()).
'<br />'.
'<strong>Outcome:</strong> '.$outcome,
);
}
$table = new AphrontTableView($rows);
$table->setNoDataString('No actions were taken.');
$table->setHeaders(
array(
'Action',
'Target',
'Details',
));
$table->setColumnClasses(
array(
'',
'',
'wide',
));
$panel = new AphrontPanelView();
$panel->setHeader('Actions Taken');
$panel->appendChild($table);
return $panel;
}
private function buildActionTranscriptPanel($xscript) {
$action_xscript = mgroup($xscript->getApplyTranscripts(), 'getRuleID');
$field_names = HeraldFieldConfig::getFieldMap();
$condition_names = HeraldConditionConfig::getConditionMap();
$action_names = HeraldActionConfig::getActionMap();
$handles = $this->handles;
$rule_markup = array();
foreach ($xscript->getRuleTranscripts() as $rule_id => $rule) {
$cond_markup = array();
foreach ($xscript->getConditionTranscriptsForRule($rule_id) as $cond) {
if ($cond->getNote()) {
$note =
'<div class="herald-condition-note">'.
phutil_escape_html($cond->getNote()).
'</div>';
} else {
$note = null;
}
if ($cond->getResult()) {
$result =
'<span class="herald-outcome condition-pass">'.
"\xE2\x9C\x93".
'</span>';
} else {
$result =
'<span class="herald-outcome condition-fail">'.
"\xE2\x9C\x98".
'</span>';
}
$cond_markup[] =
'<li>'.
$result.' Condition: '.
phutil_escape_html($field_names[$cond->getFieldName()]).
' '.
phutil_escape_html($condition_names[$cond->getCondition()]).
' '.
$this->renderConditionTestValue($cond, $handles).
$note.
'</li>';
}
if ($rule->getResult()) {
$result = '<span class="herald-outcome rule-pass">PASS</span>';
$class = 'herald-rule-pass';
} else {
$result = '<span class="herald-outcome rule-fail">FAIL</span>';
$class = 'herald-rule-fail';
}
$cond_markup[] =
'<li>'.$result.' '.phutil_escape_html($rule->getReason()).'</li>';
/*
if ($rule->getResult()) {
$actions = idx($action_xscript, $rule_id, array());
if ($actions) {
$cond_markup[] = <li><div class="action-header">Actions</div></li>;
foreach ($actions as $action) {
$target = $action->getTarget();
if ($target) {
foreach ((array)$target as $k => $phid) {
$target[$k] = $handles[$phid]->getName();
}
$target = <strong>: {implode(', ', $target)}</strong>;
}
$cond_markup[] =
<li>
{$action_names[$action->getAction()]}
{$target}
</li>;
}
}
}
*/
$user_phid = $this->getRequest()->getUser()->getPHID();
$name = $rule->getRuleName();
if ($rule->getRuleOwner() == $user_phid) {
// $name = <a href={"/herald/rule/".$rule->getRuleID()."/"}>{$name}</a>;
}
$rule_markup[] =
phutil_render_tag(
'li',
array(
'class' => $class,
),
'<div class="rule-name">'.
'<strong>'.phutil_escape_html($name).'</strong> '.
phutil_escape_html($handles[$rule->getRuleOwner()]->getName()).
'</div>'.
'<ul>'.implode("\n", $cond_markup).'</ul>');
}
$panel = new AphrontPanelView();
$panel->setHeader('Rule Details');
$panel->appendChild(
'<ul class="herald-explain-list">'.
implode("\n", $rule_markup).
'</ul>');
return $panel;
}
private function buildObjectTranscriptPanel($xscript) {
$field_names = HeraldFieldConfig::getFieldMap();
$object_xscript = $xscript->getObjectTranscript();
$data = array();
if ($object_xscript) {
$phid = $object_xscript->getPHID();
$handles = id(new PhabricatorObjectHandleData(array($phid)))
->loadHandles();
$data += array(
'Object Name' => $object_xscript->getName(),
'Object Type' => $object_xscript->getType(),
'Object PHID' => $phid,
'Object Link' => $handles[$phid]->renderLink(),
);
}
$data += $xscript->getMetadataMap();
if ($object_xscript) {
foreach ($object_xscript->getFields() as $field => $value) {
$field = idx($field_names, $field, '['.$field.'?]');
$data['Field: '.$field] = $value;
}
}
$rows = array();
foreach ($data as $name => $value) {
if (!is_scalar($value) && !is_null($value)) {
$value = implode("\n", $value);
}
if (strlen($value) > 256) {
$value = phutil_render_tag(
'textarea',
array(
'class' => 'herald-field-value-transcript',
),
phutil_escape_html($value));
} else if ($name === 'Object Link') {
// The link cannot be escaped
} else {
$value = phutil_escape_html($value);
}
$rows[] = array(
phutil_escape_html($name),
$value,
);
}
$table = new AphrontTableView($rows);
$table->setColumnClasses(
array(
'header',
'wide',
));
$panel = new AphrontPanelView();
$panel->setHeader('Object Transcript');
$panel->appendChild($table);
return $panel;
}
}
diff --git a/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php b/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php
index c465655c4d..560c7ad8dc 100644
--- a/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php
+++ b/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php
@@ -1,151 +1,155 @@
<?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 HeraldTranscriptListController extends HeraldController {
+ public function getFilter() {
+ return 'transcript';
+ }
+
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
// Get one page of data together with the pager.
// Pull these objects manually since the serialized fields are gigantic.
$transcript = new HeraldTranscript();
$conn_r = $transcript->establishConnection('r');
$phid = $request->getStr('phid');
$where_clause = '';
if ($phid) {
$where_clause = qsprintf(
$conn_r,
'WHERE objectPHID = %s',
$phid);
}
$offset = $request->getInt('offset', 0);
$page_size = 100;
$limit_clause = qsprintf(
$conn_r,
'LIMIT %d, %d',
$offset, $page_size + 1);
$data = queryfx_all(
$conn_r,
'SELECT id, objectPHID, time, duration, dryRun FROM %T
%Q
ORDER BY id DESC
%Q',
$transcript->getTableName(),
$where_clause,
$limit_clause);
$pager = new AphrontPagerView();
$pager->getPageSize($page_size);
$pager->setHasMorePages(count($data) == $page_size + 1);
$pager->setOffset($offset);
$pager->setURI($request->getRequestURI(), 'offset');
/*
$conn_r = smc_get_db('cdb.herald', 'r');
$page_size = 100;
$pager = new SimplePager();
$pager->setPageSize($page_size);
$pager->setOffset((((int)$request->getInt('page')) - 1) * $page_size);
$pager->order('id', array('id'));
$fbid = $request->getInt('fbid');
if ($fbid) {
$filter = qsprintf(
$conn_r,
'WHERE objectID = %d',
$fbid);
} else {
$filter = '';
}
$data = $pager->select(
$conn_r,
'id, objectID, time, duration, dryRun FROM transcript %Q',
$filter);
*/
// Render the table.
$handles = array();
if ($data) {
$phids = ipull($data, 'objectPHID', 'objectPHID');
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
}
$rows = array();
foreach ($data as $xscript) {
$rows[] = array(
phabricator_date($xscript['time'],$user),
phabricator_time($xscript['time'],$user),
$handles[$xscript['objectPHID']]->renderLink(),
$xscript['dryRun'] ? 'Yes' : '',
number_format((int)(1000 * $xscript['duration'])).' ms',
phutil_render_tag(
'a',
array(
'href' => '/herald/transcript/'.$xscript['id'].'/',
'class' => 'button small grey',
),
'View Transcript'),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Date',
'Time',
'Object',
'Dry Run',
'Duration',
'View',
));
$table->setColumnClasses(
array(
'',
'right',
'wide wrap',
'',
'',
'action',
));
// Render the whole page.
$panel = new AphrontPanelView();
$panel->setHeader('Herald Transcripts');
$panel->appendChild($table);
$panel->appendChild($pager);
return $this->buildStandardPageResponse(
$panel,
array(
'title' => 'Herald Transcripts',
'tab' => 'transcripts',
));
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Mar 16, 9:21 PM (3 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
963286
Default Alt Text
(59 KB)

Event Timeline