Skip to content

Commit 6abe65b

Browse files
author
epriestley
committed
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
1 parent d32c09d commit 6abe65b

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_file.file_imagemacro
2+
ADD mailKey VARCHAR(20) NOT NULL COLLATE utf8_bin;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
echo "Adding mailkeys to macros.\n";
4+
5+
$table = new PhabricatorFileImageMacro();
6+
$conn_w = $table->establishConnection('w');
7+
$iterator = new LiskMigrationIterator($table);
8+
foreach ($iterator as $macro) {
9+
$id = $macro->getID();
10+
11+
echo "Populating macro {$id}...\n";
12+
13+
if (!$macro->getMailKey()) {
14+
queryfx(
15+
$conn_w,
16+
'UPDATE %T SET mailKey = %s WHERE id = %d',
17+
$table->getTableName(),
18+
Filesystem::readRandomCharacters(20),
19+
$id);
20+
}
21+
}
22+
23+
echo "Done.\n";

src/applications/macro/storage/PhabricatorFileImageMacro.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
1313
protected $isDisabled = 0;
1414
protected $audioPHID;
1515
protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE;
16+
protected $mailKey;
1617

1718
private $file = self::ATTACHABLE;
1819
private $audio = self::ATTACHABLE;
@@ -50,10 +51,18 @@ public function generatePHID() {
5051
PhabricatorMacroPHIDTypeMacro::TYPECONST);
5152
}
5253

53-
public function isAutomaticallySubscribed($phid) {
54-
return false;
54+
55+
public function save() {
56+
if (!$this->getMailKey()) {
57+
$this->setMailKey(Filesystem::readRandomCharacters(20));
58+
}
59+
return parent::save();
5560
}
5661

62+
63+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
64+
65+
5766
public function getApplicationTransactionEditor() {
5867
return new PhabricatorMacroEditor();
5968
}
@@ -62,6 +71,18 @@ public function getApplicationTransactionObject() {
6271
return new PhabricatorMacroTransaction();
6372
}
6473

74+
75+
/* -( PhabricatorSubscribableInterface )----------------------------------- */
76+
77+
78+
public function isAutomaticallySubscribed($phid) {
79+
return false;
80+
}
81+
82+
83+
/* -( PhabricatorPolicyInterface )----------------------------------------- */
84+
85+
6586
public function getCapabilities() {
6687
return array(
6788
PhabricatorPolicyCapability::CAN_VIEW,

0 commit comments

Comments
 (0)