From 6abe65bfdce399394fbd0ac86b47154b3d75ff57 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 6 Jan 2014 12:17:23 -0800 Subject: [PATCH] Add mailKey to macros Summary: If you have private replies on and a Macro reply handler set, we try to access `getMailKey()` and fail. See P1039 for a trace. (Thanks to @Korvin for picking this up.) Test Plan: Set configuration, repro'd the exception, applied the patch, then disabled/enabled a macro. Reviewers: btrahan Reviewed By: btrahan CC: Korvin, aran Differential Revision: https://secure.phabricator.com/D7896 --- .../autopatches/20140106.macromailkey.1.sql | 2 ++ .../autopatches/20140106.macromailkey.2.php | 23 +++++++++++++++++ .../storage/PhabricatorFileImageMacro.php | 25 +++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 resources/sql/autopatches/20140106.macromailkey.1.sql create mode 100644 resources/sql/autopatches/20140106.macromailkey.2.php diff --git a/resources/sql/autopatches/20140106.macromailkey.1.sql b/resources/sql/autopatches/20140106.macromailkey.1.sql new file mode 100644 index 0000000000..39bdc9aed4 --- /dev/null +++ b/resources/sql/autopatches/20140106.macromailkey.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_file.file_imagemacro + ADD mailKey VARCHAR(20) NOT NULL COLLATE utf8_bin; diff --git a/resources/sql/autopatches/20140106.macromailkey.2.php b/resources/sql/autopatches/20140106.macromailkey.2.php new file mode 100644 index 0000000000..fdca4e4d59 --- /dev/null +++ b/resources/sql/autopatches/20140106.macromailkey.2.php @@ -0,0 +1,23 @@ +establishConnection('w'); +$iterator = new LiskMigrationIterator($table); +foreach ($iterator as $macro) { + $id = $macro->getID(); + + echo "Populating macro {$id}...\n"; + + if (!$macro->getMailKey()) { + queryfx( + $conn_w, + 'UPDATE %T SET mailKey = %s WHERE id = %d', + $table->getTableName(), + Filesystem::readRandomCharacters(20), + $id); + } +} + +echo "Done.\n"; diff --git a/src/applications/macro/storage/PhabricatorFileImageMacro.php b/src/applications/macro/storage/PhabricatorFileImageMacro.php index 0dd6f02cdc..0bd9e238d8 100644 --- a/src/applications/macro/storage/PhabricatorFileImageMacro.php +++ b/src/applications/macro/storage/PhabricatorFileImageMacro.php @@ -13,6 +13,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO protected $isDisabled = 0; protected $audioPHID; protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE; + protected $mailKey; private $file = self::ATTACHABLE; private $audio = self::ATTACHABLE; @@ -50,10 +51,18 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO PhabricatorMacroPHIDTypeMacro::TYPECONST); } - public function isAutomaticallySubscribed($phid) { - return false; + + public function save() { + if (!$this->getMailKey()) { + $this->setMailKey(Filesystem::readRandomCharacters(20)); + } + return parent::save(); } + +/* -( PhabricatorApplicationTransactionInterface )------------------------- */ + + public function getApplicationTransactionEditor() { return new PhabricatorMacroEditor(); } @@ -62,6 +71,18 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO return new PhabricatorMacroTransaction(); } + +/* -( PhabricatorSubscribableInterface )----------------------------------- */ + + + public function isAutomaticallySubscribed($phid) { + return false; + } + + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW,