1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

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
This commit is contained in:
epriestley 2014-01-06 12:17:23 -08:00
parent d32c09de41
commit 6abe65bfdc
3 changed files with 48 additions and 2 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_file.file_imagemacro
ADD mailKey VARCHAR(20) NOT NULL COLLATE utf8_bin;

View file

@ -0,0 +1,23 @@
<?php
echo "Adding mailkeys to macros.\n";
$table = new PhabricatorFileImageMacro();
$conn_w = $table->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";

View file

@ -13,6 +13,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
protected $isDisabled = 0; protected $isDisabled = 0;
protected $audioPHID; protected $audioPHID;
protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE; protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE;
protected $mailKey;
private $file = self::ATTACHABLE; private $file = self::ATTACHABLE;
private $audio = self::ATTACHABLE; private $audio = self::ATTACHABLE;
@ -50,10 +51,18 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
PhabricatorMacroPHIDTypeMacro::TYPECONST); 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() { public function getApplicationTransactionEditor() {
return new PhabricatorMacroEditor(); return new PhabricatorMacroEditor();
} }
@ -62,6 +71,18 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
return new PhabricatorMacroTransaction(); return new PhabricatorMacroTransaction();
} }
/* -( PhabricatorSubscribableInterface )----------------------------------- */
public function isAutomaticallySubscribed($phid) {
return false;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() { public function getCapabilities() {
return array( return array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,