Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2891439
ManiphestTaskCoverImageTransaction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
3 KB
Referenced Files
None
Subscribers
None
ManiphestTaskCoverImageTransaction.php
View Options
<?php
final
class
ManiphestTaskCoverImageTransaction
extends
ManiphestTaskTransactionType
{
const
TRANSACTIONTYPE
=
'cover-image'
;
public
function
generateOldValue
(
$object
)
{
return
$object
->
getCoverImageFilePHID
(
)
;
}
public
function
applyInternalEffects
(
$object
,
$value
)
{
$file_phid
=
$value
;
if
(
$file_phid
)
{
$file
=
id
(
new
PhabricatorFileQuery
(
)
)
->
setViewer
(
$this
->
getActor
(
)
)
->
withPHIDs
(
array
(
$file_phid
)
)
->
executeOne
(
)
;
}
else
{
$file
=
null
;
}
if
(
!
$file
||
!
$file
->
isTransformableImage
(
)
)
{
$object
->
setProperty
(
'cover.filePHID'
,
null
)
;
$object
->
setProperty
(
'cover.thumbnailPHID'
,
null
)
;
return
;
}
// Generate an image transformation, usually smaller (orphan now).
$xform_key
=
PhabricatorFileThumbnailTransform
::
TRANSFORM_WORKCARD
;
$xform
=
PhabricatorFileTransform
::
getTransformByKey
(
$xform_key
)
->
executeTransform
(
$file
)
;
// Make that image transformation non-orphan.
id
(
new
PhabricatorTransformedFile
(
)
)
->
setOriginalPHID
(
$file_phid
)
->
setTransformedPHID
(
$xform
->
getPHID
(
)
)
->
setTransform
(
$xform_key
)
->
save
(
)
;
$object
->
setProperty
(
'cover.filePHID'
,
$file
->
getPHID
(
)
)
;
$object
->
setProperty
(
'cover.thumbnailPHID'
,
$xform
->
getPHID
(
)
)
;
}
public
function
applyExternalEffects
(
$object
,
$value
)
{
// If the File has a Cover Image, attach that as side-effect.
// Otherwise, the Cover Image may be invisible to participants.
$file_phid
=
$object
->
getProperty
(
'cover.filePHID'
)
;
if
(
$file_phid
)
{
PhabricatorFile
::
attachFileToObject
(
$file_phid
,
$object
->
getPHID
(
)
)
;
}
}
public
function
getTitle
(
)
{
$old
=
$this
->
getOldValue
(
)
;
$new
=
$this
->
getNewValue
(
)
;
if
(
$old
===
null
)
{
return
pht
(
'%s set the cover image to %s.'
,
$this
->
renderAuthor
(
)
,
$this
->
renderHandle
(
$new
)
)
;
}
return
pht
(
'%s updated the cover image to %s.'
,
$this
->
renderAuthor
(
)
,
$this
->
renderHandle
(
$new
)
)
;
}
public
function
getTitleForFeed
(
)
{
$old
=
$this
->
getOldValue
(
)
;
if
(
$old
===
null
)
{
return
pht
(
'%s added a cover image to %s.'
,
$this
->
renderAuthor
(
)
,
$this
->
renderObject
(
)
)
;
}
return
pht
(
'%s updated the cover image for %s.'
,
$this
->
renderAuthor
(
)
,
$this
->
renderObject
(
)
)
;
}
public
function
validateTransactions
(
$object
,
array
$xactions
)
{
$errors
=
array
(
)
;
$viewer
=
$this
->
getActor
(
)
;
foreach
(
$xactions
as
$xaction
)
{
$file_phid
=
$xaction
->
getNewValue
(
)
;
$file
=
id
(
new
PhabricatorFileQuery
(
)
)
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$file_phid
)
)
->
executeOne
(
)
;
if
(
!
$file
)
{
$errors
[
]
=
$this
->
newInvalidError
(
pht
(
'File PHID ("%s") is invalid, or you do not have permission '
.
'to view it.'
,
$file_phid
)
,
$xaction
)
;
continue
;
}
if
(
!
$file
->
isViewableImage
(
)
)
{
$errors
[
]
=
$this
->
newInvalidError
(
pht
(
'File ("%s", with MIME type "%s") is not a viewable image file.'
,
$file_phid
,
$file
->
getMimeType
(
)
)
,
$xaction
)
;
continue
;
}
if
(
!
$file
->
isTransformableImage
(
)
)
{
$errors
[
]
=
$this
->
newInvalidError
(
pht
(
'File ("%s", with MIME type "%s") can not be transformed into '
.
'a thumbnail. You may be missing support for this file type in '
.
'the "GD" extension.'
,
$file_phid
,
$file
->
getMimeType
(
)
)
,
$xaction
)
;
continue
;
}
}
return
$errors
;
}
public
function
getIcon
(
)
{
return
'fa-image'
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 15:12 (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1125855
Default Alt Text
ManiphestTaskCoverImageTransaction.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment