Issue #2687977 by claudiu.cristea, alexpott, prics: Comment::preSave() unconditionally sets hostname to client host
parent
fed0b7d7b0
commit
012bca1943
|
@ -151,9 +151,11 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
if ($this->getOwnerId() === \Drupal::currentUser()->id() && \Drupal::currentUser()->isAuthenticated()) {
|
||||
$this->setAuthorName(\Drupal::currentUser()->getUsername());
|
||||
}
|
||||
// Add the values which aren't passed into the function.
|
||||
$this->setThread($thread);
|
||||
$this->setHostname(\Drupal::request()->getClientIP());
|
||||
if (!$this->getHostname()) {
|
||||
// Ensure a client host from the current request.
|
||||
$this->setHostname(\Drupal::request()->getClientIP());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,14 +61,17 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
|||
$this->assertIdentical('node', $comment->getCommentedEntityTypeId());
|
||||
$this->assertIdentical('en', $comment->language()->getId());
|
||||
$this->assertIdentical('comment_no_subject', $comment->getTypeId());
|
||||
$this->assertEquals('203.0.113.1', $comment->getHostname());
|
||||
|
||||
$comment = $comment_storage->load(2);
|
||||
$this->assertIdentical('The response to the second comment.', $comment->subject->value);
|
||||
$this->assertIdentical('3', $comment->pid->target_id);
|
||||
$this->assertEquals('203.0.113.2', $comment->getHostname());
|
||||
|
||||
$comment = $comment_storage->load(3);
|
||||
$this->assertIdentical('The second comment.', $comment->subject->value);
|
||||
$this->assertIdentical(NULL, $comment->pid->target_id);
|
||||
$this->assertEquals('203.0.113.3', $comment->getHostname());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
|||
$this->assertIdentical('admin@local.host', $comment->getAuthorEmail());
|
||||
$this->assertIdentical('This is a comment', $comment->comment_body->value);
|
||||
$this->assertIdentical('filtered_html', $comment->comment_body->format);
|
||||
$this->assertEquals('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertTrue($node instanceof NodeInterface);
|
||||
|
|
|
@ -1772,7 +1772,7 @@ $connection->insert('comments')
|
|||
'uid' => '0',
|
||||
'subject' => 'The first comment.',
|
||||
'comment' => 'The first comment body.',
|
||||
'hostname' => '127.0.0.1',
|
||||
'hostname' => '203.0.113.1',
|
||||
'timestamp' => '1390264918',
|
||||
'status' => '0',
|
||||
'format' => '1',
|
||||
|
@ -1788,7 +1788,7 @@ $connection->insert('comments')
|
|||
'uid' => '0',
|
||||
'subject' => 'The response to the second comment.',
|
||||
'comment' => 'The second comment response body.',
|
||||
'hostname' => '127.0.0.1',
|
||||
'hostname' => '203.0.113.2',
|
||||
'timestamp' => '1390264938',
|
||||
'status' => '0',
|
||||
'format' => '1',
|
||||
|
@ -1804,7 +1804,7 @@ $connection->insert('comments')
|
|||
'uid' => '0',
|
||||
'subject' => 'The second comment.',
|
||||
'comment' => 'The second comment body.',
|
||||
'hostname' => '127.0.0.1',
|
||||
'hostname' => '203.0.113.3',
|
||||
'timestamp' => '1390264948',
|
||||
'status' => '1',
|
||||
'format' => '1',
|
||||
|
|
|
@ -2512,7 +2512,7 @@ $connection->insert('comment')
|
|||
'nid' => '1',
|
||||
'uid' => '1',
|
||||
'subject' => 'A comment',
|
||||
'hostname' => '::1',
|
||||
'hostname' => '2001:db8:ffff:ffff:ffff:ffff:ffff:ffff',
|
||||
'created' => '1421727536',
|
||||
'changed' => '1421727536',
|
||||
'status' => '1',
|
||||
|
|
Loading…
Reference in New Issue