Give Pholio images a more modern initializer method

Summary: Depends on D19910. Ref T11351. Minor changes to make this behave in a more modern way.

Test Plan:
  - Destroyed a mock.
  - Lipsum'd a mock.
  - Poked around, edited/viewed mocks.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T11351

Differential Revision: https://secure.phabricator.com/D19911
This commit is contained in:
epriestley
2018-12-18 15:23:07 -08:00
parent 38083f6f9e
commit 1d84b5b86b
5 changed files with 24 additions and 16 deletions

View File

@@ -22,7 +22,7 @@ final class PholioImageUploadController extends PholioController {
$title = $file->getName(); $title = $file->getName();
} }
$image = id(new PholioImage()) $image = PholioImage::initializeNewImage()
->attachFile($file) ->attachFile($file)
->setName($title) ->setName($title)
->setDescription($description) ->setDescription($description)

View File

@@ -140,7 +140,7 @@ final class PholioMockEditController extends PholioController {
$sequence = $sequence_map[$file_phid]; $sequence = $sequence_map[$file_phid];
if ($replaces_image_phid) { if ($replaces_image_phid) {
$replace_image = id(new PholioImage()) $replace_image = PholioImage::initializeNewImage()
->setReplacesImagePHID($replaces_image_phid) ->setReplacesImagePHID($replaces_image_phid)
->setFilePhid($file_phid) ->setFilePhid($file_phid)
->attachFile($file) ->attachFile($file)
@@ -153,7 +153,7 @@ final class PholioMockEditController extends PholioController {
->setNewValue($replace_image); ->setNewValue($replace_image);
$posted_mock_images[] = $replace_image; $posted_mock_images[] = $replace_image;
} else if (!$existing_image) { // this is an add } else if (!$existing_image) { // this is an add
$add_image = id(new PholioImage()) $add_image = PholioImage::initializeNewImage()
->setFilePhid($file_phid) ->setFilePhid($file_phid)
->attachFile($file) ->attachFile($file)
->setName(strlen($title) ? $title : $file->getName()) ->setName(strlen($title) ? $title : $file->getName())

View File

@@ -41,10 +41,11 @@ final class PhabricatorPholioMockTestDataGenerator
$sequence = 0; $sequence = 0;
$images = array(); $images = array();
foreach ($files as $file) { foreach ($files as $file) {
$image = new PholioImage(); $image = PholioImage::initializeNewImage()
$image->setFilePHID($file->getPHID()); ->setFilePHID($file->getPHID())
$image->setSequence($sequence++); ->setSequence($sequence++)
$image->attachMock($mock); ->attachMock($mock);
$images[] = $image; $images[] = $image;
} }

View File

@@ -9,16 +9,23 @@ final class PholioImage extends PholioDAO
protected $mockID; protected $mockID;
protected $filePHID; protected $filePHID;
protected $name = ''; protected $name;
protected $description = ''; protected $description;
protected $sequence; protected $sequence;
protected $isObsolete = 0; protected $isObsolete;
protected $replacesImagePHID = null; protected $replacesImagePHID = null;
private $inlineComments = self::ATTACHABLE; private $inlineComments = self::ATTACHABLE;
private $file = self::ATTACHABLE; private $file = self::ATTACHABLE;
private $mock = self::ATTACHABLE; private $mock = self::ATTACHABLE;
public static function initializeNewImage() {
return id(new self())
->setName('')
->setDescription('')
->setIsObsolete(0);
}
protected function getConfiguration() { protected function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
@@ -43,8 +50,8 @@ final class PholioImage extends PholioDAO
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }
public function generatePHID() { public function getPHIDType() {
return PhabricatorPHID::generateNewPHID(PholioImagePHIDType::TYPECONST); return PholioImagePHIDType::TYPECONST;
} }
public function attachFile(PhabricatorFile $file) { public function attachFile(PhabricatorFile $file) {
@@ -67,7 +74,6 @@ final class PholioImage extends PholioDAO
return $this->mock; return $this->mock;
} }
public function attachInlineComments(array $inline_comments) { public function attachInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PholioTransactionComment'); assert_instances_of($inline_comments, 'PholioTransactionComment');
$this->inlineComments = $inline_comments; $this->inlineComments = $inline_comments;

View File

@@ -295,9 +295,10 @@ final class PholioMock extends PholioDAO
PhabricatorDestructionEngine $engine) { PhabricatorDestructionEngine $engine) {
$this->openTransaction(); $this->openTransaction();
$images = id(new PholioImage())->loadAllWhere( $images = id(new PholioImageQuery())
'mockID = %d', ->setViewer($engine->getViewer())
$this->getID()); ->withMockIDs(array($this->getID()))
->execute();
foreach ($images as $image) { foreach ($images as $image) {
$image->delete(); $image->delete();
} }