From 272a5d668f9e67b1ad61f6b13877974007ccf9ec Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 22 May 2017 12:24:58 -0700 Subject: [PATCH] Fix a handful of Nuance fatals Summary: Ref T12738. Some of the Nuance "form" workflows currently fatal after work on the GitHub stuff. Try to make everything stop fataling, at least. Test Plan: Using "Complaints Form" no longer fatals, and now lodges a complaint instead. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12738 Differential Revision: https://secure.phabricator.com/D18007 --- .../autopatches/20170522.nuance.01.itemkey.sql | 2 ++ src/__phutil_library_map__.php | 2 ++ .../cursor/NuanceGitHubIssuesImportCursor.php | 3 +-- .../NuanceGitHubRepositoryImportCursor.php | 3 +-- .../nuance/item/NuanceFormItemType.php | 16 ++++++++++++++++ .../nuance/phid/NuanceItemPHIDType.php | 2 +- .../NuancePhabricatorFormSourceDefinition.php | 4 +++- .../nuance/source/NuanceSourceDefinition.php | 5 ++++- src/applications/nuance/storage/NuanceItem.php | 8 ++++++-- .../xaction/NuanceItemPropertyTransaction.php | 4 ++-- 10 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 resources/sql/autopatches/20170522.nuance.01.itemkey.sql create mode 100644 src/applications/nuance/item/NuanceFormItemType.php diff --git a/resources/sql/autopatches/20170522.nuance.01.itemkey.sql b/resources/sql/autopatches/20170522.nuance.01.itemkey.sql new file mode 100644 index 0000000000..75118205ce --- /dev/null +++ b/resources/sql/autopatches/20170522.nuance.01.itemkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_nuance.nuance_item + MODIFY itemKey VARCHAR(64) COLLATE {$COLLATE_TEXT}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ff287cbb01..ac24aa3cb6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1606,6 +1606,7 @@ phutil_register_library_map(array( 'NuanceContentSource' => 'applications/nuance/contentsource/NuanceContentSource.php', 'NuanceController' => 'applications/nuance/controller/NuanceController.php', 'NuanceDAO' => 'applications/nuance/storage/NuanceDAO.php', + 'NuanceFormItemType' => 'applications/nuance/item/NuanceFormItemType.php', 'NuanceGitHubEventItemType' => 'applications/nuance/item/NuanceGitHubEventItemType.php', 'NuanceGitHubImportCursor' => 'applications/nuance/cursor/NuanceGitHubImportCursor.php', 'NuanceGitHubIssuesImportCursor' => 'applications/nuance/cursor/NuanceGitHubIssuesImportCursor.php', @@ -6716,6 +6717,7 @@ phutil_register_library_map(array( 'NuanceContentSource' => 'PhabricatorContentSource', 'NuanceController' => 'PhabricatorController', 'NuanceDAO' => 'PhabricatorLiskDAO', + 'NuanceFormItemType' => 'NuanceItemType', 'NuanceGitHubEventItemType' => 'NuanceItemType', 'NuanceGitHubImportCursor' => 'NuanceImportCursor', 'NuanceGitHubIssuesImportCursor' => 'NuanceGitHubImportCursor', diff --git a/src/applications/nuance/cursor/NuanceGitHubIssuesImportCursor.php b/src/applications/nuance/cursor/NuanceGitHubIssuesImportCursor.php index d250b1d02d..151a5876ba 100644 --- a/src/applications/nuance/cursor/NuanceGitHubIssuesImportCursor.php +++ b/src/applications/nuance/cursor/NuanceGitHubIssuesImportCursor.php @@ -17,10 +17,9 @@ final class NuanceGitHubIssuesImportCursor $container_key = null; - return NuanceItem::initializeNewItem() + return NuanceItem::initializeNewItem(NuanceGitHubEventItemType::ITEMTYPE) ->setStatus(NuanceItem::STATUS_IMPORTING) ->setSourcePHID($source->getPHID()) - ->setItemType(NuanceGitHubEventItemType::ITEMTYPE) ->setItemKey($item_key) ->setItemContainerKey($container_key) ->setItemProperty('api.type', 'issue') diff --git a/src/applications/nuance/cursor/NuanceGitHubRepositoryImportCursor.php b/src/applications/nuance/cursor/NuanceGitHubRepositoryImportCursor.php index 72aca276d2..018b3aa8c1 100644 --- a/src/applications/nuance/cursor/NuanceGitHubRepositoryImportCursor.php +++ b/src/applications/nuance/cursor/NuanceGitHubRepositoryImportCursor.php @@ -36,10 +36,9 @@ final class NuanceGitHubRepositoryImportCursor $container_key = "github.issue.{$issue_id}"; } - return NuanceItem::initializeNewItem() + return NuanceItem::initializeNewItem(NuanceGitHubEventItemType::ITEMTYPE) ->setStatus(NuanceItem::STATUS_IMPORTING) ->setSourcePHID($source->getPHID()) - ->setItemType(NuanceGitHubEventItemType::ITEMTYPE) ->setItemKey($item_key) ->setItemContainerKey($container_key) ->setItemProperty('api.type', 'repository') diff --git a/src/applications/nuance/item/NuanceFormItemType.php b/src/applications/nuance/item/NuanceFormItemType.php new file mode 100644 index 0000000000..ee2f923d08 --- /dev/null +++ b/src/applications/nuance/item/NuanceFormItemType.php @@ -0,0 +1,16 @@ + $handle) { $item = $objects[$phid]; - $handle->setName($item->getItemDisplayName()); + $handle->setName($item->getDisplayName()); $handle->setURI($item->getURI()); } } diff --git a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php index e7c7212590..2eaf5781dc 100644 --- a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php +++ b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php @@ -39,6 +39,8 @@ final class NuancePhabricatorFormSourceDefinition $content_source = PhabricatorContentSource::newFromRequest($request); $item = $this->newItemFromProperties( + NuanceFormItemType::ITEMTYPE, + $viewer->getPHID(), $properties, $content_source); @@ -79,7 +81,7 @@ final class NuancePhabricatorFormSourceDefinition NuanceItem $item, PHUIPropertyListView $view) { - $complaint = $item->getNuanceProperty('complaint'); + $complaint = $item->getItemProperty('complaint'); $complaint = new PHUIRemarkupView($viewer, $complaint); $view->addSectionHeader( pht('Complaint'), 'fa-exclamation-circle'); diff --git a/src/applications/nuance/source/NuanceSourceDefinition.php b/src/applications/nuance/source/NuanceSourceDefinition.php index 0330aa5c7e..2c4ebc65e5 100644 --- a/src/applications/nuance/source/NuanceSourceDefinition.php +++ b/src/applications/nuance/source/NuanceSourceDefinition.php @@ -149,6 +149,8 @@ abstract class NuanceSourceDefinition extends Phobject { } protected function newItemFromProperties( + $item_type, + $author_phid, array $properties, PhabricatorContentSource $content_source) { @@ -157,7 +159,7 @@ abstract class NuanceSourceDefinition extends Phobject { $actor = PhabricatorUser::getOmnipotentUser(); $source = $this->getSource(); - $item = NuanceItem::initializeNewItem(); + $item = NuanceItem::initializeNewItem($item_type); $xactions = array(); @@ -181,6 +183,7 @@ abstract class NuanceSourceDefinition extends Phobject { $editor = id(new NuanceItemEditor()) ->setActor($actor) + ->setActingAsPHID($author_phid) ->setContentSource($content_source); $editor->applyTransactions($item, $xactions); diff --git a/src/applications/nuance/storage/NuanceItem.php b/src/applications/nuance/storage/NuanceItem.php index 2eadcdb2d9..9fbfea8dae 100644 --- a/src/applications/nuance/storage/NuanceItem.php +++ b/src/applications/nuance/storage/NuanceItem.php @@ -26,8 +26,12 @@ final class NuanceItem private $source = self::ATTACHABLE; private $implementation = self::ATTACHABLE; - public static function initializeNewItem() { + public static function initializeNewItem($item_type) { + + // TODO: Validate that the type is valid, and construct and attach it. + return id(new NuanceItem()) + ->setItemType($item_type) ->setStatus(self::STATUS_OPEN); } @@ -42,7 +46,7 @@ final class NuanceItem 'requestorPHID' => 'phid?', 'queuePHID' => 'phid?', 'itemType' => 'text64', - 'itemKey' => 'text64', + 'itemKey' => 'text64?', 'itemContainerKey' => 'text64?', 'status' => 'text32', 'mailKey' => 'bytes20', diff --git a/src/applications/nuance/xaction/NuanceItemPropertyTransaction.php b/src/applications/nuance/xaction/NuanceItemPropertyTransaction.php index 76724843de..3367a6a0cf 100644 --- a/src/applications/nuance/xaction/NuanceItemPropertyTransaction.php +++ b/src/applications/nuance/xaction/NuanceItemPropertyTransaction.php @@ -8,14 +8,14 @@ final class NuanceItemPropertyTransaction public function generateOldValue($object) { $property_key = NuanceItemTransaction::PROPERTY_KEY; $key = $this->getMetadataValue($property_key); - return $object->getNuanceProperty($key); + return $object->getItemProperty($key); } public function applyInternalEffects($object, $value) { $property_key = NuanceItemTransaction::PROPERTY_KEY; $key = $this->getMetadataValue($property_key); - $object->setNuanceProperty($key, $value); + $object->setItemProperty($key, $value); } public function getTitle() {