1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

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
This commit is contained in:
epriestley 2014-02-10 14:31:57 -08:00
parent 7c8a875c19
commit 1520065ec0
9 changed files with 83 additions and 54 deletions

View file

@ -0,0 +1,26 @@
<?php
$conn_w = id(new PhabricatorProject())->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";

View file

@ -1840,6 +1840,7 @@ phutil_register_library_map(array(
'PhabricatorProjectCustomFieldStorage' => 'applications/project/storage/PhabricatorProjectCustomFieldStorage.php', 'PhabricatorProjectCustomFieldStorage' => 'applications/project/storage/PhabricatorProjectCustomFieldStorage.php',
'PhabricatorProjectCustomFieldStringIndex' => 'applications/project/storage/PhabricatorProjectCustomFieldStringIndex.php', 'PhabricatorProjectCustomFieldStringIndex' => 'applications/project/storage/PhabricatorProjectCustomFieldStringIndex.php',
'PhabricatorProjectDAO' => 'applications/project/storage/PhabricatorProjectDAO.php', 'PhabricatorProjectDAO' => 'applications/project/storage/PhabricatorProjectDAO.php',
'PhabricatorProjectDescriptionField' => 'applications/project/customfield/PhabricatorProjectDescriptionField.php',
'PhabricatorProjectEditorTestCase' => 'applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php', 'PhabricatorProjectEditorTestCase' => 'applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php',
'PhabricatorProjectHistoryController' => 'applications/project/controller/PhabricatorProjectHistoryController.php', 'PhabricatorProjectHistoryController' => 'applications/project/controller/PhabricatorProjectHistoryController.php',
'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php', 'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php',
@ -1855,6 +1856,7 @@ phutil_register_library_map(array(
'PhabricatorProjectQuery' => 'applications/project/query/PhabricatorProjectQuery.php', 'PhabricatorProjectQuery' => 'applications/project/query/PhabricatorProjectQuery.php',
'PhabricatorProjectSearchEngine' => 'applications/project/query/PhabricatorProjectSearchEngine.php', 'PhabricatorProjectSearchEngine' => 'applications/project/query/PhabricatorProjectSearchEngine.php',
'PhabricatorProjectSearchIndexer' => 'applications/project/search/PhabricatorProjectSearchIndexer.php', 'PhabricatorProjectSearchIndexer' => 'applications/project/search/PhabricatorProjectSearchIndexer.php',
'PhabricatorProjectStandardCustomField' => 'applications/project/customfield/PhabricatorProjectStandardCustomField.php',
'PhabricatorProjectStatus' => 'applications/project/constants/PhabricatorProjectStatus.php', 'PhabricatorProjectStatus' => 'applications/project/constants/PhabricatorProjectStatus.php',
'PhabricatorProjectTestDataGenerator' => 'applications/project/lipsum/PhabricatorProjectTestDataGenerator.php', 'PhabricatorProjectTestDataGenerator' => 'applications/project/lipsum/PhabricatorProjectTestDataGenerator.php',
'PhabricatorProjectTransaction' => 'applications/project/storage/PhabricatorProjectTransaction.php', 'PhabricatorProjectTransaction' => 'applications/project/storage/PhabricatorProjectTransaction.php',
@ -4574,7 +4576,7 @@ phutil_register_library_map(array(
'PhabricatorProjectConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorProjectConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorProjectConfiguredCustomField' => 'PhabricatorProjectConfiguredCustomField' =>
array( array(
0 => 'PhabricatorProjectCustomField', 0 => 'PhabricatorProjectStandardCustomField',
1 => 'PhabricatorStandardCustomFieldInterface', 1 => 'PhabricatorStandardCustomFieldInterface',
), ),
'PhabricatorProjectController' => 'PhabricatorController', 'PhabricatorProjectController' => 'PhabricatorController',
@ -4584,6 +4586,7 @@ phutil_register_library_map(array(
'PhabricatorProjectCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 'PhabricatorProjectCustomFieldStorage' => 'PhabricatorCustomFieldStorage',
'PhabricatorProjectCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 'PhabricatorProjectCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage',
'PhabricatorProjectDAO' => 'PhabricatorLiskDAO', 'PhabricatorProjectDAO' => 'PhabricatorLiskDAO',
'PhabricatorProjectDescriptionField' => 'PhabricatorProjectStandardCustomField',
'PhabricatorProjectEditorTestCase' => 'PhabricatorTestCase', 'PhabricatorProjectEditorTestCase' => 'PhabricatorTestCase',
'PhabricatorProjectHistoryController' => 'PhabricatorProjectController', 'PhabricatorProjectHistoryController' => 'PhabricatorProjectController',
'PhabricatorProjectListController' => 'PhabricatorProjectListController' =>
@ -4603,6 +4606,11 @@ phutil_register_library_map(array(
'PhabricatorProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorProjectSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorProjectSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorProjectSearchIndexer' => 'PhabricatorSearchDocumentIndexer', 'PhabricatorProjectSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
'PhabricatorProjectStandardCustomField' =>
array(
0 => 'PhabricatorProjectCustomField',
1 => 'PhabricatorStandardCustomFieldInterface',
),
'PhabricatorProjectTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorProjectTestDataGenerator' => 'PhabricatorTestDataGenerator',
'PhabricatorProjectTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorProjectTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorProjectTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorProjectTransactionEditor' => 'PhabricatorApplicationTransactionEditor',

View file

@ -12,9 +12,9 @@ final class PhabricatorProjectConfigOptions
} }
public function getOptions() { public function getOptions() {
// This is intentionally blank for now, until we can move more Project $default_fields = array(
// logic to custom fields. 'std:project:internal:description' => true,
$default_fields = array(); );
foreach ($default_fields as $key => $enabled) { foreach ($default_fields as $key => $enabled) {
$default_fields[$key] = array( $default_fields[$key] = array(

View file

@ -40,11 +40,10 @@ final class PhabricatorProjectCreateController
// TODO: Deal with name collision exceptions more gracefully. // TODO: Deal with name collision exceptions more gracefully.
$profile->setBlurb($request->getStr('blurb'));
if (!$errors) { if (!$errors) {
$project->save(); $project->save();
$profile->setProjectPHID($project->getPHID()); $profile->setProjectPHID($project->getPHID());
$profile->setBlurb('');
$profile->save(); $profile->save();
if ($request->isAjax()) { if ($request->isAjax()) {
@ -79,13 +78,7 @@ final class PhabricatorProjectCreateController
->setLabel(pht('Name')) ->setLabel(pht('Name'))
->setName('name') ->setName('name')
->setValue($project->getName()) ->setValue($project->getName())
->setError($e_name)) ->setError($e_name));
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel(pht('Blurb'))
->setName('blurb')
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
->setValue($profile->getBlurb()));
if ($request->isAjax()) { if ($request->isAjax()) {
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())

View file

@ -271,13 +271,6 @@ final class PhabricatorProjectProfileController
PhabricatorCustomField::ROLE_VIEW); PhabricatorCustomField::ROLE_VIEW);
$field_list->appendFieldsToPropertyList($project, $viewer, $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; return $view;
} }

View file

@ -21,14 +21,11 @@ final class PhabricatorProjectProfileEditController
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->needProfiles(true)
->executeOne(); ->executeOne();
if (!$project) { if (!$project) {
return new Aphront404Response(); return new Aphront404Response();
} }
$profile = $project->getProfile();
$field_list = PhabricatorCustomField::getObjectFields( $field_list = PhabricatorCustomField::getObjectFields(
$project, $project,
PhabricatorCustomField::ROLE_EDIT); PhabricatorCustomField::ROLE_EDIT);
@ -42,7 +39,6 @@ final class PhabricatorProjectProfileEditController
$e_edit = null; $e_edit = null;
$v_name = $project->getName(); $v_name = $project->getName();
$v_desc = $profile->getBlurb();
$validation_exception = null; $validation_exception = null;
@ -50,7 +46,6 @@ final class PhabricatorProjectProfileEditController
$e_name = null; $e_name = null;
$v_name = $request->getStr('name'); $v_name = $request->getStr('name');
$v_desc = $request->getStr('blurb');
$v_view = $request->getStr('can_view'); $v_view = $request->getStr('can_view');
$v_edit = $request->getStr('can_edit'); $v_edit = $request->getStr('can_edit');
$v_join = $request->getStr('can_join'); $v_join = $request->getStr('can_join');
@ -86,13 +81,6 @@ final class PhabricatorProjectProfileEditController
try { try {
$editor->applyTransactions($project, $xactions); $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); return id(new AphrontRedirectResponse())->setURI($view_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) { } catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex; $validation_exception = $ex;
@ -108,7 +96,6 @@ final class PhabricatorProjectProfileEditController
$header_name = pht('Edit Project'); $header_name = pht('Edit Project');
$title = pht('Edit Project'); $title = pht('Edit Project');
$action = '/project/edit/'.$project->getID().'/';
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -117,20 +104,13 @@ final class PhabricatorProjectProfileEditController
$form = new AphrontFormView(); $form = new AphrontFormView();
$form $form
->setID('project-edit-form')
->setUser($viewer) ->setUser($viewer)
->setAction($action)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel(pht('Name')) ->setLabel(pht('Name'))
->setName('name') ->setName('name')
->setValue($v_name) ->setValue($v_name)
->setError($e_name)) ->setError($e_name));
->appendChild(
id(new PhabricatorRemarkupControl())
->setLabel(pht('Description'))
->setName('blurb')
->setValue($v_desc));
$field_list->appendFieldsToForm($form); $field_list->appendFieldsToForm($form);

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhabricatorProjectConfiguredCustomField final class PhabricatorProjectConfiguredCustomField
extends PhabricatorProjectCustomField extends PhabricatorProjectStandardCustomField
implements PhabricatorStandardCustomFieldInterface { implements PhabricatorStandardCustomFieldInterface {
public function getStandardCustomFieldNamespace() { public function getStandardCustomFieldNamespace() {
@ -16,16 +16,4 @@ final class PhabricatorProjectConfiguredCustomField
array())); array()));
} }
public function newStorageObject() {
return new PhabricatorProjectCustomFieldStorage();
}
protected function newStringIndexStorage() {
return new PhabricatorProjectCustomFieldStringIndex();
}
protected function newNumericIndexStorage() {
return new PhabricatorProjectCustomFieldNumericIndex();
}
} }

View file

@ -0,0 +1,18 @@
<?php
final class PhabricatorProjectDescriptionField
extends PhabricatorProjectStandardCustomField {
public function createFields() {
return PhabricatorStandardCustomField::buildStandardFields(
$this,
array(
'description' => array(
'name' => pht('Description'),
'type' => 'remarkup',
'description' => pht('Short project description.'),
),
));
}
}

View file

@ -0,0 +1,23 @@
<?php
abstract class PhabricatorProjectStandardCustomField
extends PhabricatorProjectCustomField
implements PhabricatorStandardCustomFieldInterface {
public function getStandardCustomFieldNamespace() {
return 'project:internal';
}
public function newStorageObject() {
return new PhabricatorProjectCustomFieldStorage();
}
protected function newStringIndexStorage() {
return new PhabricatorProjectCustomFieldStringIndex();
}
protected function newNumericIndexStorage() {
return new PhabricatorProjectCustomFieldNumericIndex();
}
}