public function getHeraldFieldValueType($condition) { $map = PhabricatorContentSource::getAllContentSources(); $map = mpull($map, 'getSourceName'); asort($map); return id(new HeraldSelectFieldValue())->setKey(self::FIELDCONST)->setDefault(PhabricatorWebContentSource::SOURCECONST)->setOptions($map); }
protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $raw_diff = $request->getValue('diff'); $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne(); if (!$repository) { throw new Exception(pht('No such repository "%s"!', $repository_phid)); } } else { $repository = null; } $parser = new ArcanistDiffParser(); $changes = $parser->parseDiff($raw_diff); $diff = DifferentialDiff::newFromRawChanges($changes); $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); $diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP); $diff->setAuthorPHID($viewer->getPHID()); $diff->setCreationMethod('web'); if ($repository) { $diff->setRepositoryPHID($repository->getPHID()); } id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromConduitRequest($request))->saveDiff($diff); return $this->buildDiffInfoDictionary($diff); }
protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender) { $title = $mail->getSubject(); if (!$title) { $title = pht('Email Paste'); } $file = PhabricatorPasteEditor::initializeFileForPaste($sender, $title, $mail->getCleanTextBody()); $xactions = array(); $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)->setNewValue($file->getPHID()); $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)->setNewValue($title); $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE)->setNewValue(''); // auto-detect $paste = PhabricatorPaste::initializeNewPaste($sender); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID())); $editor = id(new PhabricatorPasteEditor())->setActor($sender)->setContentSource($content_source)->setContinueOnNoEffect(true); $xactions = $editor->applyTransactions($paste, $xactions); $mail->setRelatedPHID($paste->getPHID()); $subject_prefix = PhabricatorEnv::getEnvConfig('metamta.paste.subject-prefix'); $subject = pht('You successfully created a paste.'); $paste_uri = PhabricatorEnv::getProductionURI($paste->getURI()); $body = new PhabricatorMetaMTAMailBody(); $body->addRawSection($subject); $body->addTextSection(pht('PASTE LINK'), $paste_uri); id(new PhabricatorMetaMTAMail())->addTos(array($sender->getPHID()))->setSubject($subject)->setSubjectPrefix($subject_prefix)->setFrom($sender->getPHID())->setRelatedPHID($paste->getPHID())->setBody($body->render())->saveAndSend(); }
public function processRequest() { $request = $this->getRequest(); if (!$request->isFormPost()) { return new Aphront400Response(); } $revision_id = $request->getInt('revision_id'); $revision = id(new DifferentialRevision())->load($revision_id); if (!$revision) { return new Aphront400Response(); } $comment = $request->getStr('comment'); $action = $request->getStr('action'); $reviewers = $request->getArr('reviewers'); $ccs = $request->getArr('ccs'); $editor = new DifferentialCommentEditor($revision, $request->getUser()->getPHID(), $action); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr())); $editor->setMessage($comment)->setContentSource($content_source)->setAttachInlineComments(true)->setAddCC($action != DifferentialAction::ACTION_RESIGN)->setAddedReviewers($reviewers)->setAddedCCs($ccs)->save(); // TODO: Diff change detection? $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $request->getUser()->getPHID(), 'differential-comment-' . $revision->getID()); if ($draft) { $draft->delete(); } return id(new AphrontRedirectResponse())->setURI('/D' . $revision->getID()); }
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { $conpherence = $this->getMailReceiver(); $user = $this->getActor(); if (!$conpherence->getPHID()) { $conpherence->attachParticipants(array())->attachFilePHIDs(array()); } else { $edge_type = PhabricatorObjectHasFileEdgeType::EDGECONST; $file_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($conpherence->getPHID(), $edge_type); $conpherence->attachFilePHIDs($file_phids); $participants = id(new ConpherenceParticipant())->loadAllWhere('conpherencePHID = %s', $conpherence->getPHID()); $participants = mpull($participants, null, 'getParticipantPHID'); $conpherence->attachParticipants($participants); } $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID())); $editor = id(new ConpherenceEditor())->setActor($user)->setContentSource($content_source)->setParentMessageID($mail->getMessageID()); $body = $mail->getCleanTextBody(); $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments()); $xactions = array(); if ($this->getMailAddedParticipantPHIDs()) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $this->getMailAddedParticipantPHIDs())); } $xactions = array_merge($xactions, $editor->generateTransactionsFromText($user, $conpherence, $body)); $editor->applyTransactions($conpherence, $xactions); return $conpherence; }
public function processRequest() { $request = $this->getRequest(); if (!$request->isFormPost()) { return new Aphront400Response(); } $user = $request->getUser(); $question_id = $request->getInt('question_id'); $question = PonderQuestionQuery::loadSingle($user, $question_id); if (!$question) { return new Aphront404Response(); } $answer = $request->getStr('answer'); // Only want answers with some non whitespace content if (!strlen(trim($answer))) { $dialog = new AphrontDialogView(); $dialog->setUser($request->getUser()); $dialog->setTitle('Empty answer'); $dialog->appendChild('<p>Your answer must not be empty.</p>'); $dialog->addCancelButton('/Q' . $question_id); return id(new AphrontDialogResponse())->setDialog($dialog); } $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr())); $res = new PonderAnswer(); $res->setContent($answer)->setAuthorPHID($user->getPHID())->setVoteCount(0)->setQuestionID($question_id)->setContentSource($content_source); id(new PonderAnswerEditor())->setUser($user)->setQuestion($question)->setAnswer($res)->saveAnswer(); return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID()))); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$user) { return new Aphront404Response(); } $profile_uri = '/p/' . $user->getUsername() . '/'; $field_list = PhabricatorCustomField::getObjectFields($user, PhabricatorCustomField::ROLE_EDIT); $field_list->setViewer($viewer)->readFieldsFromStorage($user); $validation_exception = null; if ($request->isFormPost()) { $xactions = $field_list->buildFieldTransactionsFromRequest(new PhabricatorUserTransaction(), $request); $editor = id(new PhabricatorUserProfileEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->setContinueOnNoEffect(true); try { $editor->applyTransactions($user, $xactions); return id(new AphrontRedirectResponse())->setURI($profile_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; } } $title = pht('Edit Profile'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($user->getUsername(), $profile_uri); $crumbs->addTextCrumb($title); $form = id(new AphrontFormView())->setUser($viewer); $field_list->appendFieldsToForm($form); $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($profile_uri)->setValue(pht('Save Profile'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Edit Profile'))->setValidationException($validation_exception)->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title)); }
protected function execute(ConduitAPIRequest $request) { $source_phid = $request->getValue('sourcePHID'); $owner_phid = $request->getValue('ownerPHID'); $requestor_phid = $request->getValue('requestorPHID'); $user = $request->getUser(); $item = NuanceItem::initializeNewItem(); $xactions = array(); if ($source_phid) { $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_SOURCE)->setNewValue($source_phid); } else { throw new ConduitException('ERR-NO-SOURCE-PHID'); } if ($owner_phid) { $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_OWNER)->setNewValue($owner_phid); } if ($requestor_phid) { $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_REQUESTOR)->setNewValue($requestor_phid); } else { throw new ConduitException('ERR-NO-REQUESTOR-PHID'); } $source = PhabricatorContentSource::newFromConduitRequest($request); $editor = id(new NuanceItemEditor())->setActor($user)->setContentSource($source)->applyTransactions($item, $xactions); return $item->toDictionary(); }
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { $actor = $this->getActor(); $document = $this->getMailReceiver(); $body_data = $mail->parseBody(); $body = $body_data['body']; $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments()); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID())); $xactions = array(); $command = $body_data['command']; switch ($command) { case 'unsubscribe': $xaction = id(new LegalpadTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('-' => array($actor->getPHID()))); $xactions[] = $xaction; break; } $xactions[] = id(new LegalpadTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new LegalpadTransactionComment())->setDocumentID($document->getID())->setLineNumber(0)->setLineLength(0)->setContent($body)); $editor = id(new LegalpadDocumentEditor())->setActor($actor)->setContentSource($content_source)->setContinueOnNoEffect(true)->setIsPreview(false); try { $xactions = $editor->applyTransactions($document, $xactions); } catch (PhabricatorApplicationTransactionNoEffectException $ex) { // just do nothing, though unclear why you're sending a blank email return true; } $head_xaction = head($xactions); return $head_xaction->getID(); }
protected function execute(ConduitAPIRequest $request) { $diff = id(new DifferentialDiff())->load($request->getValue('diffid')); if (!$diff) { throw new ConduitException('ERR_BAD_DIFF'); } $revision = id(new DifferentialRevision())->load($request->getValue('id')); if (!$revision) { throw new ConduitException('ERR_BAD_REVISION'); } if ($request->getUser()->getPHID() !== $revision->getAuthorPHID()) { throw new ConduitException('ERR_WRONG_USER'); } if ($revision->getStatus() == ArcanistDifferentialRevisionStatus::CLOSED) { throw new ConduitException('ERR_CLOSED'); } $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_CONDUIT, array()); $editor = new DifferentialRevisionEditor($revision, $revision->getAuthorPHID()); $editor->setContentSource($content_source); $fields = $request->getValue('fields'); $editor->copyFieldsFromConduit($fields); $editor->addDiff($diff, $request->getValue('message')); $editor->save(); return array('revisionid' => $revision->getID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID())); }
public function generateObject() { $author_phid = $this->loadPhabrictorUserPHID(); $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $author_phid); $task = ManiphestTask::initializeNewTask($author)->setSubPriority($this->generateTaskSubPriority())->setTitle($this->generateTitle()); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_UNKNOWN, array()); $template = new ManiphestTransaction(); // Accumulate Transactions $changes = array(); $changes[ManiphestTransaction::TYPE_TITLE] = $this->generateTitle(); $changes[ManiphestTransaction::TYPE_DESCRIPTION] = $this->generateDescription(); $changes[ManiphestTransaction::TYPE_OWNER] = $this->loadOwnerPHID(); $changes[ManiphestTransaction::TYPE_STATUS] = $this->generateTaskStatus(); $changes[ManiphestTransaction::TYPE_PRIORITY] = $this->generateTaskPriority(); $changes[PhabricatorTransactions::TYPE_SUBSCRIBERS] = array('=' => $this->getCCPHIDs()); $transactions = array(); foreach ($changes as $type => $value) { $transaction = clone $template; $transaction->setTransactionType($type); $transaction->setNewValue($value); $transactions[] = $transaction; } $transactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)->setNewValue(array('=' => array_fuse($this->getProjectPHIDs()))); // Apply Transactions $editor = id(new ManiphestTransactionEditor())->setActor($author)->setContentSource($content_source)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($task, $transactions); return $task; }
protected function updateServiceLock(AlmanacService $service, $lock) { $almanac_phid = id(new PhabricatorAlmanacApplication())->getPHID(); $xaction = id(new AlmanacServiceTransaction())->setTransactionType(AlmanacServiceTransaction::TYPE_LOCK)->setNewValue((int) $lock); $editor = id(new AlmanacServiceEditor())->setActor($this->getViewer())->setActingAsPHID($almanac_phid)->setContentSource(PhabricatorContentSource::newConsoleSource())->setContinueOnMissingFields(true); $editor->applyTransactions($service, array($xaction)); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $xaction = id(new PhabricatorObjectQuery())->withPHIDs(array($this->phid))->setViewer($viewer)->executeOne(); if (!$xaction) { return new Aphront404Response(); } if (!$xaction->getComment()) { return new Aphront404Response(); } if ($xaction->getComment()->getIsRemoved()) { // You can't remove an already-removed comment. return new Aphront400Response(); } $obj_phid = $xaction->getObjectPHID(); $obj_handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($obj_phid))->executeOne(); if ($request->isDialogFormPost()) { $comment = $xaction->getApplicationTransactionCommentObject()->setContent('')->setIsRemoved(true); $editor = id(new PhabricatorApplicationTransactionCommentEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->applyEdit($xaction, $comment); if ($request->isAjax()) { return id(new AphrontAjaxResponse())->setContent(array()); } else { return id(new AphrontReloadResponse())->setURI($obj_handle->getURI()); } } $form = id(new AphrontFormView())->setUser($viewer); $dialog = $this->newDialog()->setTitle(pht('Remove Comment')); $dialog->addHiddenInput('anchor', $request->getStr('anchor'))->appendParagraph(pht("Removing a comment prevents anyone (including you) from reading " . "it. Removing a comment also hides the comment's edit history " . "and prevents it from being edited."))->appendParagraph(pht('Really remove this comment?')); $dialog->addSubmitButton(pht('Remove Comment'))->addCancelButton($obj_handle->getURI()); return $dialog; }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); if (!$request->isFormPost()) { return new Aphront400Response(); } $question_id = $request->getInt('question_id'); $question = id(new PonderQuestionQuery())->setViewer($viewer)->withIDs(array($question_id))->needAnswers(true)->executeOne(); if (!$question) { return new Aphront404Response(); } $answer = $request->getStr('answer'); if (!strlen(trim($answer))) { $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Empty Answer'))->appendChild(phutil_tag('p', array(), pht('Your answer must not be empty.')))->addCancelButton('/Q' . $question_id); return id(new AphrontDialogResponse())->setDialog($dialog); } $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr())); $res = id(new PonderAnswer())->setAuthorPHID($viewer->getPHID())->setQuestionID($question->getID())->setContent($answer)->setVoteCount(0)->setContentSource($content_source); $xactions = array(); $xactions[] = id(new PonderQuestionTransaction())->setTransactionType(PonderQuestionTransaction::TYPE_ANSWERS)->setNewValue(array('+' => array(array('answer' => $res)))); $editor = id(new PonderQuestionEditor())->setActor($viewer)->setContentSourceFromRequest($request); $editor->applyTransactions($question, $xactions); return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID()))); }
protected function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit) { // Reload the commit to pull commit data and audit requests. $commit = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($commit->getID()))->needCommitData(true)->needAuditRequests(true)->executeOne(); $data = $commit->getCommitData(); if (!$data) { throw new PhabricatorWorkerPermanentFailureException(pht('Unable to load commit data. The data for this task is invalid ' . 'or no longer exists.')); } $commit->attachRepository($repository); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_DAEMON, array()); $committer_phid = $data->getCommitDetail('committerPHID'); $author_phid = $data->getCommitDetail('authorPHID'); $acting_as_phid = nonempty($committer_phid, $author_phid, id(new PhabricatorDiffusionApplication())->getPHID()); $editor = id(new PhabricatorAuditEditor())->setActor(PhabricatorUser::getOmnipotentUser())->setActingAsPHID($acting_as_phid)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->setContentSource($content_source); $xactions = array(); $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorAuditTransaction::TYPE_COMMIT)->setDateCreated($commit->getEpoch())->setNewValue(array('description' => $data->getCommitMessage(), 'summary' => $data->getSummary(), 'authorName' => $data->getAuthorName(), 'authorPHID' => $commit->getAuthorPHID(), 'committerName' => $data->getCommitDetail('committer'), 'committerPHID' => $data->getCommitDetail('committerPHID'))); $reverts_refs = id(new DifferentialCustomFieldRevertsParser())->parseCorpus($data->getCommitMessage()); $reverts = array_mergev(ipull($reverts_refs, 'monograms')); if ($reverts) { $reverted_commits = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepository($repository)->withIdentifiers($reverts)->execute(); $reverted_commit_phids = mpull($reverted_commits, 'getPHID', 'getPHID'); // NOTE: Skip any write attempts if a user cleverly implies a commit // reverts itself. unset($reverted_commit_phids[$commit->getPHID()]); $reverts_edge = DiffusionCommitRevertsCommitEdgeType::EDGECONST; $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $reverts_edge)->setNewValue(array('+' => array_fuse($reverted_commit_phids))); } try { $raw_patch = $this->loadRawPatchText($repository, $commit); } catch (Exception $ex) { $raw_patch = pht('Unable to generate patch: %s', $ex->getMessage()); } $editor->setRawPatch($raw_patch); return $editor->applyTransactions($commit, $xactions); }
public function execute(PhutilArgumentParser $args) { $viewer = $this->getViewer(); $argv = $args->getArg('argv'); if (count($argv) !== 2) { throw new PhutilArgumentUsageException(pht('Specify a commit and a revision to attach it to.')); } $commit_name = head($argv); $revision_name = last($argv); $commit = id(new DiffusionCommitQuery())->setViewer($viewer)->withIdentifiers(array($commit_name))->executeOne(); if (!$commit) { throw new PhutilArgumentUsageException(pht('Commit "%s" does not exist.', $commit_name)); } $revision = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames(array($revision_name))->executeOne(); if (!$revision) { throw new PhutilArgumentUsageException(pht('Revision "%s" does not exist.', $revision_name)); } if (!$revision instanceof DifferentialRevision) { throw new PhutilArgumentUsageException(pht('Object "%s" must be a Differential revision.', $revision_name)); } // Reload the revision to get the active diff. $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($revision->getID()))->needActiveDiffs(true)->executeOne(); $differential_phid = id(new PhabricatorDifferentialApplication())->getPHID(); $extraction_engine = id(new DifferentialDiffExtractionEngine())->setViewer($viewer)->setAuthorPHID($differential_phid); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_CONSOLE, array()); $extraction_engine->updateRevisionWithCommit($revision, $commit, array(), $content_source); echo tsprintf("%s\n", pht('Attached "%s" to "%s".', $commit->getMonogram(), $revision->getMonogram())); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $initiative = id(new FundInitiativeQuery())->setViewer($viewer)->withIDs(array($id))->executeOne(); if (!$initiative) { return new Aphront404Response(); } $merchant = id(new PhortuneMerchantQuery())->setViewer($viewer)->withPHIDs(array($initiative->getMerchantPHID()))->executeOne(); if (!$merchant) { return new Aphront404Response(); } $initiative_uri = '/' . $initiative->getMonogram(); if ($initiative->isClosed()) { return $this->newDialog()->setTitle(pht('Initiative Closed'))->appendParagraph(pht('You can not back a closed initiative.'))->addCancelButton($initiative_uri); } $accounts = PhortuneAccountQuery::loadAccountsForUser($viewer, PhabricatorContentSource::newFromRequest($request)); $v_amount = null; $e_amount = true; $v_account = head($accounts)->getPHID(); $errors = array(); if ($request->isFormPost()) { $v_amount = $request->getStr('amount'); $v_account = $request->getStr('accountPHID'); if (empty($accounts[$v_account])) { $errors[] = pht('You must specify an account.'); } else { $account = $accounts[$v_account]; } if (!strlen($v_amount)) { $errors[] = pht('You must specify how much money you want to contribute to the ' . 'initiative.'); $e_amount = pht('Required'); } else { try { $currency = PhortuneCurrency::newFromUserInput($viewer, $v_amount); $currency->assertInRange('1.00 USD', null); } catch (Exception $ex) { $errors[] = $ex->getMessage(); $e_amount = pht('Invalid'); } } if (!$errors) { $backer = FundBacker::initializeNewBacker($viewer)->setInitiativePHID($initiative->getPHID())->attachInitiative($initiative)->setAmountAsCurrency($currency)->save(); $product = id(new PhortuneProductQuery())->setViewer($viewer)->withClassAndRef('FundBackerProduct', $initiative->getPHID())->executeOne(); $cart_implementation = id(new FundBackerCart())->setInitiative($initiative); $cart = $account->newCart($viewer, $cart_implementation, $merchant); $purchase = $cart->newPurchase($viewer, $product); $purchase->setBasePriceAsCurrency($currency)->setMetadataValue('backerPHID', $backer->getPHID())->save(); $xactions = array(); $xactions[] = id(new FundBackerTransaction())->setTransactionType(FundBackerTransaction::TYPE_STATUS)->setNewValue(FundBacker::STATUS_IN_CART); $editor = id(new FundBackerEditor())->setActor($viewer)->setContentSourceFromRequest($request); $editor->applyTransactions($backer, $xactions); $cart->activateCart(); return id(new AphrontRedirectResponse())->setURI($cart->getCheckoutURI()); } } $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setName('accountPHID')->setLabel(pht('Account'))->setValue($v_account)->setOptions(mpull($accounts, 'getName', 'getPHID')))->appendChild(id(new AphrontFormTextControl())->setName('amount')->setLabel(pht('Amount'))->setValue($v_amount)->setError($e_amount)); return $this->newDialog()->setTitle(pht('Back %s %s', $initiative->getMonogram(), $initiative->getName()))->setErrors($errors)->appendChild($form->buildLayoutView())->addCancelButton($initiative_uri)->addSubmitButton(pht('Continue')); }
protected function addMessageWithFile(PhabricatorUser $actor, ConpherenceThread $conpherence) { $file = $this->generateTestFile($actor); $message = Filesystem::readRandomCharacters(64) . sprintf(' {%s} ', $file->getMonogram()); $editor = id(new ConpherenceEditor())->setActor($actor)->setContentSource(PhabricatorContentSource::newConsoleSource()); $xactions = $editor->generateTransactionsFromText($actor, $conpherence, $message); return $editor->applyTransactions($conpherence, $xactions); }
/** * Build and configure an Editor to publish these transactions. */ private function buildEditor(PhabricatorApplicationTransactionInterface $object) { $data = $this->getTaskData(); $daemon_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_DAEMON, array()); $viewer = PhabricatorUser::getOmnipotentUser(); $editor = $object->getApplicationTransactionEditor()->setActor($viewer)->setContentSource($daemon_source)->setActingAsPHID(idx($data, 'actorPHID'))->loadWorkerState(idx($data, 'state', array())); return $editor; }
private function newEditor(PhabricatorMetaMTAReceivedMail $mail) { $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID())); $editor = $this->getMailReceiver()->getApplicationTransactionEditor()->setActor($this->getActor())->setContentSource($content_source)->setContinueOnMissingFields(true)->setParentMessageID($mail->getMessageID())->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs()); if ($this->getApplicationEmail()) { $editor->setApplicationEmail($this->getApplicationEmail()); } return $editor; }
protected function execute(ConduitAPIRequest $request) { $action = $request->getValue('action'); $new_commit_id = $request->getValue('commitIdentifier'); $releeph_request = id(new ReleephRequest())->loadOneWhere('phid = %s', $request->getValue('requestPHID')); $xactions = array(); $xactions[] = id(new ReleephRequestTransaction())->setTransactionType(ReleephRequestTransaction::TYPE_COMMIT)->setMetadataValue('action', $action)->setNewValue($new_commit_id); $editor = id(new ReleephRequestTransactionalEditor())->setActor($request->getUser())->setContinueOnNoEffect(true)->setContentSource(PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_CONDUIT, array())); $editor->applyTransactions($releeph_request, $xactions); }
protected function execute(ConduitAPIRequest $request) { $content_source = PhabricatorContentSource::newFromConduitRequest($request); $editor = id(new PhabricatorTokenGivenEditor())->setActor($request->getUser())->setContentSource($content_source); if ($request->getValue('tokenPHID')) { $editor->addToken($request->getValue('objectPHID'), $request->getValue('tokenPHID')); } else { $editor->deleteToken($request->getValue('objectPHID')); } }
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { $commit = $this->getMailReceiver(); $actor = $this->getActor(); $message = $mail->getCleanTextBody(); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID())); // TODO: Support !raise, !accept, etc. $xactions = array(); $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new PhabricatorAuditTransactionComment())->setCommitPHID($commit->getPHID())->setContent($message)); $editor = id(new PhabricatorAuditEditor())->setActor($actor)->setContentSource($content_source)->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())->setContinueOnMissingFields(true)->applyTransactions($commit, $xactions); }
public function renderModuleStatus(AphrontRequest $request) { $viewer = $request->getViewer(); $sources = PhabricatorContentSource::getAllContentSources(); ksort($sources); $rows = array(); foreach ($sources as $source) { $rows[] = array($source->getSourceTypeConstant(), get_class($source), $source->getSourceName(), $source->getSourceDescription()); } return id(new AphrontTableView($rows))->setHeaders(array(pht('Key'), pht('Class'), pht('Source'), pht('Description')))->setColumnClasses(array(null, null, 'pri', 'wide')); }
protected function doWork() { $subscription = $this->loadSubscription(); $range = $this->getBillingPeriodRange($subscription); list($last_epoch, $next_epoch) = $range; $should_invoice = $subscription->shouldInvoiceForBillingPeriod($last_epoch, $next_epoch); if (!$should_invoice) { return; } $currency = $subscription->getCostForBillingPeriodAsCurrency($last_epoch, $next_epoch); if (!$currency->isPositive()) { return; } $account = $subscription->getAccount(); $merchant = $subscription->getMerchant(); $viewer = PhabricatorUser::getOmnipotentUser(); $product = id(new PhortuneProductQuery())->setViewer($viewer)->withClassAndRef('PhortuneSubscriptionProduct', $subscription->getPHID())->executeOne(); $cart_implementation = id(new PhortuneSubscriptionCart())->setSubscription($subscription); // TODO: This isn't really ideal. It would be better to use an application // actor than the original author of the subscription. In particular, if // someone initiates a subscription, adds some other account managers, and // later leaves the company, they'll continue "acting" here indefinitely. // However, for now, some of the stuff later in the pipeline requires a // valid actor with a real PHID. The subscription should eventually be // able to create these invoices "as" the application it is acting on // behalf of. $actor = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withPHIDs(array($subscription->getAuthorPHID()))->executeOne(); if (!$actor) { throw new Exception(pht('Failed to load actor to bill subscription!')); } $cart = $account->newCart($actor, $cart_implementation, $merchant); $purchase = $cart->newPurchase($actor, $product); $purchase->setBasePriceAsCurrency($currency)->setMetadataValue('subscriptionPHID', $subscription->getPHID())->setMetadataValue('epoch.start', $last_epoch)->setMetadataValue('epoch.end', $next_epoch)->save(); $cart->setSubscriptionPHID($subscription->getPHID())->setIsInvoice(1)->save(); $cart->activateCart(); try { $issues = $this->chargeSubscription($actor, $subscription, $cart); } catch (Exception $ex) { $issues = array(pht('There was a technical error while trying to automatically bill ' . 'this subscription: %s', $ex)); } if (!$issues) { // We're all done; charging the cart sends a billing email as a side // effect. return; } // We're shoving this through the CartEditor because it has all the logic // for sending mail about carts. This doesn't really affect the state of // the cart, but reduces the amount of code duplication. $xactions = array(); $xactions[] = id(new PhortuneCartTransaction())->setTransactionType(PhortuneCartTransaction::TYPE_INVOICED)->setNewValue(true); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_PHORTUNE, array()); $acting_phid = id(new PhabricatorPhortuneApplication())->getPHID(); $editor = id(new PhortuneCartEditor())->setActor($viewer)->setActingAsPHID($acting_phid)->setContentSource($content_source)->setContinueOnMissingFields(true)->setInvoiceIssues($issues)->applyTransactions($cart, $xactions); }
public function render() { require_celerity_resource('phabricator-content-source-view-css'); $map = PhabricatorContentSource::getSourceNameMap(); $source = $this->contentSource->getSource(); $type = idx($map, $source, null); if (!$type) { return null; } return phutil_tag('span', array('class' => 'phabricator-content-source-view'), pht('Via %s', $type)); }
public function manageApplication($issue) { $key = 'config.ignore-issues'; $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); $list = $config_entry->getValue(); if (isset($list[$issue])) { unset($list[$issue]); } else { $list[$issue] = true; } PhabricatorConfigEditor::storeNewValue($this->getRequest()->getUser(), $config_entry, $list, PhabricatorContentSource::newFromRequest($this->getRequest())); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $title = pht('New Message'); $participants = array(); $participant_prefill = null; $message = ''; $e_participants = null; $e_message = null; // this comes from ajax requests from all over. should be a single phid. if ($request->isFormPost()) { $participants = $request->getArr('participants'); $message = $request->getStr('message'); list($error_codes, $conpherence) = ConpherenceEditor::createConpherence($user, $participants, $conpherence_title = null, $message, PhabricatorContentSource::newFromRequest($request)); if ($error_codes) { foreach ($error_codes as $error_code) { switch ($error_code) { case ConpherenceEditor::ERROR_EMPTY_MESSAGE: $e_message = true; break; case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS: $e_participants = true; break; } } } else { $uri = $this->getApplicationURI($conpherence->getID()); return id(new AphrontRedirectResponse())->setURI($uri); } } else { $participant_prefill = $request->getStr('participant'); if ($participant_prefill) { $participants[] = $participant_prefill; } } $participant_handles = array(); if ($participants) { $participant_handles = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs($participants)->execute(); } $submit_uri = $this->getApplicationURI('new/'); $cancel_uri = $this->getApplicationURI(); // TODO - we can get a better cancel_uri once we get better at crazy // ajax jonx T2086 if ($participant_prefill) { $handle = $participant_handles[$participant_prefill]; $cancel_uri = $handle->getURI(); } $dialog = id(new AphrontDialogView())->setWidth(AphrontDialogView::WIDTH_FORM)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Send Message')); $form = id(new PHUIFormLayoutView())->setUser($user)->setFullWidth(true)->appendChild(id(new AphrontFormTokenizerControl())->setName('participants')->setValue($participant_handles)->setUser($user)->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('To'))->setError($e_participants))->appendChild(id(new PhabricatorRemarkupControl())->setName('message')->setValue($message)->setLabel(pht('Message'))->setError($e_message)); $dialog->appendChild($form); return id(new AphrontDialogResponse())->setDialog($dialog); }
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { $rq = $this->getMailReceiver(); $user = $this->getActor(); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID())); $editor = id(new ReleephRequestTransactionalEditor())->setActor($user)->setContentSource($content_source)->setParentMessageID($mail->getMessageID()); $body = $mail->getCleanTextBody(); $xactions = array(); $xactions[] = id(new ReleephRequestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment($body); $editor->applyTransactions($rq, $xactions); return $rq; }
public function manageApplication() { $key = 'phabricator.uninstalled-applications'; $config_entry = PhabricatorConfigEntry::loadConfigEntry($key); $list = $config_entry->getValue(); $uninstalled = PhabricatorEnv::getEnvConfig($key); if (isset($uninstalled[$this->application])) { unset($list[$this->application]); } else { $list[$this->application] = true; } PhabricatorConfigEditor::storeNewValue($this->getViewer(), $config_entry, $list, PhabricatorContentSource::newFromRequest($this->getRequest())); }