From 835cd7f2706fdfd4a392cbc1a55bd878a8ddd361 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 28 May 2022 06:27:03 -0700 Subject: [PATCH] Improve remarkup metadata robustness against debris in the database Summary: Ref T13682. Versioned drafts may have missing or unexpected metadata: - versioned drafts from an older version of Phabricator may be missing metadata; - versioned drafts created by an older UI against a newer version of Phabricator may have `null` metadata. Generally, make these workflows robust to metadata in unexpected formats, so database debris doesn't break the UI. Test Plan: Simulated debris, interacted with UI. Maniphest Tasks: T13682 Differential Revision: https://secure.phabricator.com/D21849 --- .../storage/PhabricatorApplicationTransaction.php | 7 ++++++- .../view/PhabricatorApplicationTransactionCommentView.php | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php index 51ed2adba8..e32fe92983 100644 --- a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php +++ b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php @@ -244,7 +244,12 @@ abstract class PhabricatorApplicationTransaction ->setNewValue($new_value); } - $metadata = $this->getMetadataValue('remarkup.control', array()); + $metadata = $this->getMetadataValue('remarkup.control'); + + if (!is_array($metadata)) { + $metadata = array(); + } + foreach ($changes as $change) { if (!$change->getMetadata()) { $change->setMetadata($metadata); diff --git a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php index caf1ce5183..2e469c5e0a 100644 --- a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php +++ b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php @@ -325,6 +325,10 @@ final class PhabricatorApplicationTransactionCommentView } $remarkup_control->setValue($draft_comment); + + if (!is_array($draft_metadata)) { + $draft_metadata = array(); + } $remarkup_control->setRemarkupMetadata($draft_metadata); if (!$this->getObjectPHID()) {