diff --git a/src/applications/macro/editor/PhabricatorMacroEditEngine.php b/src/applications/macro/editor/PhabricatorMacroEditEngine.php index 3f472ff0ce..2cafea937f 100644 --- a/src/applications/macro/editor/PhabricatorMacroEditEngine.php +++ b/src/applications/macro/editor/PhabricatorMacroEditEngine.php @@ -1,88 +1,88 @@ getViewer(); return PhabricatorFileImageMacro::initializeNewFileImageMacro($viewer); } protected function newObjectQuery() { return new PhabricatorMacroQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create New Macro'); } protected function getObjectEditTitleText($object) { return pht('Edit %s', $object->getName()); } protected function getObjectEditShortText($object) { return $object->getName(); } protected function getObjectCreateShortText() { return pht('Create Macro'); } protected function getObjectName() { return pht('Macro'); } protected function getObjectViewURI($object) { return $object->getViewURI(); } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('edit/'); } protected function getCreateNewObjectPolicy() { return $this->getApplication()->getPolicy( PhabricatorMacroManageCapability::CAPABILITY); } protected function buildCustomEditFields($object) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Macro name.')) ->setConduitDescription(pht('Rename the macro.')) ->setConduitTypeDescription(pht('New macro name.')) ->setTransactionType(PhabricatorMacroNameTransaction::TRANSACTIONTYPE) ->setValue($object->getName()), id(new PhabricatorFileEditField()) ->setKey('filePHID') ->setLabel(pht('Image File')) ->setDescription(pht('Image file to import.')) ->setTransactionType(PhabricatorMacroFileTransaction::TRANSACTIONTYPE) ->setConduitDescription(pht('File PHID to import.')) ->setConduitTypeDescription(pht('File PHID.')), ); } } diff --git a/src/applications/macro/editor/PhabricatorMacroEditor.php b/src/applications/macro/editor/PhabricatorMacroEditor.php index d9067c5367..5d28b78f5f 100644 --- a/src/applications/macro/editor/PhabricatorMacroEditor.php +++ b/src/applications/macro/editor/PhabricatorMacroEditor.php @@ -1,107 +1,69 @@ getTransactionType()) { - case PhabricatorMacroFileTransaction::TRANSACTIONTYPE: - case PhabricatorMacroAudioTransaction::TRANSACTIONTYPE: - // When changing a macro's image or audio, attach the underlying files - // to the macro (and detach the old files). - $old = $xaction->getOldValue(); - $new = $xaction->getNewValue(); - $all = array(); - if ($old) { - $all[] = $old; - } - if ($new) { - $all[] = $new; - } - - $files = id(new PhabricatorFileQuery()) - ->setViewer($this->requireActor()) - ->withPHIDs($all) - ->execute(); - $files = mpull($files, null, 'getPHID'); - - $old_file = idx($files, $old); - if ($old_file) { - $old_file->detachFromObject($object->getPHID()); - } - - $new_file = idx($files, $new); - if ($new_file) { - $new_file->attachToObject($object->getPHID()); - } - break; - } - } - protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new PhabricatorMacroReplyHandler()) ->setMailReceiver($object); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $name = $object->getName(); $name = 'Image Macro "'.$name.'"'; return id(new PhabricatorMetaMTAMail()) ->setSubject($name) ->addHeader('Thread-Topic', $name); } protected function getMailTo(PhabricatorLiskDAO $object) { return array( $this->requireActor()->getPHID(), ); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); $body->addLinkSection( pht('MACRO DETAIL'), PhabricatorEnv::getProductionURI('/macro/view/'.$object->getID().'/')); return $body; } protected function getMailSubjectPrefix() { return PhabricatorEnv::getEnvConfig('metamta.macro.subject-prefix'); } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { return true; } } diff --git a/src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php b/src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php index aacf9f4016..26dc64c1f3 100644 --- a/src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php +++ b/src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php @@ -1,56 +1,84 @@ getAudioPHID(); } public function applyInternalEffects($object, $value) { $object->setAudioPHID($value); } + public function applyExternalEffects($object, $value) { + $old = $this->generateOldValue($object); + $new = $value; + $all = array(); + if ($old) { + $all[] = $old; + } + if ($new) { + $all[] = $new; + } + + $files = id(new PhabricatorFileQuery()) + ->setViewer($this->getActor()) + ->withPHIDs($all) + ->execute(); + $files = mpull($files, null, 'getPHID'); + + $old_file = idx($files, $old); + if ($old_file) { + $old_file->detachFromObject($object->getPHID()); + } + + $new_file = idx($files, $new); + if ($new_file) { + $new_file->attachToObject($object->getPHID()); + } + } + public function getTitle() { $new = $this->getNewValue(); $old = $this->getOldValue(); if (!$old) { return pht( '%s attached audio: %s.', $this->renderAuthor(), $this->renderHandle($new)); } else { return pht( '%s changed the audio for this macro from %s to %s.', $this->renderAuthor(), $this->renderHandle($old), $this->renderHandle($new)); } } public function getTitleForFeed() { $new = $this->getNewValue(); $old = $this->getOldValue(); if (!$old) { return pht( '%s attached audio to %s: %s.', $this->renderAuthor(), $this->renderObject(), $this->renderHandle($new)); } else { return pht( '%s changed the audio for %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderHandle($old), $this->renderHandle($new)); } } public function getIcon() { return 'fa-music'; } } diff --git a/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php b/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php index 77c9f24dd9..35091cd585 100644 --- a/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php +++ b/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php @@ -1,68 +1,96 @@ getFilePHID(); } public function applyInternalEffects($object, $value) { $object->setFilePHID($value); } + public function applyExternalEffects($object, $value) { + $old = $this->generateOldValue($object); + $new = $value; + $all = array(); + if ($old) { + $all[] = $old; + } + if ($new) { + $all[] = $new; + } + + $files = id(new PhabricatorFileQuery()) + ->setViewer($this->getActor()) + ->withPHIDs($all) + ->execute(); + $files = mpull($files, null, 'getPHID'); + + $old_file = idx($files, $old); + if ($old_file) { + $old_file->detachFromObject($object->getPHID()); + } + + $new_file = idx($files, $new); + if ($new_file) { + $new_file->attachToObject($object->getPHID()); + } + } + public function getTitle() { return pht( '%s changed the image for this macro.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( '%s changed the image for macro %s.', $this->renderAuthor(), $this->renderObject()); } public function validateTransactions($object, array $xactions) { $errors = array(); $viewer = $this->getActor(); foreach ($xactions as $xaction) { $file_phid = $xaction->getNewValue(); if ($this->isEmptyTextTransaction($file_phid, $xactions)) { $errors[] = $this->newRequiredError( pht('Image macros must have a file.')); } $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($file_phid)) ->executeOne(); if (!$file) { $errors[] = $this->newInvalidError( pht('"%s" is not a valid file PHID.', $file_phid)); } else { if (!$file->isViewableInBrowser()) { $mime_type = $file->getMimeType(); $errors[] = $this->newInvalidError( pht('File mime type of "%s" is not a valid viewable image.', $mime_type)); } } } return $errors; } public function getIcon() { return 'fa-file-image-o'; } }