From 8038af4bd570b25fdd6185500d432a917191c421 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 4 Sep 2014 12:50:51 -0700 Subject: [PATCH] Fix old image macros and memes for logged out users Summary: Fixes T6013. Old image macros/memes never had the file edge written. We also never wrote file edges for audio. Finally, the meme controller didn't allow public access. Write edges for images and audio, perform a migration to populate the historic ones, and make the Editor keep them up to date going forward. Test Plan: - Updated image, saw new image attach and old image detach. - Updated audio, saw new audio attach and old audio detach. - Ran migration. - Viewed memes as a logged-out user. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6013 Differential Revision: https://secure.phabricator.com/D10411 --- resources/celerity/map.php | 22 +++++------ .../sql/autopatches/20140904.macroattach.php | 26 +++++++++++++ .../PhabricatorMacroMemeController.php | 4 ++ .../macro/editor/PhabricatorMacroEditor.php | 38 ++++++++++++++----- 4 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 resources/sql/autopatches/20140904.macroattach.php diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 82942a6d95..51371f2157 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -8,7 +8,7 @@ return array( 'names' => array( 'core.pkg.css' => '974635bb', - 'core.pkg.js' => '4e529147', + 'core.pkg.js' => 'cebacb31', 'darkconsole.pkg.js' => 'df001cab', 'differential.pkg.css' => '36884139', 'differential.pkg.js' => '73337d1d', @@ -438,7 +438,7 @@ return array( 'rsrc/js/application/uiexample/notification-example.js' => '7a9677fc', 'rsrc/js/core/Busy.js' => '6453c869', 'rsrc/js/core/DragAndDropFileUpload.js' => '8c49f386', - 'rsrc/js/core/DraggableList.js' => '98d13594', + 'rsrc/js/core/DraggableList.js' => '2a6a1041', 'rsrc/js/core/FileUpload.js' => 'a4ae61bf', 'rsrc/js/core/Hovercard.js' => '7e8468ae', 'rsrc/js/core/KeyboardShortcut.js' => '1ae869f2', @@ -713,7 +713,7 @@ return array( 'phabricator-crumbs-view-css' => 'a49339de', 'phabricator-dashboard-css' => 'a2bfdcbf', 'phabricator-drag-and-drop-file-upload' => '8c49f386', - 'phabricator-draggable-list' => '98d13594', + 'phabricator-draggable-list' => '2a6a1041', 'phabricator-fatal-config-template-css' => '25d446d6', 'phabricator-feed-css' => '7bfc6f12', 'phabricator-file-upload' => 'a4ae61bf', @@ -987,6 +987,14 @@ return array( 'javelin-install', 'javelin-util', ), + '2a6a1041' => array( + 'javelin-install', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-util', + 'javelin-vector', + 'javelin-magical-init', + ), '2b228192' => array( 'javelin-behavior', 'javelin-dom', @@ -1437,14 +1445,6 @@ return array( 'javelin-dom', 'javelin-reactor-dom', ), - '98d13594' => array( - 'javelin-install', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-util', - 'javelin-vector', - 'javelin-magical-init', - ), '9c2623f4' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/resources/sql/autopatches/20140904.macroattach.php b/resources/sql/autopatches/20140904.macroattach.php new file mode 100644 index 0000000000..02a1d870cd --- /dev/null +++ b/resources/sql/autopatches/20140904.macroattach.php @@ -0,0 +1,26 @@ +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 index 520737ce40..d8b9d5c441 100644 --- 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 index 2bd8292d7e..5c0025ee79 100644 --- a/src/applications/macro/editor/PhabricatorMacroEditor.php +++ b/src/applications/macro/editor/PhabricatorMacroEditor.php @@ -82,19 +82,39 @@ final class PhabricatorMacroEditor 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; + } - return array(); + $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; + } } protected function mergeTransactions(