[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionMirrorEditController 4 extends DiffusionController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = idx($data, 'id'); 10 parent::willProcessRequest($data); 11 } 12 13 public function processRequest() { 14 $request = $this->getRequest(); 15 $viewer = $request->getUser(); 16 $drequest = $this->diffusionRequest; 17 $repository = $drequest->getRepository(); 18 19 if ($this->id) { 20 $mirror = id(new PhabricatorRepositoryMirrorQuery()) 21 ->setViewer($viewer) 22 ->withIDs(array($this->id)) 23 ->executeOne(); 24 if (!$mirror) { 25 return new Aphront404Response(); 26 } 27 $is_new = false; 28 } else { 29 $mirror = PhabricatorRepositoryMirror::initializeNewMirror($viewer) 30 ->setRepositoryPHID($repository->getPHID()) 31 ->attachRepository($repository); 32 $is_new = true; 33 } 34 35 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/#mirrors'); 36 37 $v_remote = $mirror->getRemoteURI(); 38 $e_remote = true; 39 40 $v_credentials = $mirror->getCredentialPHID(); 41 $e_credentials = null; 42 43 $credentials = id(new PassphraseCredentialQuery()) 44 ->setViewer($viewer) 45 ->withIsDestroyed(false) 46 ->execute(); 47 48 $errors = array(); 49 if ($request->isFormPost()) { 50 $v_remote = $request->getStr('remoteURI'); 51 if (strlen($v_remote)) { 52 try { 53 PhabricatorRepository::assertValidRemoteURI($v_remote); 54 $e_remote = null; 55 } catch (Exception $ex) { 56 $e_remote = pht('Invalid'); 57 $errors[] = $ex->getMessage(); 58 } 59 } else { 60 $e_remote = pht('Required'); 61 $errors[] = pht('You must provide a remote URI.'); 62 } 63 64 $v_credentials = $request->getStr('credential'); 65 if ($v_credentials) { 66 $phids = mpull($credentials, null, 'getPHID'); 67 if (empty($phids[$v_credentials])) { 68 $e_credentials = pht('Invalid'); 69 $errors[] = pht( 70 'You do not have permission to use those credentials.'); 71 } 72 } 73 74 if (!$errors) { 75 $mirror 76 ->setRemoteURI($v_remote) 77 ->setCredentialPHID($v_credentials) 78 ->save(); 79 return id(new AphrontReloadResponse())->setURI($edit_uri); 80 } 81 } 82 83 $form_errors = null; 84 if ($errors) { 85 $form_errors = id(new AphrontErrorView()) 86 ->setErrors($errors); 87 } 88 89 if ($is_new) { 90 $title = pht('Create Mirror'); 91 $submit = pht('Create Mirror'); 92 } else { 93 $title = pht('Edit Mirror'); 94 $submit = pht('Save Changes'); 95 } 96 97 $form = id(new PHUIFormLayoutView()) 98 ->appendChild( 99 id(new AphrontFormTextControl()) 100 ->setLabel(pht('Remote URI')) 101 ->setName('remoteURI') 102 ->setValue($v_remote) 103 ->setError($e_remote)) 104 ->appendChild( 105 id(new PassphraseCredentialControl()) 106 ->setLabel(pht('Credentials')) 107 ->setName('credential') 108 ->setAllowNull(true) 109 ->setValue($v_credentials) 110 ->setError($e_credentials) 111 ->setOptions($credentials)); 112 113 $dialog = id(new AphrontDialogView()) 114 ->setUser($viewer) 115 ->setTitle($title) 116 ->setWidth(AphrontDialogView::WIDTH_FORM) 117 ->appendChild($form_errors) 118 ->appendChild($form) 119 ->addSubmitButton($submit) 120 ->addCancelButton($edit_uri); 121 122 return id(new AphrontDialogResponse()) 123 ->setDialog($dialog); 124 } 125 126 127 }
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 |