| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::bif::log::identity; | 
| 2 | 1 |  |  | 1 |  | 8286 | use strict; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 50 |  | 
| 3 | 1 |  |  | 1 |  | 8 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 59 |  | 
| 4 | 1 |  |  | 1 |  | 7 | use locale; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 12 |  | 
| 5 | 1 |  |  | 1 |  | 47 | use Bif::Mo; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 13 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.1.5_6'; | 
| 8 |  |  |  |  |  |  | extends 'App::bif::log'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub run { | 
| 11 | 1 |  |  | 1 | 1 | 2 | my $self = shift; | 
| 12 | 1 |  |  |  |  | 5 | my $opts = $self->opts; | 
| 13 | 1 |  |  |  |  | 7 | my $db   = $self->db; | 
| 14 | 0 |  |  |  |  |  | my $info = $self->get_node( $opts->{id}, 'identity' ); | 
| 15 | 0 |  |  |  |  |  | my $now  = $self->now; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 0 |  |  |  |  |  | DBIx::ThinSQL->import(qw/concat case func qv/); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | my $sth = $db->xprepare( | 
| 20 |  |  |  |  |  |  | select => [ | 
| 21 |  |  |  |  |  |  | 'id.id AS id', | 
| 22 |  |  |  |  |  |  | concat( qv('.'),  'c.id' )->as('change_id'), | 
| 23 |  |  |  |  |  |  | concat( qv('.u'), 'c.uuid' )->as('change_uuid'), | 
| 24 |  |  |  |  |  |  | 'c.mtime AS mtime', | 
| 25 |  |  |  |  |  |  | 'c.mtimetz AS mtimetz', | 
| 26 |  |  |  |  |  |  | 'c.mtimetzhm AS mtimetzhm', | 
| 27 |  |  |  |  |  |  | "$now - c.mtime AS mtime_age", | 
| 28 |  |  |  |  |  |  | 'c.action AS action', | 
| 29 |  |  |  |  |  |  | 'COALESCE(c.author,i.name) AS author', | 
| 30 |  |  |  |  |  |  | "COALESCE(c.author_contact_method || ': ' || c.author_contact," | 
| 31 |  |  |  |  |  |  | . "ecm.method || ': ' || ecm.mvalue) AS contact", | 
| 32 |  |  |  |  |  |  | 'c.message AS message', | 
| 33 |  |  |  |  |  |  | 'c.ucount AS ucount', | 
| 34 |  |  |  |  |  |  | qv(undef)->as('name'), | 
| 35 |  |  |  |  |  |  | qv(undef)->as('method'), | 
| 36 |  |  |  |  |  |  | qv(undef)->as('mvalue'), | 
| 37 |  |  |  |  |  |  | 'c.path AS path', | 
| 38 |  |  |  |  |  |  | 'ct.depth AS depth', | 
| 39 |  |  |  |  |  |  | 'd.action AS delta', | 
| 40 |  |  |  |  |  |  | case ( | 
| 41 |  |  |  |  |  |  | when => 'd.action = "new_identity"', | 
| 42 |  |  |  |  |  |  | then => func( | 
| 43 |  |  |  |  |  |  | 'printf', ',', | 
| 44 |  |  |  |  |  |  | qv( | 
| 45 |  |  |  |  |  |  | "new_identity:\n" . "  name: %s\n" . "  shortname: %s" | 
| 46 |  |  |  |  |  |  | ), | 
| 47 |  |  |  |  |  |  | 'ed.name', | 
| 48 |  |  |  |  |  |  | 'id.shortname' | 
| 49 |  |  |  |  |  |  | ), | 
| 50 |  |  |  |  |  |  | when => 'd.action = "new_identity_contact_method"', | 
| 51 |  |  |  |  |  |  | then => func( | 
| 52 |  |  |  |  |  |  | 'printf', ',', | 
| 53 |  |  |  |  |  |  | qv( | 
| 54 |  |  |  |  |  |  | "new_identity_contact_method:\n" | 
| 55 |  |  |  |  |  |  | . "  method: %s\n" | 
| 56 |  |  |  |  |  |  | . "  mvalue: %s" | 
| 57 |  |  |  |  |  |  | ), | 
| 58 |  |  |  |  |  |  | 'ecmd.method', | 
| 59 |  |  |  |  |  |  | 'ecmd.mvalue' | 
| 60 |  |  |  |  |  |  | ), | 
| 61 |  |  |  |  |  |  | when => 'd.action = "update_identity"', | 
| 62 |  |  |  |  |  |  | then => func( | 
| 63 |  |  |  |  |  |  | 'printf', ',', | 
| 64 |  |  |  |  |  |  | qv( | 
| 65 |  |  |  |  |  |  | "update_identity:\n" | 
| 66 |  |  |  |  |  |  | . "  default_contact_method: %s\n" | 
| 67 |  |  |  |  |  |  | . "  name: %s\n" | 
| 68 |  |  |  |  |  |  | . "  shortname: %s" | 
| 69 |  |  |  |  |  |  | ), | 
| 70 |  |  |  |  |  |  | 'ecm2.mvalue', | 
| 71 |  |  |  |  |  |  | 'ed.name', | 
| 72 |  |  |  |  |  |  | 'id.shortname' | 
| 73 |  |  |  |  |  |  | ), | 
| 74 |  |  |  |  |  |  | else => qv('*unknown*'), | 
| 75 |  |  |  |  |  |  | )->as('delta_value'), | 
| 76 |  |  |  |  |  |  | ], | 
| 77 |  |  |  |  |  |  | from       => 'nodes n', | 
| 78 |  |  |  |  |  |  | inner_join => 'changes_tree ct', | 
| 79 |  |  |  |  |  |  | on         => 'ct.parent = n.first_change_id', | 
| 80 |  |  |  |  |  |  | inner_join => 'changes c', | 
| 81 |  |  |  |  |  |  | on         => 'c.id = ct.child', | 
| 82 |  |  |  |  |  |  | inner_join => 'entities i', | 
| 83 |  |  |  |  |  |  | on         => 'i.id = c.identity_id', | 
| 84 |  |  |  |  |  |  | inner_join => 'entity_contact_methods ecm', | 
| 85 |  |  |  |  |  |  | on         => 'ecm.id = i.default_contact_method_id', | 
| 86 |  |  |  |  |  |  | left_join  => 'deltas d', | 
| 87 |  |  |  |  |  |  | on         => 'd.change_id = c.id', | 
| 88 |  |  |  |  |  |  | left_join  => 'entity_deltas ed', | 
| 89 |  |  |  |  |  |  | on         => 'ed.id = d.id', | 
| 90 |  |  |  |  |  |  | left_join  => 'identity_deltas id', | 
| 91 |  |  |  |  |  |  | on         => 'id.id = d.id', | 
| 92 |  |  |  |  |  |  | left_join  => 'entity_contact_method_deltas ecmd', | 
| 93 |  |  |  |  |  |  | on         => 'ecmd.id = d.id', | 
| 94 |  |  |  |  |  |  | left_join  => 'entity_contact_methods ecm2', | 
| 95 |  |  |  |  |  |  | on         => 'ecm2.id = ed.default_contact_method_id', | 
| 96 |  |  |  |  |  |  | where      => { 'n.id' => $info->{id} }, | 
| 97 | 0 |  |  |  |  |  | order_by   => 'c.path,d.id', | 
| 98 |  |  |  |  |  |  | ); | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 0 |  |  |  |  |  | $sth->execute; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 0 |  |  |  |  |  | $self->start_pager; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 0 |  |  |  |  |  | $self->log_start; | 
| 105 | 0 |  |  |  |  |  | $self->log_next($_) for $sth->hashrefs; | 
| 106 | 0 |  |  |  |  |  | $self->log_next;    # finalize output | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 0 |  |  |  |  |  | return $self->ok('LogIdentity'); | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | 1; | 
| 112 |  |  |  |  |  |  | __END__ |