Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ModerationLoggingListener | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onAfterInsert | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| log | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Data\Listener; |
| 4 | |
| 5 | use Flow\Log\ModerationLogger; |
| 6 | use Flow\Model\PostRevision; |
| 7 | use Flow\Model\Workflow; |
| 8 | |
| 9 | class ModerationLoggingListener extends AbstractListener { |
| 10 | |
| 11 | /** |
| 12 | * @var ModerationLogger |
| 13 | */ |
| 14 | protected $moderationLogger; |
| 15 | |
| 16 | public function __construct( ModerationLogger $moderationLogger ) { |
| 17 | $this->moderationLogger = $moderationLogger; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @param PostRevision $object |
| 22 | * @param array $row |
| 23 | * @param array $metadata (must contain 'workflow' key with a Workflow object) |
| 24 | */ |
| 25 | public function onAfterInsert( $object, array $row, array $metadata ) { |
| 26 | if ( $object instanceof PostRevision ) { |
| 27 | $this->log( $object, $metadata['workflow'] ); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | protected function log( PostRevision $post, Workflow $workflow ) { |
| 32 | if ( !$post->isModerationChange() ) { |
| 33 | // Do nothing for non-moderation actions |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | if ( $this->moderationLogger->canLog( $post, $post->getChangeType() ) ) { |
| 38 | $workflowId = $workflow->getId(); |
| 39 | |
| 40 | $this->moderationLogger->log( |
| 41 | $post, |
| 42 | $post->getChangeType(), |
| 43 | $post->getModeratedReason(), |
| 44 | $workflowId |
| 45 | ); |
| 46 | } |
| 47 | } |
| 48 | } |