Changeset 2611


Ignore:
Timestamp:
05/13/24 21:16:03 (2 weeks ago)
Author:
nanardon
Message:

Allow to use another attribute as key for sync

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts
Files:
6 edited

Legend:

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

    r2597 r2611  
    10991099        $data{$attrname} = $srcobj->GetAttributeValue($srcattrname); 
    11001100    } 
    1101     if (my $dstobj = $self->get_object($srcobj->type, $srcobj->id)) { 
     1101 
     1102    my $KeyAttribute = $self->config( 'keyAttribute.' . $srcobj->base->label . '.' . $srcobj->type  ); 
     1103 
     1104    my $destid = $options{ KeyAttribute } 
     1105        ? $srcobj->get_attibutes( $options{ KeyAttribute } ) 
     1106        : $srcobj->id; 
     1107    if (my $dstobj = $self->get_object($srcobj->type, $destid)) { 
    11021108        keys %data or return 'SYNCED'; 
    11031109        foreach (keys %data) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r2606 r2611  
    461461} 
    462462 
     463sub key_field { 
     464    my ( $self, $otype ) = @_; 
     465 
     466    my $pclass = $self->_load_obj_class($otype) or return; 
     467    return $pclass->_key_field; 
     468} 
     469 
    463470sub current_rev { 
    464471    my ($self) = @_; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r2601 r2611  
    162162            }, 
    163163            uidnumber => { inline => 1, hide => 1, monitored => 1 }, 
     164            partageid => { inline => 1, monitored => 1 }, 
    164165            gidNumber => { 
    165166                inline => 1, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r2607 r2611  
    5252} 
    5353 
     54# $keyAttribute must be a internal attribute 
     55 
    5456sub list_from_rev { 
    55     my ($class, $base, $rev) = @_; 
     57    my ($class, $base, $rev, $keyAttribute) = @_; 
     58    defined( $rev ) or die '$rev must be defined when calling list_from_rev()'; 
     59    $keyAttribute ||= $base->db->quote_identifier($class->_key_field); 
    5660    my $sth = $base->db->prepare_cached( 
    5761        sprintf( 
    58             q{select %s as k from %s where rev > ? and internobject = false 
    59                 and oalias IS NULL %s order by %s}, 
    60             $base->db->quote_identifier($class->_key_field), 
     62            q{select %s as k from %s where rev > ? AND internobject = false 
     63                AND oalias IS NULL AND %s IS NOT NULL %s order by %s}, 
     64            $keyAttribute, 
    6165            $base->db->quote_identifier($class->_object_table), 
     66            $keyAttribute, 
    6267            ($base->{wexported} ? '' : 'and exported = true'), 
    6368            $base->db->quote_identifier($class->_key_field), 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm

    r2541 r2611  
    15211521            recompute => 1, 
    15221522        }, 
     1523        { 
     1524            ver => 41, 
     1525            sql => [ 
     1526                q{ 
     1527                ALTER TABLE "user" ADD COLUMN partageid TEXT 
     1528                CREATE INDEX user_partageid_uniqidx 
     1529                ON partageid 
     1530                USING btree 
     1531                (value); 
     1532                } 
     1533            ], 
     1534        }, 
    15231535    ); 
    15241536 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r2436 r2611  
    283283            $destbase->is_supported_object($otype) or next; 
    284284 
     285            my $SyncKeyAttribute = $self->from->key_field( $otype ); 
     286            if ( my $attr = $destbase->config( 'keyAttribute.' . $self->from->label . '.' . $otype ) ) { 
     287                $SyncKeyAttribute = $attr; 
     288            } 
     289 
    285290            my %existings; 
    286291            my %filtering; 
    287292 
    288293            $existings{$otype} = { map { $_ => 1 } 
    289                 $self->from->listRealObjects($otype) }; 
     294                $self->from->list_objects_from_rev( $otype, 0, $SyncKeyAttribute ) }; 
    290295 
    291296            # Is there a filter to apply: 
     
    293298            if (my $filter = $self->{options}->{$filtername}) { 
    294299                la_log(LA_DEBUG, "Found %s param, using it: %s", $filtername, $filter); 
    295                 $filtering{$otype} = { map { $_ => 1 } 
    296                     $self->from->search_objects($otype, $filter, 'oalias=NULL') }; 
     300                    foreach ( my $id = $self->from->search_objects($otype, $filter, 'oalias=NULL') ) { 
     301                        my $obj = $self->from->get_object( $otype, $id ); 
     302                        my $id = $obj->get_attributes( $SyncKeyAttribute ); 
     303                        $filtering{$otype}{ $id } = 1; 
     304                    } 
    297305            } else { 
    298306                $filtering{$otype} = $existings{$otype}; 
     
    385393                    } 
    386394 
    387                     my $res = $destbase->sync_object_from($self->from, $otype, $_, 
    388                         %options, firstpass => $pass); 
     395                    my $res = $destbase->sync_object_from( 
     396                        $self->from, $otype, $_, 
     397                        %options, firstpass => $pass ); 
    389398                    if (defined $res) { 
    390399                        if ($res) { 
Note: See TracChangeset for help on using the changeset viewer.