2011-06-10 00:28:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-24 16:11:37 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-06-10 00:28:29 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorProjectCreateController
|
2011-06-10 00:28:29 +02:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$project = new PhabricatorProject();
|
|
|
|
$project->setAuthorPHID($user->getPHID());
|
|
|
|
$profile = new PhabricatorProjectProfile();
|
|
|
|
|
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
try {
|
2012-01-24 16:11:37 +01:00
|
|
|
$xactions = array();
|
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_NAME);
|
|
|
|
$xaction->setNewValue($request->getStr('name'));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
$editor = new PhabricatorProjectEditor($project);
|
|
|
|
$editor->setUser($user);
|
2012-01-24 16:11:37 +01:00
|
|
|
$editor->applyTransactions($xactions);
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
} catch (PhabricatorProjectNameCollisionException $ex) {
|
|
|
|
$e_name = 'Not Unique';
|
|
|
|
$errors[] = $ex->getMessage();
|
|
|
|
}
|
|
|
|
|
2011-06-10 00:28:29 +02:00
|
|
|
$profile->setBlurb($request->getStr('blurb'));
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$project->save();
|
|
|
|
$profile->setProjectPHID($project->getPHID());
|
|
|
|
$profile->save();
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
id(new PhabricatorProjectAffiliation())
|
|
|
|
->setUserPHID($user->getPHID())
|
|
|
|
->setProjectPHID($project->getPHID())
|
|
|
|
->setRole('Owner')
|
|
|
|
->setIsOwner(true)
|
|
|
|
->save();
|
|
|
|
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(array(
|
|
|
|
'phid' => $project->getPHID(),
|
|
|
|
'name' => $project->getName(),
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/project/view/'.$project->getID().'/');
|
|
|
|
}
|
2011-06-10 00:28:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = new AphrontErrorView();
|
|
|
|
$error_view->setTitle('Form Errors');
|
|
|
|
$error_view->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
$form = new AphrontFormLayoutView();
|
|
|
|
} else {
|
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form->setUser($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
2011-06-10 00:28:29 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Name')
|
|
|
|
->setName('name')
|
|
|
|
->setValue($project->getName())
|
|
|
|
->setError($e_name))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel('Blurb')
|
|
|
|
->setName('blurb')
|
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
|
|
|
|
->setValue($profile->getBlurb()));
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
|
|
|
|
if ($error_view) {
|
|
|
|
$error_view->setWidth(AphrontErrorView::WIDTH_DIALOG);
|
|
|
|
}
|
2011-06-10 00:28:29 +02:00
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setTitle('Create a New Project')
|
|
|
|
->appendChild($error_view)
|
|
|
|
->appendChild($form)
|
|
|
|
->addSubmitButton('Create Project')
|
|
|
|
->addCancelButton('/project/');
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Create')
|
|
|
|
->addCancelButton('/project/'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel
|
|
|
|
->setWidth(AphrontPanelView::WIDTH_FORM)
|
|
|
|
->setHeader('Create a New Project')
|
|
|
|
->appendChild($form);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
|
|
|
$error_view,
|
|
|
|
$panel,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => 'Create new Project',
|
|
|
|
));
|
|
|
|
}
|
2011-06-10 00:28:29 +02:00
|
|
|
}
|
|
|
|
}
|