Example #1
0
 protected function updateLast($comment, $oldRevisionId, $newRevisionId, $diffFieldName, $entity, CommentInterface $lastComment)
 {
     // If there is a new revision of the host entity, update it on the comment
     if (!empty($newRevisionId)) {
         // If the last comment did not store changes, store the current revisions pair
         if (empty($lastComment->{$diffFieldName}->right_rid)) {
             $lastComment->{$diffFieldName}->setValue([['left_rid' => $oldRevisionId, 'right_rid' => $newRevisionId]]);
         } else {
             $changes = $lastComment->{$diffFieldName}->getValue();
             $changes[0]['right_rid'] = $newRevisionId;
             $lastComment->{$diffFieldName}->setValue($changes);
         }
     }
     // Overwrite the old subject only if it was a change record.
     if ($lastComment->subject->value === 'Change Record') {
         $lastComment->setSubject($comment['subject']);
     }
     // Set all fields for which data has been passed
     // and there is no saved value
     foreach ($comment as $name => $value) {
         if (!isset($lastComment->{$name}->value)) {
             if (is_array($value)) {
                 $lastComment->{$name}->setValue($value);
             } else {
                 $lastComment->{$name}->value = $value;
             }
         }
     }
     $lastComment->setChangedTime(REQUEST_TIME);
     $lastComment->save();
 }