[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class HeraldTestConsoleController extends HeraldController { 4 5 public function processRequest() { 6 7 $request = $this->getRequest(); 8 $user = $request->getUser(); 9 10 $request = $this->getRequest(); 11 12 $object_name = trim($request->getStr('object_name')); 13 14 $e_name = true; 15 $errors = array(); 16 if ($request->isFormPost()) { 17 if (!$object_name) { 18 $e_name = pht('Required'); 19 $errors[] = pht('An object name is required.'); 20 } 21 22 if (!$errors) { 23 $object = id(new PhabricatorObjectQuery()) 24 ->setViewer($user) 25 ->withNames(array($object_name)) 26 ->executeOne(); 27 28 if (!$object) { 29 $e_name = pht('Invalid'); 30 $errors[] = pht('No object exists with that name.'); 31 } 32 33 if (!$errors) { 34 35 // TODO: Let the adapters claim objects instead. 36 37 if ($object instanceof DifferentialRevision) { 38 $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( 39 $object, 40 $object->loadActiveDiff()); 41 } else if ($object instanceof PhabricatorRepositoryCommit) { 42 $adapter = id(new HeraldCommitAdapter()) 43 ->setCommit($object); 44 } else if ($object instanceof ManiphestTask) { 45 $adapter = id(new HeraldManiphestTaskAdapter()) 46 ->setTask($object); 47 } else if ($object instanceof PholioMock) { 48 $adapter = id(new HeraldPholioMockAdapter()) 49 ->setMock($object); 50 } else if ($object instanceof PhrictionDocument) { 51 $adapter = id(new PhrictionDocumentHeraldAdapter()) 52 ->setDocument($object); 53 } else { 54 throw new Exception('Can not build adapter for object!'); 55 } 56 57 $adapter->setIsNewObject(false); 58 59 $rules = id(new HeraldRuleQuery()) 60 ->setViewer($user) 61 ->withContentTypes(array($adapter->getAdapterContentType())) 62 ->withDisabled(false) 63 ->needConditionsAndActions(true) 64 ->needAppliedToPHIDs(array($object->getPHID())) 65 ->needValidateAuthors(true) 66 ->execute(); 67 68 $engine = id(new HeraldEngine()) 69 ->setDryRun(true); 70 71 $effects = $engine->applyRules($rules, $adapter); 72 $engine->applyEffects($effects, $adapter, $rules); 73 74 $xscript = $engine->getTranscript(); 75 76 return id(new AphrontRedirectResponse()) 77 ->setURI('/herald/transcript/'.$xscript->getID().'/'); 78 } 79 } 80 } 81 82 $form = id(new AphrontFormView()) 83 ->setUser($user) 84 ->appendRemarkupInstructions( 85 pht( 86 'Enter an object to test rules for, like a Diffusion commit (e.g., '. 87 '`rX123`) or a Differential revision (e.g., `D123`). You will be '. 88 'shown the results of a dry run on the object.')) 89 ->appendChild( 90 id(new AphrontFormTextControl()) 91 ->setLabel(pht('Object Name')) 92 ->setName('object_name') 93 ->setError($e_name) 94 ->setValue($object_name)) 95 ->appendChild( 96 id(new AphrontFormSubmitControl()) 97 ->setValue(pht('Test Rules'))); 98 99 $box = id(new PHUIObjectBoxView()) 100 ->setHeaderText(pht('Herald Test Console')) 101 ->setFormErrors($errors) 102 ->setForm($form); 103 104 $nav = $this->buildSideNavView(); 105 $nav->selectFilter('test'); 106 $nav->appendChild($box); 107 108 $crumbs = id($this->buildApplicationCrumbs()) 109 ->addTextCrumb(pht('Test Console')); 110 $nav->setCrumbs($crumbs); 111 112 return $this->buildApplicationPage( 113 $nav, 114 array( 115 'title' => pht('Test Console'), 116 )); 117 } 118 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |