Ignore:
Timestamp:
02/19/19 19:43:10 (5 years ago)
Author:
nanardon
Message:

Track parent object in SQL log

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r2194 r2204  
    1818our $VERSION = (q$Rev: 2149 $ =~ /^Rev: (\d+) /)[0]; 
    1919 
    20 sub SCHEMA_VERSION { 28 }; 
     20sub SCHEMA_VERSION { 29 }; 
    2121 
    2222=head1 NAME 
     
    154154        # return; 
    155155    } 
    156     $self->_CreateInternalObjects; 
     156    if (!$self->_CreateInternalObjects) { 
     157        $self->rollback; 
     158    } 
    157159 
    158160    1; 
     
    214216    if ($change > 0) { 
    215217        $self->db->commit; 
    216     } else { 
    217        $self->db->rollback; 
    218     } 
    219  
    220     return 1; 
     218    } 
     219 
     220    return $change; 
    221221} 
    222222 
     
    10921092    ); 
    10931093 
     1094    my ($potype, $pname, $pikey); 
     1095 
     1096    if (my $obj = $self->get_object($otype, $name)) { 
     1097        my $parent = $obj->ParentObject; 
     1098        $potype = $parent->type; 
     1099        $pname  = $parent->name; 
     1100        $pikey  = $parent->Iid;  
     1101    } 
     1102 
    10941103    my $sth = $self->db->prepare(q{ 
    1095         INSERT into objectslogs (ikey, irev, otype, name, changetype, username, message) 
    1096         VALUES (?,?,?,?,?,?,?) 
     1104        INSERT into objectslogs (ikey, irev, otype, name, changetype, username, message, parentotype, parentname, parentikey) 
     1105        VALUES (?,?,?,?,?,?,?,?,?,?) 
    10971106        }); 
    10981107 
     
    11051114        $self->user || '@Console', 
    11061115        sprintf($message, @args), 
     1116        $potype, $pname, $pikey, 
    11071117    ); 
    11081118} 
     
    11191129    my $sth = $self->db->prepare(q{ 
    11201130        select ikey from objectslogs where 
    1121             otype = ? and 
    1122             name  = ? 
     1131            (otype = $1 and name  = $2)  
    11231132        group by ikey 
    11241133    }); 
     
    11301139    @ids or return; 
    11311140 
    1132     my $sth2 = $self->db->prepare(sprintf( 
     1141    my $sth2 = $self->db->prepare( 
    11331142        q{ 
    1134             select * from objectslogs where ikey IN (%s) 
     1143            select * from objectslogs where ikey = ANY ($1) 
     1144                or parentikey = ANY ($1) 
    11351145            order by logdate asc 
    11361146        }, 
    1137         join(',', ('?') x scalar(@ids)) 
    1138     )); 
    1139  
    1140     $sth2->execute(@ids); 
     1147    ); 
     1148 
     1149    $sth2->execute( \@ids ); 
    11411150    my @logs; 
    11421151    while (my $res = $sth2->fetchrow_hashref) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Address.pm

    r2078 r2204  
    337337} 
    338338 
     339sub ParentObject { 
     340    my ($self) = @_; 
     341 
     342    return $self->base->get_object('user', $self->_get_attributes('user')); 
     343} 
     344 
    339345sub _create { 
    340346    my ($class, $base, $id, %data) = @_; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm

    r2147 r2204  
    316316    } 
    317317    $class->SUPER::_get_attr_schema($base, $attrs); 
     318} 
     319 
     320sub ParentObject { 
     321    my ($self) = @_; 
     322 
     323    return $self->base->get_object('user', $self->_get_attributes('user')); 
    318324} 
    319325 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r2196 r2204  
    306306 
    307307sub Iid { $_[0]->_get_ikey } 
     308 
     309sub ParentObject { } 
    308310 
    309311sub _get_ikey { 
     
    14171419} 
    14181420 
     1421sub ReportChange { 
     1422    my ($self, $changetype, $message, @args) = @_; 
     1423 
     1424    $self->base->ReportChange( 
     1425        $self->type, 
     1426        $self->id, 
     1427        $self->Iid, 
     1428        $changetype, $message, @args 
     1429    ) 
     1430} 
     1431 
     1432 
    141914331; 
    14201434 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm

    r2175 r2204  
    11611161                } 
    11621162            ] 
     1163        }, 
     1164        { 
     1165            ver => 29, 
     1166            sql => [ 
     1167                q{ 
     1168                ALTER TABLE objectslogs 
     1169                   ADD COLUMN parentotype text; 
     1170                ALTER TABLE objectslogs 
     1171                   ADD COLUMN parentname text; 
     1172                ALTER TABLE objectslogs 
     1173                   ADD COLUMN parentikey bigint; 
     1174                CREATE INDEX objectslogs_parentotype_idx 
     1175                    ON public.objectslogs 
     1176                    USING btree (parentotype); 
     1177                CREATE INDEX objectslogs_parentname_idx 
     1178                    ON objectslogs 
     1179                    USING btree (parentname); 
     1180                CREATE INDEX objectslogs_parentikey_idx 
     1181                    ON objectslogs 
     1182                    USING btree (parentikey); 
     1183                } 
     1184            ], 
    11631185        }, 
    11641186    ); 
     
    12241246    ); 
    12251247 
     1248    return 1; 
    12261249} 
    12271250 
Note: See TracChangeset for help on using the changeset viewer.