Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Bump versions #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ The `drivers` key of the config file should look like so:
]
],
'index' => env('AUDIT_INDEX', 'laravel_auditing'),
'type' => env('AUDIT_TYPE', 'audits')
],
],
...
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
{
"packagist.org": false,
"type": "vcs",
"url": "https://github.com/rankarpan/laravel-auditing"
"url": "https://github.com/owen-it/laravel-auditing"
}
],
"license": "MIT",
"support": {
"issues": "https://github.com/iconscout/laravel-auditing-elasticsearch/issues",
"source": "https://github.com/iconscout/laravel-auditing-elasticsearch"
"issues": "https://github.com/kirschbaum-development/laravel-auditing-elasticsearch/issues",
"source": "https://github.com/kirschbaum-development/laravel-auditing-elasticsearch"
},
"authors": [
{
"name": "Arpan Rank",
"email": "arpan@iconscout.com"
"name": "Kirschbaum Development",
"email": "wilker@kirschbaumdevelopment.com"
}
],
"require": {
"php": ">=7.0",
"owen-it/laravel-auditing": "dev-master",
"elasticsearch/elasticsearch": "6.*"
"php": "^8.2",
"owen-it/laravel-auditing": "^13.6",
"elasticsearch/elasticsearch": "^8.0"
},
"autoload": {
"psr-4": {
Expand Down
152 changes: 68 additions & 84 deletions src/Drivers/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Iconscout\Auditing\Drivers;

use Carbon\Carbon;
use Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\ClientBuilder;
use Illuminate\Support\Facades\Config;
use Iconscout\Auditing\Jobs\AuditIndexQueuedModels;
use Iconscout\Auditing\Jobs\AuditDeleteQueuedModels;
Expand All @@ -36,19 +36,13 @@ class ElasticSearch implements AuditDriver
*/
protected $index = null;

/**
* @var string
*/
protected $type = null;

/**
* ElasticSearch constructor.
*/
public function __construct()
{
$this->client = ClientBuilder::create()->setHosts(Config::get('audit.drivers.es.client.hosts', ['localhost:9200']))->build();
$this->index = Config::get('audit.drivers.es.index', 'laravel_auditing');
$this->type = Config::get('audit.drivers.es.type', 'audits');
}

/**
Expand All @@ -60,10 +54,11 @@ public function __construct()
*/
public function audit(Auditable $model): Audit
{

$implementation = Config::get('audit.implementation', AuditModel::class);

$this->storeAudit($model->toAudit());

return new $implementation;
}

Expand All @@ -90,15 +85,15 @@ public function storeAudit($model)
if (Config::get('audit.queue', false)) {
return $this->indexQueueAuditDocument($model);
}

return $this->indexAuditDocument($model);
}

public function indexQueueAuditDocument($model)
{
dispatch((new AuditIndexQueuedModels($model))
->onQueue($this->syncWithSearchUsingQueue())
->onConnection($this->syncWithSearchUsing()));
->onQueue($this->syncWithSearchUsingQueue())
->onConnection($this->syncWithSearchUsing()));

return true;
}
Expand All @@ -108,15 +103,15 @@ public function destroyAudit($model)
if (Config::get('audit.queue', false)) {
return $this->deleteQueueAuditDocument($model);
}

return $this->deleteAuditDocument($model);
}

public function deleteQueueAuditDocument($model)
{
dispatch((new AuditDeleteQueuedModels($model))
->onQueue($this->syncWithSearchUsingQueue())
->onConnection($this->syncWithSearchUsing()));
->onQueue($this->syncWithSearchUsingQueue())
->onConnection($this->syncWithSearchUsing()));

return true;
}
Expand Down Expand Up @@ -145,14 +140,14 @@ public function indexAuditDocument($model)
{
$params = [
'index' => $this->index,
'type' => $this->type,
'id' => Uuid::uuid4(),
'id' => (string) Uuid::uuid4(),
'body' => $model
];

try {
return $this->client->index($params);
} catch (\Exception $e) {}
} catch (\Exception $e) {
}
}

public function searchAuditDocument($model)
Expand All @@ -161,7 +156,6 @@ public function searchAuditDocument($model)

$params = [
'index' => $this->index,
'type' => $this->type,
'size' => 10000 - $skip,
'from' => $skip,
'body' => [
Expand Down Expand Up @@ -199,18 +193,16 @@ public function deleteAuditDocument($model)

if (count($audits)) {
$audit_ids = array_column($audits, '_id');

foreach ($audit_ids as $audit_id) {
$params['body'][] = [
'delete' => [
'_index' => $this->index,
'_type' => $this->type,
'_id' => $audit_id
]
];

}

return (bool) $this->client->bulk($params);
}

Expand Down Expand Up @@ -239,7 +231,7 @@ public function updateAliases()
[
'add' => [
'index' => $this->index,
'alias' => $this->index.'_write'
'alias' => $this->index . '_write'
]
]
]
Expand All @@ -254,7 +246,7 @@ public function deleteIndex()
'index' => $this->index
];

return $this->client->indices()->delete($deleteParams);
return $this->client->indices()->delete($deleteParams)->asBool();
}

public function existsIndex()
Expand All @@ -263,74 +255,66 @@ public function existsIndex()
'index' => $this->index
];

return $this->client->indices()->exists($params);
return $this->client->indices()->exists($params)->asBool();
}

public function putMapping()
{
$params = [
'index' => $this->index,
'type' => $this->type,
'body' => [
$this->type => [
'_source' => [
'enabled' => true
'_source' => [
'enabled' => true
],
'properties' => [
'event' => [
'type' => 'keyword'
],
'properties' => [
'event' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'auditable_type' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'ip_address' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'url' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'user_agent' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'new_values' => [
'properties' => [
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'updated_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'deleted_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
]
'auditable_type' => [
'type' => 'keyword'
],
'ip_address' => [
'type' => 'keyword'
],
'url' => [
'type' => 'keyword'
],
'user_agent' => [
'type' => 'keyword'
],
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'new_values' => [
'properties' => [
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'updated_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'deleted_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
]
],
'old_values' => [
'properties' => [
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'updated_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'deleted_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
]
]
],
'old_values' => [
'properties' => [
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'updated_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'deleted_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
]
]
]
Expand Down
8 changes: 3 additions & 5 deletions src/Traits/ElasticSearchAuditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Iconscout\Auditing\Traits;

use Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\ClientBuilder;
use Illuminate\Support\Facades\Config;
use Illuminate\Database\Eloquent\Collection;

Expand All @@ -23,14 +23,12 @@ public function esAudits($page = 1, $perPage = 10, $sort = 'latest')
{
$client = ClientBuilder::create()->setHosts(Config::get('audit.drivers.es.client.hosts', ['localhost:9200']))->build();
$index = Config::get('audit.drivers.es.index', 'laravel_auditing');
$type = Config::get('audit.drivers.es.type', 'audits');


$from = ($page - 1) * $perPage;
$order = $sort === 'latest' ? 'desc' : 'asc';

$params = [
'index' => $index,
'type' => $type,
'size' => $perPage,
'from' => $from,
'body' => [
Expand Down Expand Up @@ -83,4 +81,4 @@ public function getEsAuditsAttribute()
{
return $this->esAudits();
}
}
}
1 change: 0 additions & 1 deletion src/config/audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
]
],
'index' => env('AUDIT_INDEX', 'laravel_auditing'),
'type' => env('AUDIT_TYPE', 'audits')
]
],

Expand Down