1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Modernize "mailKey" on Almanac Namespaces

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

Test Plan: Ran "bin/storage upgrade", got a clean report, saw mail keys migrated to mail properties table.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13641, T13065

Differential Revision: https://secure.phabricator.com/D21631
This commit is contained in:
epriestley 2021-03-16 15:06:22 -07:00
parent 7c0e33c34d
commit 8226b3c880
3 changed files with 35 additions and 10 deletions

View file

@ -0,0 +1,28 @@
<?php
$namespace_table = new AlmanacNamespace();
$namespace_conn = $namespace_table->establishConnection('w');
$properties_table = new PhabricatorMetaMTAMailProperties();
$conn = $properties_table->establishConnection('w');
$iterator = new LiskRawMigrationIterator(
$namespace_conn,
$namespace_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_namespace
DROP mailKey;

View file

@ -12,7 +12,6 @@ final class AlmanacNamespace
protected $name;
protected $nameIndex;
protected $mailKey;
protected $viewPolicy;
protected $editPolicy;
@ -28,7 +27,6 @@ final class AlmanacNamespace
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text128',
'nameIndex' => 'bytes12',
'mailKey' => 'bytes20',
),
self::CONFIG_KEY_SCHEMA => array(
'key_nameindex' => array(
@ -42,9 +40,8 @@ final class AlmanacNamespace
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
AlmanacNamespacePHIDType::TYPECONST);
public function getPHIDType() {
return AlmanacNamespacePHIDType::TYPECONST;
}
public function save() {
@ -52,15 +49,13 @@ final class AlmanacNamespace
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName());
if (!$this->mailKey) {
$this->mailKey = Filesystem::readRandomCharacters(20);
}
return parent::save();
}
public function getURI() {
return '/almanac/namespace/view/'.$this->getName().'/';
return urisprintf(
'/almanac/namespace/view/%s/',
$this->getName());
}
public function getNameLength() {