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 @@ -1,84 +1,105 @@ file = $file; return $this; } public function getFile() { return $this->assertAttached($this->file); } public function attachAudio(PhabricatorFile $audio = null) { $this->audio = $audio; return $this; } public function getAudio() { return $this->assertAttached($this->audio); } public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID( 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(); } public function getApplicationTransactionObject() { return new PhabricatorMacroTransaction(); } + +/* -( PhabricatorSubscribableInterface )----------------------------------- */ + + + public function isAutomaticallySubscribed($phid) { + return false; + } + + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, ); } public function getPolicy($capability) { return PhabricatorPolicies::getMostOpenPolicy(); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return false; } public function describeAutomaticCapability($capability) { return null; } }