2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group conpherence
|
|
|
|
*/
|
|
|
|
final class ConpherenceUpdateController extends
|
|
|
|
ConpherenceController {
|
|
|
|
|
|
|
|
private $conpherenceID;
|
|
|
|
|
|
|
|
public function setConpherenceID($conpherence_id) {
|
|
|
|
$this->conpherenceID = $conpherence_id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getConpherenceID() {
|
|
|
|
return $this->conpherenceID;
|
|
|
|
}
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->setConpherenceID(idx($data, 'id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
$conpherence_id = $this->getConpherenceID();
|
|
|
|
if (!$conpherence_id) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($conpherence_id))
|
|
|
|
->executeOne();
|
|
|
|
$supported_formats = PhabricatorFile::getTransformableImageFormats();
|
|
|
|
|
|
|
|
$updated = false;
|
|
|
|
$error_view = null;
|
2013-01-27 02:14:58 +01:00
|
|
|
$e_file = array();
|
2013-01-25 02:23:05 +01:00
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr()
|
|
|
|
));
|
|
|
|
|
|
|
|
$action = $request->getStr('action');
|
|
|
|
switch ($action) {
|
|
|
|
case 'message':
|
|
|
|
$message = $request->getStr('text');
|
|
|
|
$files = array();
|
|
|
|
$file_phids =
|
|
|
|
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
|
|
|
array($message)
|
|
|
|
);
|
|
|
|
if ($file_phids) {
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs($file_phids)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
$xactions = array();
|
|
|
|
if ($files) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
|
|
|
->setNewValue(array('+' => mpull($files, 'getPHID')));
|
|
|
|
}
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new ConpherenceTransactionComment())
|
|
|
|
->setContent($message)
|
|
|
|
->setConpherencePHID($conpherence->getPHID())
|
|
|
|
);
|
|
|
|
$time = time();
|
|
|
|
$conpherence->openTransaction();
|
|
|
|
$xactions = id(new ConpherenceEditor())
|
|
|
|
->setContentSource($content_source)
|
|
|
|
->setActor($user)
|
|
|
|
->applyTransactions($conpherence, $xactions);
|
|
|
|
$last_xaction = end($xactions);
|
|
|
|
$xaction_phid = $last_xaction->getPHID();
|
|
|
|
$behind = ConpherenceParticipationStatus::BEHIND;
|
|
|
|
$up_to_date = ConpherenceParticipationStatus::UP_TO_DATE;
|
|
|
|
$participants = $conpherence->getParticipants();
|
|
|
|
foreach ($participants as $phid => $participant) {
|
|
|
|
if ($phid != $user->getPHID()) {
|
|
|
|
if ($participant->getParticipationStatus() != $behind) {
|
|
|
|
$participant->setBehindTransactionPHID($xaction_phid);
|
|
|
|
}
|
|
|
|
$participant->setParticipationStatus($behind);
|
|
|
|
$participant->setDateTouched($time);
|
|
|
|
} else {
|
|
|
|
$participant->setParticipationStatus($up_to_date);
|
|
|
|
$participant->setDateTouched($time);
|
|
|
|
}
|
|
|
|
$participant->save();
|
|
|
|
}
|
|
|
|
$updated = $conpherence->saveTransaction();
|
|
|
|
break;
|
|
|
|
case 'metadata':
|
|
|
|
$xactions = array();
|
2013-01-27 02:14:58 +01:00
|
|
|
$images = $request->getArr('image');
|
|
|
|
if ($images) {
|
|
|
|
// just take the first one
|
|
|
|
$file_phid = reset($images);
|
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($file_phid))
|
|
|
|
->executeOne();
|
|
|
|
$okay = $file->isTransformableImage();
|
|
|
|
if ($okay) {
|
|
|
|
$xformer = new PhabricatorImageTransformer();
|
|
|
|
$xformed = $xformer->executeThumbTransform(
|
|
|
|
$file,
|
|
|
|
$x = 50,
|
|
|
|
$y = 50);
|
|
|
|
$image_phid = $xformed->getPHID();
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_PICTURE)
|
|
|
|
->setNewValue($image_phid);
|
|
|
|
} else {
|
|
|
|
$e_file[] = $file;
|
|
|
|
$errors[] =
|
|
|
|
pht('This server only supports these image formats: %s.',
|
2013-01-25 02:23:05 +01:00
|
|
|
implode(', ', $supported_formats));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$title = $request->getStr('title');
|
|
|
|
if ($title != $conpherence->getTitle()) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)
|
|
|
|
->setNewValue($title);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($xactions) {
|
|
|
|
$conpherence->openTransaction();
|
|
|
|
$xactions = id(new ConpherenceEditor())
|
|
|
|
->setContentSource($content_source)
|
|
|
|
->setActor($user)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->applyTransactions($conpherence, $xactions);
|
|
|
|
$updated = $conpherence->saveTransaction();
|
|
|
|
} else if (empty($errors)) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'That was a non-update. Try cancel.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception('Unknown action: '.$action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($updated) {
|
|
|
|
return id(new AphrontRedirectResponse())->setURI(
|
|
|
|
$this->getApplicationURI($conpherence_id.'/')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Errors editing conpherence.'))
|
2013-01-27 02:14:58 +01:00
|
|
|
->setInsideDialogue(true)
|
2013-01-25 02:23:05 +01:00
|
|
|
->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormLayoutView())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Title'))
|
|
|
|
->setName('title')
|
|
|
|
->setValue($conpherence->getTitle())
|
|
|
|
)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setLabel(pht('Image'))
|
|
|
|
->setValue(phutil_render_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => $conpherence->loadImageURI(),
|
|
|
|
))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
->appendChild(
|
2013-01-27 02:14:58 +01:00
|
|
|
id(new AphrontFormDragAndDropUploadControl())
|
2013-01-25 02:23:05 +01:00
|
|
|
->setLabel(pht('Change Image'))
|
|
|
|
->setName('image')
|
2013-01-27 02:14:58 +01:00
|
|
|
->setValue($e_file)
|
2013-01-25 02:23:05 +01:00
|
|
|
->setCaption('Supported formats: '.implode(', ', $supported_formats))
|
2013-01-27 02:14:58 +01:00
|
|
|
);
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
require_celerity_resource('conpherence-update-css');
|
2013-01-27 02:14:58 +01:00
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog(
|
2013-01-25 02:23:05 +01:00
|
|
|
id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('Update Conpherence'))
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setSubmitURI($this->getApplicationURI('update/'.$conpherence_id.'/'))
|
|
|
|
->addHiddenInput('action', 'metadata')
|
2013-01-27 02:14:58 +01:00
|
|
|
->appendChild($error_view)
|
2013-01-25 02:23:05 +01:00
|
|
|
->appendChild($form)
|
|
|
|
->addSubmitButton()
|
2013-01-27 02:14:58 +01:00
|
|
|
->addCancelButton($this->getApplicationURI($conpherence->getID().'/'))
|
|
|
|
);
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
}
|