1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-27 15:08:20 +01:00

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

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_project.project
ADD profileImagePHID VARCHAR(64) COLLATE utf8_bin;

View file

@ -0,0 +1,4 @@
UPDATE {$NAMESPACE}_project.project proj,
{$NAMESPACE}_project.project_profile profile
SET proj.profileImagePHID = profile.profileImagePHID
WHERE proj.phid = profile.projectPHID;

View file

@ -1849,7 +1849,6 @@ phutil_register_library_map(array(
'PhabricatorProjectNameCollisionException' => 'applications/project/exception/PhabricatorProjectNameCollisionException.php',
'PhabricatorProjectPHIDTypeColumn' => 'applications/project/phid/PhabricatorProjectPHIDTypeColumn.php',
'PhabricatorProjectPHIDTypeProject' => 'applications/project/phid/PhabricatorProjectPHIDTypeProject.php',
'PhabricatorProjectProfile' => 'applications/project/storage/PhabricatorProjectProfile.php',
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
'PhabricatorProjectProfileEditController' => 'applications/project/controller/PhabricatorProjectProfileEditController.php',
'PhabricatorProjectProfilePictureController' => 'applications/project/controller/PhabricatorProjectProfilePictureController.php',
@ -4599,7 +4598,6 @@ phutil_register_library_map(array(
'PhabricatorProjectNameCollisionException' => 'Exception',
'PhabricatorProjectPHIDTypeColumn' => 'PhabricatorPHIDType',
'PhabricatorProjectPHIDTypeProject' => 'PhabricatorPHIDType',
'PhabricatorProjectProfile' => 'PhabricatorProjectDAO',
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
'PhabricatorProjectProfileEditController' => 'PhabricatorProjectController',
'PhabricatorProjectProfilePictureController' => 'PhabricatorProjectController',

View file

@ -21,7 +21,6 @@ final class PhabricatorProjectArchiveController
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->needProfiles(true)
->executeOne();
if (!$project) {
return new Aphront404Response();

View file

@ -13,7 +13,6 @@ final class PhabricatorProjectCreateController
ProjectCapabilityCreateProjects::CAPABILITY);
$project = PhabricatorProject::initializeNewProject($user);
$profile = new PhabricatorProjectProfile();
$e_name = true;
$errors = array();
@ -42,9 +41,6 @@ final class PhabricatorProjectCreateController
if (!$errors) {
$project->save();
$profile->setProjectPHID($project->getPHID());
$profile->setBlurb('');
$profile->save();
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())

View file

@ -23,18 +23,17 @@ final class PhabricatorProjectProfileController
->setViewer($user)
->withIDs(array($this->id))
->needMembers(true)
->needProfiles(true)
->needImages(true)
->executeOne();
if (!$project) {
return new Aphront404Response();
}
$profile = $project->getProfile();
$picture = $profile->getProfileImageURI();
$picture = $project->getProfileImageURI();
require_celerity_resource('phabricator-profile-css');
$tasks = $this->renderTasksPage($project, $profile);
$tasks = $this->renderTasksPage($project);
$query = new PhabricatorFeedQuery();
$query->setFilterPHIDs(
@ -62,9 +61,8 @@ final class PhabricatorProjectProfileController
$header->setStatus('policy-noone', '', pht('Archived'));
}
$actions = $this->buildActionListView($project);
$properties = $this->buildPropertyListView($project, $profile, $actions);
$properties = $this->buildPropertyListView($project, $actions);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($project->getName())
@ -86,9 +84,7 @@ final class PhabricatorProjectProfileController
));
}
private function renderFeedPage(
PhabricatorProject $project,
PhabricatorProjectProfile $profile) {
private function renderFeedPage(PhabricatorProject $project) {
$query = new PhabricatorFeedQuery();
$query->setFilterPHIDs(array($project->getPHID()));
@ -117,9 +113,7 @@ final class PhabricatorProjectProfileController
}
private function renderTasksPage(
PhabricatorProject $project,
PhabricatorProjectProfile $profile) {
private function renderTasksPage(PhabricatorProject $project) {
$user = $this->getRequest()->getUser();
@ -244,7 +238,6 @@ final class PhabricatorProjectProfileController
private function buildPropertyListView(
PhabricatorProject $project,
PhabricatorProjectProfile $profile,
PhabricatorActionListView $actions) {
$request = $this->getRequest();
$viewer = $request->getUser();

View file

@ -16,7 +16,6 @@ final class PhabricatorProjectProfilePictureController
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($this->id))
->needProfiles(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
@ -75,14 +74,13 @@ final class PhabricatorProjectProfilePictureController
}
if (!$errors) {
$profile = $project->getProfile();
if ($is_default) {
$profile->setProfileImagePHID(null);
$project->setProfileImagePHID(null);
} else {
$profile->setProfileImagePHID($xformed->getPHID());
$project->setProfileImagePHID($xformed->getPHID());
$xformed->attachToObject($viewer, $project->getPHID());
}
$profile->save();
$project->save();
return id(new AphrontRedirectResponse())->setURI($project_uri);
}
}
@ -99,7 +97,7 @@ final class PhabricatorProjectProfilePictureController
$images = array();
$current = $project->getProfile()->getProfileImagePHID();
$current = $project->getProfileImagePHID();
$has_current = false;
if ($current) {
$files = id(new PhabricatorFileQuery())

View file

@ -37,11 +37,6 @@ final class PhabricatorProjectTestDataGenerator
->setContentSource(PhabricatorContentSource::newConsoleSource())
->applyTransactions($project, $this->xactions);
$profile = id(new PhabricatorProjectProfile())
->setBlurb($this->generateDescription())
->setProjectPHID($project->getPHID())
->save();
return $project->save();
}

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

View file

@ -12,6 +12,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO
protected $authorPHID;
protected $subprojectPHIDs = array();
protected $phrictionSlug;
protected $profileImagePHID;
protected $viewPolicy;
protected $editPolicy;
@ -19,8 +20,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO
private $memberPHIDs = self::ATTACHABLE;
private $sparseMembers = self::ATTACHABLE;
private $profile = self::ATTACHABLE;
private $customFields = self::ATTACHABLE;
private $profileImageFile = self::ATTACHABLE;
public static function initializeNewProject(PhabricatorUser $actor) {
return id(new PhabricatorProject())
@ -113,15 +114,6 @@ final class PhabricatorProject extends PhabricatorProjectDAO
PhabricatorProjectPHIDTypeProject::TYPECONST);
}
public function getProfile() {
return $this->assertAttached($this->profile);
}
public function attachProfile(PhabricatorProjectProfile $profile) {
$this->profile = $profile;
return $this;
}
public function attachMemberPHIDs(array $phids) {
$this->memberPHIDs = $phids;
return $this;
@ -153,6 +145,19 @@ final class PhabricatorProject extends PhabricatorProjectDAO
return ($this->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED);
}
public function getProfileImageURI() {
return $this->getProfileImageFile()->getBestURI();
}
public function attachProfileImageFile(PhabricatorFile $file) {
$this->profileImageFile = $file;
return $this;
}
public function getProfileImageFile() {
return $this->assertAttached($this->profileImageFile);
}
/* -( PhabricatorSubscribableInterface )----------------------------------- */

View file

@ -1,24 +0,0 @@
<?php
final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
protected $projectPHID;
protected $blurb;
protected $profileImagePHID;
private $profileImageFile = self::ATTACHABLE;
public function getProfileImageURI() {
return $this->getProfileImageFile()->getBestURI();
}
public function attachProfileImageFile(PhabricatorFile $file) {
$this->profileImageFile = $file;
return $this;
}
public function getProfileImageFile() {
return $this->assertAttached($this->profileImageFile);
}
}

View file

@ -286,7 +286,7 @@ final class PhabricatorTypeaheadCommonDatasourceController
$projs = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withStatus(PhabricatorProjectQuery::STATUS_OPEN)
->needProfiles(true)
->needImages(true)
->execute();
foreach ($projs as $proj) {
$proj_result = id(new PhabricatorTypeaheadResult())
@ -295,8 +295,7 @@ final class PhabricatorTypeaheadCommonDatasourceController
->setURI('/project/view/'.$proj->getID().'/')
->setPHID($proj->getPHID());
$prof = $proj->getProfile();
$proj_result->setImageURI($prof->getProfileImageURI());
$proj_result->setImageURI($proj->getProfileImageURI());
$results[] = $proj_result;
}