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',
'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',

View file

@ -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(

View file

@ -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())

View file

@ -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;
}

View file

@ -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);

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorProjectConfiguredCustomField
extends PhabricatorProjectCustomField
extends PhabricatorProjectStandardCustomField
implements PhabricatorStandardCustomFieldInterface {
public function getStandardCustomFieldNamespace() {
@ -16,16 +16,4 @@ final class PhabricatorProjectConfiguredCustomField
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();
}
}