Page MenuHomePhabricator

D10411.id25054.diff
No OneTemporary

D10411.id25054.diff

diff --git a/resources/sql/autopatches/20140904.macroattach.php b/resources/sql/autopatches/20140904.macroattach.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140904.macroattach.php
@@ -0,0 +1,26 @@
+<?php
+
+$table = new PhabricatorFileImageMacro();
+foreach (new LiskMigrationIterator($table) as $macro) {
+ $name = $macro->getName();
+
+ echo "Linking macro '{$name}'...\n";
+
+ $editor = new PhabricatorEdgeEditor();
+
+ $phids[] = $macro->getFilePHID();
+ $phids[] = $macro->getAudioPHID();
+ $phids = array_filter($phids);
+
+ if ($phids) {
+ foreach ($phids as $phid) {
+ $editor->addEdge(
+ $macro->getPHID(),
+ PhabricatorEdgeConfig::TYPE_OBJECT_HAS_FILE,
+ $phid);
+ }
+ $editor->save();
+ }
+}
+
+echo "Done.\n";
diff --git a/src/applications/macro/controller/PhabricatorMacroMemeController.php b/src/applications/macro/controller/PhabricatorMacroMemeController.php
--- a/src/applications/macro/controller/PhabricatorMacroMemeController.php
+++ b/src/applications/macro/controller/PhabricatorMacroMemeController.php
@@ -3,6 +3,10 @@
final class PhabricatorMacroMemeController
extends PhabricatorMacroController {
+ public function shouldAllowPublic() {
+ return true;
+ }
+
public function processRequest() {
$request = $this->getRequest();
$macro_name = $request->getStr('macro');
diff --git a/src/applications/macro/editor/PhabricatorMacroEditor.php b/src/applications/macro/editor/PhabricatorMacroEditor.php
--- a/src/applications/macro/editor/PhabricatorMacroEditor.php
+++ b/src/applications/macro/editor/PhabricatorMacroEditor.php
@@ -82,19 +82,39 @@
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
- return;
- }
-
- protected function extractFilePHIDsFromCustomTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorMacroTransactionType::TYPE_FILE:
- return array($xaction->getNewValue());
+ case PhabricatorMacroTransactionType::TYPE_AUDIO:
+ // 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($this->requireActor(), $object->getPHID());
+ }
+ break;
}
-
- return array();
}
protected function mergeTransactions(

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 5:03 AM (4 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705918
Default Alt Text
D10411.id25054.diff (3 KB)

Event Timeline