| 1 | package DBIx::Class::ElasticSync::Role::ElasticResult; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | =head2 | ||||||||||||||
| 9 | |||||||||||||||
| 10 | dispatches the Result, builds the needed DBIC ResultSet and gives it to the Indexing function | ||||||||||||||
| 11 | |||||||||||||||
| 12 | =cut | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 0 | ▶ | sub es_index { | ||||||||||||
|
Subroutine
es_index: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 0 | my $self = shift; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | my $schema = $self->result_source->schema; | |||||||||||||
| 19 | 0 | my $class = $self->result_source->source_name; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | my $elastic_rs = $schema->dispatcher->{$class}; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | for my $rs (@$elastic_rs) { | |||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | ▶ | next unless $self->schema->es_is_registered_rs($rs); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | eval "use $rs"; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | die $@ if $@; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | |||||||||||||||
| 31 | 0 | my $obj = $self->es_obj_builder($rs); | |||||||||||||
| 32 | 0 | my $dbic_rs = $self->es_dbic_builder( $rs, $obj ); | |||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | $rs->es_index($dbic_rs); | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | =head2 es_obj_builder | ||||||||||||||
| 39 | |||||||||||||||
| 40 | Reloads the Object from the Database to get a clean Row Object | ||||||||||||||
| 41 | |||||||||||||||
| 42 | =cut | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 0 | ▶ | sub es_obj_builder { | ||||||||||||
|
Subroutine
es_obj_builder: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 45 | |||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||
| 47 | 0 | my $rs = shift; | |||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | my $class = $self->result_source->source_name; | |||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | my $obj = $self; | |||||||||||||
| 52 | |||||||||||||||
| 53 | # Reload from db | ||||||||||||||
| 54 | 0 | $obj->discard_changes; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 0 | return $obj; | |||||||||||||
| 57 | |||||||||||||||
| 58 | } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =head2 es_dbic_builder | ||||||||||||||
| 61 | |||||||||||||||
| 62 | Builds the Resultset for Indexing | ||||||||||||||
| 63 | |||||||||||||||
| 64 | =cut | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | ▶ | sub es_dbic_builder { | ||||||||||||
|
Subroutine
es_dbic_builder: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | my $self = shift; | |||||||||||||
| 69 | 0 | my $rs = shift; | |||||||||||||
| 70 | 0 | my $obj = shift; | |||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | my $dbic_rs = $rs->index_rs; | |||||||||||||
| 73 | 0 | my $me = $dbic_rs->current_source_alias; | |||||||||||||
| 74 | 0 | my $dbic_params = { map { $me . "." . $_ => $obj->$_ } $obj->result_source->primary_columns }; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | $dbic_rs = $dbic_rs->search_rs($dbic_params); | |||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | return $dbic_rs; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head2 es_delete | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Dispatches and give the DBIC Resultset to the delete function | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =cut | ||||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | ▶ | sub es_delete { | ||||||||||||
|
Subroutine
es_delete: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||
| 88 | |||||||||||||||
| 89 | 0 | my ( $self, $orig ) = @_; | |||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | my $schema = $self->result_source->schema; | |||||||||||||
| 92 | 0 | my $class = $self->result_source->source_name; | |||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | my $elastic_rs = $schema->dispatcher->{$class}; | |||||||||||||
| 95 | |||||||||||||||
| 96 | 0 | my $is_primary = 0; | |||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | for my $rs (@$elastic_rs) { | |||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | eval "use $rs"; | |||||||||||||
| 101 | |||||||||||||||
| 102 | 0 | ▶ | die $@ if $@; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | my $obj = $self->es_obj_builder($rs); | |||||||||||||
| 105 | 0 | my $dbic_rs = $self->es_dbic_builder( $rs, $obj ); | |||||||||||||
| 106 | |||||||||||||||
| 107 | 0 | ▶ | if ( $rs->es_is_primary($class) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | $rs->es_delete($dbic_rs); | |||||||||||||
| 110 | 0 | $is_primary = 1; | |||||||||||||
| 111 | |||||||||||||||
| 112 | } elsif ( $rs->es_is_nested($class) ) { | ||||||||||||||
| 113 | |||||||||||||||
| 114 | 0 | ▶ | $self->$orig if $self->in_storage; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | 0 | $rs->es_index($dbic_rs); | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | } | ||||||||||||||
| 118 | |||||||||||||||
| 119 | 0 | ▶ | $self->$orig if $is_primary; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 120 | } | ||||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | ▶ | after 'insert' => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||
| 124 | |||||||||||||||
| 125 | 0 | warn "Inserting ...\n"; | |||||||||||||
| 126 | 0 | $self->es_index; | |||||||||||||
| 127 | 1 | }; | |||||||||||||
| 128 | |||||||||||||||
| 129 | 0 | ▶ | after 'update' => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | warn "Updating ...\n"; | |||||||||||||
| 133 | 0 | $self->es_index; | |||||||||||||
| 134 | 1 | }; | |||||||||||||
| 135 | |||||||||||||||
| 136 | 0 | ▶ | around 'delete' => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 137 | 0 | my $orig = shift; | |||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||
| 139 | |||||||||||||||
| 140 | 0 | warn "Deleting...\n"; | |||||||||||||
| 141 | 0 | $self->es_delete($orig); | |||||||||||||
| 142 | 1 | }; | |||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | ▶ | sub es_index_transfer { | ||||||||||||
|
Subroutine
es_index_transfer: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 145 | |||||||||||||||
| 146 | 0 | my ( $self, $body ) = @_; | |||||||||||||
| 147 | |||||||||||||||
| 148 | 0 | my $type = $self->result_source->name; | |||||||||||||
| 149 | |||||||||||||||
| 150 | 0 | my $parent = {}; | |||||||||||||
| 151 | 0 | ▶ | if ( $self->es_is_child ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 152 | |||||||||||||||
| 153 | 0 | $parent = { parent => $self->es_parent }; | |||||||||||||
| 154 | } | ||||||||||||||
| 155 | |||||||||||||||
| 156 | } | ||||||||||||||
| 157 | |||||||||||||||
| 158 | 0 | ▶ | sub schema { | ||||||||||||
|
Subroutine
schema: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 159 | |||||||||||||||
| 160 | 0 | return shift->result_source->schema; | |||||||||||||
| 161 | } | ||||||||||||||
| 162 | |||||||||||||||
| 163 | 0 | ▶ | sub es { | ||||||||||||
|
Subroutine
es: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 164 | |||||||||||||||
| 165 | 0 | return shift->schema->es; | |||||||||||||
| 166 | } | ||||||||||||||
| 167 | |||||||||||||||
| 168 | 1 | 1; | |||||||||||||