1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00

Extract PHIDs from transactions later, fixing Paste extraction/attachment

Summary:
Fixes T9787. Currently, file PHID extraction logic happens very early, before we normalize/merge/etc the transactions.

In D14390, I changed how the CONTENT transaction works: before, callers would pass in a file PHID. Afterward, they just pass in the content.

Passing in the content is generaly easier and feels more correct, but inadvertenly broke PHID extraction because converting the content into a file PHID now happened after we extracted the PHID. So we'd extract the entire text of the paste as a "file PHID", which wouldn't work.

Instead, extract file PHIDs later. This impacts a couple of other applications (Conpherence, Pholio) which receive an object or have an unusual file-oriented transaction.

Test Plan:
  - Made a new paste, verified the raw file attached to it properly.
  - Made and updated a mock, verified all the files attached properly.
  - Updated a Conpherence room image, verified the files attached properly.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9787

Differential Revision: https://secure.phabricator.com/D14494
This commit is contained in:
epriestley 2015-11-16 09:53:08 -08:00
parent 5aae89babb
commit 06de605992
3 changed files with 21 additions and 11 deletions

View file

@ -623,9 +623,8 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case ConpherenceTransaction::TYPE_PICTURE: case ConpherenceTransaction::TYPE_PICTURE:
return array($xaction->getNewValue()->getPHID());
case ConpherenceTransaction::TYPE_PICTURE_CROP: case ConpherenceTransaction::TYPE_PICTURE_CROP:
return array($xaction->getNewValue()); return array($xaction->getNewValue());
} }
return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); return parent::extractFilePHIDsFromCustomTransaction($object, $xaction);

View file

@ -120,19 +120,31 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
$images = $this->getNewImages();
$images = mpull($images, null, 'getPHID');
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PholioTransaction::TYPE_IMAGE_FILE: case PholioTransaction::TYPE_IMAGE_FILE:
$new = $xaction->getNewValue(); $file_phids = array();
$phids = array(); foreach ($xaction->getNewValue() as $image_phid) {
foreach ($new as $key => $images) { $image = idx($images, $image_phid);
$phids[] = mpull($images, 'getFilePHID'); if (!$image) {
continue;
}
$file_phids[] = $image->getFilePHID();
} }
return array_mergev($phids); return $file_phids;
case PholioTransaction::TYPE_IMAGE_REPLACE: case PholioTransaction::TYPE_IMAGE_REPLACE:
return array($xaction->getNewValue()->getFilePHID()); $image_phid = $xaction->getNewValue();
$image = idx($images, $image_phid);
if ($image) {
return array($image->getFilePHID());
}
break;
} }
return array(); return parent::extractFilePHIDsFromCustomTransaction($object, $xaction);
} }

View file

@ -775,8 +775,6 @@ abstract class PhabricatorApplicationTransactionEditor
throw new PhabricatorApplicationTransactionValidationException($errors); throw new PhabricatorApplicationTransactionValidationException($errors);
} }
$file_phids = $this->extractFilePHIDs($object, $xactions);
if ($object->getID()) { if ($object->getID()) {
foreach ($xactions as $xaction) { foreach ($xactions as $xaction) {
@ -822,6 +820,7 @@ abstract class PhabricatorApplicationTransactionEditor
} }
$xactions = $this->sortTransactions($xactions); $xactions = $this->sortTransactions($xactions);
$file_phids = $this->extractFilePHIDs($object, $xactions);
if ($is_preview) { if ($is_preview) {
$this->loadHandles($xactions); $this->loadHandles($xactions);