Migrate project profiles onto projects, and remove ProjectProfile object

Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.

The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.

Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4379

Differential Revision: https://secure.phabricator.com/D8183
This commit is contained in:
epriestley
2014-02-10 14:32:14 -08:00
parent 1520065ec0
commit 8c84ed61b1
12 changed files with 48 additions and 105 deletions

View File

@@ -17,7 +17,7 @@ final class PhabricatorProjectQuery
const STATUS_ARCHIVED = 'status-archived';
private $needMembers;
private $needProfiles;
private $needImages;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -54,8 +54,8 @@ final class PhabricatorProjectQuery
return $this;
}
public function needProfiles($need_profiles) {
$this->needProfiles = $need_profiles;
public function needImages($need_images) {
$this->needImages = $need_images;
return $this;
}
@@ -126,49 +126,27 @@ final class PhabricatorProjectQuery
}
protected function didFilterPage(array $projects) {
if ($this->needProfiles) {
$profiles = id(new PhabricatorProjectProfile())->loadAllWhere(
'projectPHID IN (%Ls)',
mpull($projects, 'getPHID'));
$profiles = mpull($profiles, null, 'getProjectPHID');
if ($this->needImages) {
$default = null;
if ($profiles) {
$file_phids = mpull($profiles, 'getProfileImagePHID');
$files = id(new PhabricatorFileQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
foreach ($profiles as $profile) {
$file = idx($files, $profile->getProfileImagePHID());
if (!$file) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'project.png');
}
$file = $default;
}
$profile->attachProfileImageFile($file);
}
}
$file_phids = mpull($projects, 'getProfileImagePHID');
$files = id(new PhabricatorFileQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
foreach ($projects as $project) {
$profile = idx($profiles, $project->getPHID());
if (!$profile) {
$file = idx($files, $project->getProfileImagePHID());
if (!$file) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'project.png');
}
$profile = id(new PhabricatorProjectProfile())
->setProjectPHID($project->getPHID())
->attachProfileImageFile($default);
$file = $default;
}
$project->attachProfile($profile);
$project->attachProfileImageFile($file);
}
}