1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Modernize "mailKey" for Almanac Bindings

Summary: Ref T13065. Ref T13641. Migrate "mailKey" and drop the column.

Test Plan: Ran "bin/storage upgrade", got a clean report and saw binding mail keys in the mail properties table.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13641, T13065

Differential Revision: https://secure.phabricator.com/D21630
This commit is contained in:
epriestley 2021-03-16 15:04:07 -07:00
parent fadb2bd52b
commit 7c0e33c34d
3 changed files with 35 additions and 12 deletions

View file

@ -0,0 +1,28 @@
<?php
$binding_table = new AlmanacBinding();
$binding_conn = $binding_table->establishConnection('w');
$properties_table = new PhabricatorMetaMTAMailProperties();
$conn = $properties_table->establishConnection('w');
$iterator = new LiskRawMigrationIterator(
$binding_conn,
$binding_table->getTableName());
foreach ($iterator as $row) {
queryfx(
$conn,
'INSERT IGNORE INTO %R
(objectPHID, mailProperties, dateCreated, dateModified)
VALUES
(%s, %s, %d, %d)',
$properties_table,
$row['phid'],
phutil_json_encode(
array(
'mailKey' => $row['mailKey'],
)),
PhabricatorTime::getNow(),
PhabricatorTime::getNow());
}

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_almanac.almanac_binding
DROP mailKey;

View file

@ -13,7 +13,6 @@ final class AlmanacBinding
protected $servicePHID;
protected $devicePHID;
protected $interfacePHID;
protected $mailKey;
protected $isDisabled;
private $service = self::ATTACHABLE;
@ -33,7 +32,6 @@ final class AlmanacBinding
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'mailKey' => 'bytes20',
'isDisabled' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
@ -51,15 +49,8 @@ final class AlmanacBinding
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(AlmanacBindingPHIDType::TYPECONST);
}
public function save() {
if (!$this->mailKey) {
$this->mailKey = Filesystem::readRandomCharacters(20);
}
return parent::save();
public function getPHIDType() {
return AlmanacBindingPHIDType::TYPECONST;
}
public function getName() {
@ -67,7 +58,9 @@ final class AlmanacBinding
}
public function getURI() {
return '/almanac/binding/'.$this->getID().'/';
return urisprintf(
'/almanac/binding/%s/',
$this->getID());
}
public function getService() {