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();
}
$image = id(new PholioImage())
$image = PholioImage::initializeNewImage()
->attachFile($file)
->setName($title)
->setDescription($description)

View File

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

View File

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

View File

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

View File

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