From 1520065ec00b81823587a08acabc73f0acb2a05d Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 10 Feb 2014 14:31:57 -0800 Subject: [PATCH] Migrate project blurb/description to standard custom field storage Summary: Ref T4379. Major goal here is to remove `ProjectProfile` so all edits use ApplicationTransactions. This also makes things more flexible, allowing users to disable this field if they don't like it. Test Plan: Ran migration, verified data survived, edited/created projects, reordered fields. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4379 Differential Revision: https://secure.phabricator.com/D8182 --- .../20140210.projcfield.1.blurb.php | 26 +++++++++++++++++++ src/__phutil_library_map__.php | 10 ++++++- .../PhabricatorProjectConfigOptions.php | 6 ++--- .../PhabricatorProjectCreateController.php | 11 ++------ .../PhabricatorProjectProfileController.php | 7 ----- ...habricatorProjectProfileEditController.php | 22 +--------------- ...habricatorProjectConfiguredCustomField.php | 14 +--------- .../PhabricatorProjectDescriptionField.php | 18 +++++++++++++ .../PhabricatorProjectStandardCustomField.php | 23 ++++++++++++++++ 9 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 resources/sql/autopatches/20140210.projcfield.1.blurb.php create mode 100644 src/applications/project/customfield/PhabricatorProjectDescriptionField.php create mode 100644 src/applications/project/customfield/PhabricatorProjectStandardCustomField.php diff --git a/resources/sql/autopatches/20140210.projcfield.1.blurb.php b/resources/sql/autopatches/20140210.projcfield.1.blurb.php new file mode 100644 index 0000000000..3cb39c5dc1 --- /dev/null +++ b/resources/sql/autopatches/20140210.projcfield.1.blurb.php @@ -0,0 +1,26 @@ +establishConnection('w'); +$table_name = id(new PhabricatorProjectCustomFieldStorage())->getTableName(); + +$rows = new LiskRawMigrationIterator($conn_w, 'project_profile'); + +echo "Migrating project descriptions to custom storage...\n"; +foreach ($rows as $row) { + $phid = $row['projectPHID']; + echo "Migrating {$phid}...\n"; + + $desc = $row['blurb']; + if (strlen($desc)) { + queryfx( + $conn_w, + 'INSERT IGNORE INTO %T (objectPHID, fieldIndex, fieldValue) + VALUES (%s, %s, %s)', + $table_name, + $phid, + PhabricatorHash::digestForIndex('std:project:internal:description'), + $desc); + } +} + +echo "Done.\n"; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9a70610392..f28ae65ce7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1840,6 +1840,7 @@ phutil_register_library_map(array( 'PhabricatorProjectCustomFieldStorage' => 'applications/project/storage/PhabricatorProjectCustomFieldStorage.php', 'PhabricatorProjectCustomFieldStringIndex' => 'applications/project/storage/PhabricatorProjectCustomFieldStringIndex.php', 'PhabricatorProjectDAO' => 'applications/project/storage/PhabricatorProjectDAO.php', + 'PhabricatorProjectDescriptionField' => 'applications/project/customfield/PhabricatorProjectDescriptionField.php', 'PhabricatorProjectEditorTestCase' => 'applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php', 'PhabricatorProjectHistoryController' => 'applications/project/controller/PhabricatorProjectHistoryController.php', 'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php', @@ -1855,6 +1856,7 @@ phutil_register_library_map(array( 'PhabricatorProjectQuery' => 'applications/project/query/PhabricatorProjectQuery.php', 'PhabricatorProjectSearchEngine' => 'applications/project/query/PhabricatorProjectSearchEngine.php', 'PhabricatorProjectSearchIndexer' => 'applications/project/search/PhabricatorProjectSearchIndexer.php', + 'PhabricatorProjectStandardCustomField' => 'applications/project/customfield/PhabricatorProjectStandardCustomField.php', 'PhabricatorProjectStatus' => 'applications/project/constants/PhabricatorProjectStatus.php', 'PhabricatorProjectTestDataGenerator' => 'applications/project/lipsum/PhabricatorProjectTestDataGenerator.php', 'PhabricatorProjectTransaction' => 'applications/project/storage/PhabricatorProjectTransaction.php', @@ -4574,7 +4576,7 @@ phutil_register_library_map(array( 'PhabricatorProjectConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorProjectConfiguredCustomField' => array( - 0 => 'PhabricatorProjectCustomField', + 0 => 'PhabricatorProjectStandardCustomField', 1 => 'PhabricatorStandardCustomFieldInterface', ), 'PhabricatorProjectController' => 'PhabricatorController', @@ -4584,6 +4586,7 @@ phutil_register_library_map(array( 'PhabricatorProjectCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 'PhabricatorProjectCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 'PhabricatorProjectDAO' => 'PhabricatorLiskDAO', + 'PhabricatorProjectDescriptionField' => 'PhabricatorProjectStandardCustomField', 'PhabricatorProjectEditorTestCase' => 'PhabricatorTestCase', 'PhabricatorProjectHistoryController' => 'PhabricatorProjectController', 'PhabricatorProjectListController' => @@ -4603,6 +4606,11 @@ phutil_register_library_map(array( 'PhabricatorProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorProjectSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorProjectSearchIndexer' => 'PhabricatorSearchDocumentIndexer', + 'PhabricatorProjectStandardCustomField' => + array( + 0 => 'PhabricatorProjectCustomField', + 1 => 'PhabricatorStandardCustomFieldInterface', + ), 'PhabricatorProjectTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorProjectTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorProjectTransactionEditor' => 'PhabricatorApplicationTransactionEditor', diff --git a/src/applications/project/config/PhabricatorProjectConfigOptions.php b/src/applications/project/config/PhabricatorProjectConfigOptions.php index 4d48cdc9aa..83907a9269 100644 --- a/src/applications/project/config/PhabricatorProjectConfigOptions.php +++ b/src/applications/project/config/PhabricatorProjectConfigOptions.php @@ -12,9 +12,9 @@ final class PhabricatorProjectConfigOptions } public function getOptions() { - // This is intentionally blank for now, until we can move more Project - // logic to custom fields. - $default_fields = array(); + $default_fields = array( + 'std:project:internal:description' => true, + ); foreach ($default_fields as $key => $enabled) { $default_fields[$key] = array( diff --git a/src/applications/project/controller/PhabricatorProjectCreateController.php b/src/applications/project/controller/PhabricatorProjectCreateController.php index 5bed330282..f91d6c2b31 100644 --- a/src/applications/project/controller/PhabricatorProjectCreateController.php +++ b/src/applications/project/controller/PhabricatorProjectCreateController.php @@ -40,11 +40,10 @@ final class PhabricatorProjectCreateController // TODO: Deal with name collision exceptions more gracefully. - $profile->setBlurb($request->getStr('blurb')); - if (!$errors) { $project->save(); $profile->setProjectPHID($project->getPHID()); + $profile->setBlurb(''); $profile->save(); if ($request->isAjax()) { @@ -79,13 +78,7 @@ final class PhabricatorProjectCreateController ->setLabel(pht('Name')) ->setName('name') ->setValue($project->getName()) - ->setError($e_name)) - ->appendChild( - id(new AphrontFormTextAreaControl()) - ->setLabel(pht('Blurb')) - ->setName('blurb') - ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) - ->setValue($profile->getBlurb())); + ->setError($e_name)); if ($request->isAjax()) { $dialog = id(new AphrontDialogView()) diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php index e88ee1f044..203f8f0977 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileController.php @@ -271,13 +271,6 @@ final class PhabricatorProjectProfileController PhabricatorCustomField::ROLE_VIEW); $field_list->appendFieldsToPropertyList($project, $viewer, $view); - $view->addSectionHeader(pht('Description')); - $view->addTextContent( - PhabricatorMarkupEngine::renderOneObject( - id(new PhabricatorMarkupOneOff())->setContent($profile->getBlurb()), - 'default', - $viewer)); - return $view; } diff --git a/src/applications/project/controller/PhabricatorProjectProfileEditController.php b/src/applications/project/controller/PhabricatorProjectProfileEditController.php index 638401e9f8..5830e1d113 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileEditController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileEditController.php @@ -21,14 +21,11 @@ final class PhabricatorProjectProfileEditController PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) - ->needProfiles(true) ->executeOne(); if (!$project) { return new Aphront404Response(); } - $profile = $project->getProfile(); - $field_list = PhabricatorCustomField::getObjectFields( $project, PhabricatorCustomField::ROLE_EDIT); @@ -42,7 +39,6 @@ final class PhabricatorProjectProfileEditController $e_edit = null; $v_name = $project->getName(); - $v_desc = $profile->getBlurb(); $validation_exception = null; @@ -50,7 +46,6 @@ final class PhabricatorProjectProfileEditController $e_name = null; $v_name = $request->getStr('name'); - $v_desc = $request->getStr('blurb'); $v_view = $request->getStr('can_view'); $v_edit = $request->getStr('can_edit'); $v_join = $request->getStr('can_join'); @@ -86,13 +81,6 @@ final class PhabricatorProjectProfileEditController try { $editor->applyTransactions($project, $xactions); - // TODO: Move this into a custom field. - $profile->setBlurb($request->getStr('blurb')); - if (!$profile->getProjectPHID()) { - $profile->setProjectPHID($project->getPHID()); - } - $profile->save(); - return id(new AphrontRedirectResponse())->setURI($view_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; @@ -108,7 +96,6 @@ final class PhabricatorProjectProfileEditController $header_name = pht('Edit Project'); $title = pht('Edit Project'); - $action = '/project/edit/'.$project->getID().'/'; $policies = id(new PhabricatorPolicyQuery()) ->setViewer($viewer) @@ -117,20 +104,13 @@ final class PhabricatorProjectProfileEditController $form = new AphrontFormView(); $form - ->setID('project-edit-form') ->setUser($viewer) - ->setAction($action) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name')) ->setName('name') ->setValue($v_name) - ->setError($e_name)) - ->appendChild( - id(new PhabricatorRemarkupControl()) - ->setLabel(pht('Description')) - ->setName('blurb') - ->setValue($v_desc)); + ->setError($e_name)); $field_list->appendFieldsToForm($form); diff --git a/src/applications/project/customfield/PhabricatorProjectConfiguredCustomField.php b/src/applications/project/customfield/PhabricatorProjectConfiguredCustomField.php index b4aec137ac..8e2cb3dce1 100644 --- a/src/applications/project/customfield/PhabricatorProjectConfiguredCustomField.php +++ b/src/applications/project/customfield/PhabricatorProjectConfiguredCustomField.php @@ -1,7 +1,7 @@ array( + 'name' => pht('Description'), + 'type' => 'remarkup', + 'description' => pht('Short project description.'), + ), + )); + } + +} diff --git a/src/applications/project/customfield/PhabricatorProjectStandardCustomField.php b/src/applications/project/customfield/PhabricatorProjectStandardCustomField.php new file mode 100644 index 0000000000..de1972bcc8 --- /dev/null +++ b/src/applications/project/customfield/PhabricatorProjectStandardCustomField.php @@ -0,0 +1,23 @@ +