mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 03:32:49 +08:00
WIP IP Logging
This commit is contained in:
parent
5e2f659f54
commit
49fddbd450
30
migrations/2015_10_24_194000_add_ip_to_posts.php
Normal file
30
migrations/2015_10_24_194000_add_ip_to_posts.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
namespace Flarum\Migrations\Core;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Flarum\Database\AbstractMigration;
|
||||
|
||||
class AddIpToPosts extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->schema->table('posts', function (Blueprint $table) {
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->schema->table('posts', function (Blueprint $table) {
|
||||
$table->dropColumn(['ip_address']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -54,9 +54,10 @@ class CreatePostController extends AbstractCreateController
|
|||
$actor = $request->getAttribute('actor');
|
||||
$data = array_get($request->getParsedBody(), 'data');
|
||||
$discussionId = array_get($data, 'relationships.discussion.data.id');
|
||||
$ipAddress = array_get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
|
||||
|
||||
$post = $this->bus->dispatch(
|
||||
new PostReply($discussionId, $actor, $data)
|
||||
new PostReply($discussionId, $actor, $data, $ipAddress)
|
||||
);
|
||||
|
||||
// After replying, we assume that the user has seen all of the posts
|
||||
|
|
|
@ -35,15 +35,24 @@ class PostReply
|
|||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* The IP address of the actor.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* @param int $discussionId The ID of the discussion to post the reply to.
|
||||
* @param User $actor The user who is performing the action.
|
||||
* @param array $data The attributes to assign to the new post.
|
||||
* @param string $ipAddress The IP address of the actor.
|
||||
*/
|
||||
public function __construct($discussionId, User $actor, array $data)
|
||||
public function __construct($discussionId, User $actor, array $data, $ipAddress)
|
||||
{
|
||||
$this->discussionId = $discussionId;
|
||||
$this->actor = $actor;
|
||||
$this->data = $data;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,8 @@ class PostReplyHandler
|
|||
$post = CommentPost::reply(
|
||||
$discussion->id,
|
||||
array_get($command->data, 'attributes.content'),
|
||||
$actor->id
|
||||
$actor->id,
|
||||
$command->ipAddress
|
||||
);
|
||||
|
||||
$this->events->fire(
|
||||
|
|
|
@ -45,9 +45,10 @@ class CommentPost extends Post
|
|||
* @param int $discussionId
|
||||
* @param string $content
|
||||
* @param int $userId
|
||||
* @param string $ipAddress
|
||||
* @return static
|
||||
*/
|
||||
public static function reply($discussionId, $content, $userId)
|
||||
public static function reply($discussionId, $content, $userId, $ipAddress)
|
||||
{
|
||||
$post = new static;
|
||||
|
||||
|
@ -55,6 +56,7 @@ class CommentPost extends Post
|
|||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
$post->type = static::$type;
|
||||
$post->ip_address = $ipAddress;
|
||||
|
||||
// Set content last, as the parsing may rely on other post attributes.
|
||||
$post->content = $content;
|
||||
|
|
Loading…
Reference in New Issue
Block a user