1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Isswp101\Persimmon; |
4
|
|
|
|
5
|
|
|
use Elasticsearch\Client; |
6
|
|
|
use Isswp101\Persimmon\Collection\ElasticsearchCollection; |
7
|
|
|
use Isswp101\Persimmon\DAL\ElasticsearchDAL; |
8
|
|
|
use Isswp101\Persimmon\Traits\Elasticsearchable; |
9
|
|
|
use Isswp101\Persimmon\Traits\Mappingable; |
10
|
|
|
use Isswp101\Persimmon\Traits\Relationshipable; |
11
|
|
|
|
12
|
|
|
class ElasticsearchModel extends Model |
13
|
|
|
{ |
14
|
|
|
use Elasticsearchable, Mappingable, Relationshipable; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var ElasticsearchDAL |
18
|
|
|
*/ |
19
|
|
|
public $_dal; |
20
|
|
|
|
21
|
|
|
public function __construct(array $attributes = []) |
22
|
|
|
{ |
23
|
|
|
$this->validateIndexAndType(); |
24
|
|
|
|
25
|
|
|
parent::__construct($attributes); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function injectDependencies() |
29
|
|
|
{ |
30
|
|
|
// @TODO: move logger to DAL |
31
|
|
|
$this->injectDataAccessLayer(new ElasticsearchDAL($this, app(Client::class))); |
32
|
|
|
// $this->injectLogger(app(Log::class)); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function findWithParentId($id, $parentId, array $columns = ['*']) |
36
|
|
|
{ |
37
|
|
|
/** @var static $model */ |
38
|
|
|
$model = parent::find($id, $columns, ['parent_id' => $parentId]); |
|
|
|
|
39
|
|
|
|
40
|
|
|
if ($model) { |
41
|
|
|
$model->setParentId($parentId); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $model; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $query |
49
|
|
|
* @return ElasticsearchCollection|static[] |
50
|
|
|
*/ |
51
|
|
|
public static function search($query = []) |
52
|
|
|
{ |
53
|
|
|
$model = static::createInstance(); |
54
|
|
|
|
55
|
|
|
return $model->_dal->search($query); |
56
|
|
|
} |
57
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.