Ignore:
Timestamp:
09/19/17 16:15:20 (7 years ago)
Author:
nanardon
Message:

Make differences between view and table for attributes

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql
Files:
4 edited

Legend:

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

    r2054 r2090  
    1919 
    2020sub _object_table { 'nethost' } 
     21 
     22sub _object_table_attributes_read { 'nethost_attributes_read' } 
    2123 
    2224sub _key_field { 'name' } 
     
    126128                multiple => 1, ro => 1, managed => 1, 
    127129                reference => 'netzone', 
    128                 get => sub { 
    129                     my ($self) = @_; 
    130                     my $find = $self->base->db->prepare_cached(q{ 
    131                         select name from netzone where ikey in 
    132                         ( 
    133                         select netzone_attributes.okey from netzone_attributes join 
    134                         nethost_attributes_ips on netzone_attributes.attr='net' 
    135                             and  
    136                         nethost_attributes_ips.value::inet <<= 
    137                         netzone_attributes.value::inet 
    138                         where nethost_attributes_ips.okey = $1 
    139                         except 
    140                         select netzone_attributes.okey from netzone_attributes join 
    141                         nethost_attributes_ips on netzone_attributes.attr='netExclude' 
    142                             and nethost_attributes_ips.value::inet <<= netzone_attributes.value::inet 
    143                         where nethost_attributes_ips.okey = $1 
    144                         ) 
    145                         order by name 
    146                         }); 
    147                     $find->execute($self->object->get_attributes('ikey')); 
    148                     my @zones; 
    149                     while (my $res = $find->fetchrow_hashref) { 
    150                         push(@zones, $res->{name}); 
    151                     } 
    152                     return @zones ? [ @zones ] : undef; 
    153                 }, 
    154130                label => l('NetZones'), 
    155131            }, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Onlyaddress.pm

    r1023 r2090  
    3535            ($base->{wexported} ? '' : 'and "user".exported = true'), 
    3636            $base->db->quote_identifier($class->_object_table), 
    37             $base->db->quote_identifier($class->_object_table. '_attributes'), # attr 
     37            $base->db->quote_identifier($class->_object_table_attributes_read), # attr 
    3838            ($base->{wexported} ? '' : 'and ' . 
    3939                $base->db->quote_identifier($class->_object_table) . '.exported = true'), 
     
    5959            $base->db->quote_identifier($class->_key_field), 
    6060            $base->db->quote_identifier($class->_object_table), 
    61             $base->db->quote_identifier($class->_object_table. '_attributes'), # attr 
     61            $base->db->quote_identifier($class->_object_table_attributes_read), # attr 
    6262            ($base->{wexported} ? '' : 'and exported = true'), 
    6363            $base->db->quote_identifier($class->_key_field), 
     
    7979            $base->db->quote_identifier($class->_key_field), 
    8080            ($base->{wexported} ? '' : 'and exported = true'), 
    81             $base->db->quote_identifier($class->_object_table. '_attributes'), 
     81            $base->db->quote_identifier($class->_object_table_attributes_read), 
    8282        ), 
    8383    ); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r2088 r2090  
    2121 
    2222sub _attributes_table { $_[0]->_object_table . '_attributes_list' } 
     23 
     24# Write extend attribute table 
     25sub _object_table_attributes      { $_[0]->_object_table . '_attributes' } 
     26# Read search table (with compute attribute) 
     27sub _object_table_attributes_read { $_[0]->_object_table . '_attributes' } 
    2328 
    2429sub listReal { 
     
    516521                where %s = ? 
    517522                }, 
    518                 $self->db->quote_identifier($self->_object_table. '_attributes'), 
     523                $self->db->quote_identifier($self->_object_table_attributes_read), 
    519524                $self->db->quote_identifier($self->_object_table), 
    520525                $self->db->quote_identifier($self->_key_field), 
     
    620625            sprintf( 
    621626                q{delete from %s where okey = ? and attr = ?}, 
    622                 $self->db->quote_identifier($self->_object_table. '_attributes'), 
     627                $self->db->quote_identifier($self->_object_table_attributes), 
    623628            ), 
    624629        ); 
     
    626631            sprintf( 
    627632                q{delete from %s where okey = ? and attr = ? and value = ?}, 
    628                 $self->db->quote_identifier($self->_object_table. '_attributes'), 
     633                $self->db->quote_identifier($self->_object_table_attributes), 
    629634            ), 
    630635        ); 
     
    632637            sprintf( 
    633638                q{insert into %s (okey, attr, value) values (?,?,?)}, 
    634                 $self->db->quote_identifier($self->_object_table. '_attributes'), 
     639                $self->db->quote_identifier($self->_object_table_attributes), 
    635640            ) 
    636641        ); 
     
    638643            sprintf( 
    639644                q{update %s set value = ? where okey = ? and attr = ?}, 
    640                 $self->db->quote_identifier($self->_object_table. '_attributes'), 
     645                $self->db->quote_identifier($self->_object_table_attributes), 
    641646            ) 
    642647        ); 
     
    839844                    ($base->{wexported} ? '' : ' and "exported" = true'), 
    840845                $base->db->quote_identifier($class->_object_table), 
    841                 $base->db->quote_identifier($class->_object_table . 
    842                     '_attributes'), 
     846                $base->db->quote_identifier($class->_object_table_attributes_read), 
    843847                $base->db->quote_identifier($class->_object_table), 
    844                 $base->db->quote_identifier($class->_object_table . 
    845                     '_attributes'), 
     848                $base->db->quote_identifier($class->_object_table_attributes_read), 
    846849            ) 
    847850    ); 
     
    906909                q{select name, value from %s left join %s on %s.ikey = %s.okey and attr = ?} . ($base->{wexported} ? '' : ' and "exported" = true'), 
    907910                $base->db->quote_identifier($class->_object_table), 
    908                 $base->db->quote_identifier($class->_object_table . 
    909                     '_attributes'), 
     911                $base->db->quote_identifier($class->_object_table_attributes_read), 
    910912                $base->db->quote_identifier($class->_object_table), 
    911                 $base->db->quote_identifier($class->_object_table . 
    912                     '_attributes'), 
     913                $base->db->quote_identifier($class->_object_table_attributes_read), 
    913914            ) 
    914915    ); 
     
    10651066            my $sql = sprintf( 
    10661067                q{select okey from %s where attr = ? and "value" = ANY (?) }, 
    1067                     $base->db->quote_identifier($class->_object_table . '_attributes'), 
     1068                    $base->db->quote_identifier($class->_object_table_attributes_read), 
    10681069            ); 
    10691070            push(@attrbind, $attribute->iname); 
     
    11231124                          $base->db->quote_identifier($class->_object_table), 
    11241125                          $base->db->quote_identifier( 
    1125                               $class->_object_table . '_attributes' 
     1126                              $class->_object_table_attributes_read 
    11261127                          ), 
    11271128                ); 
     
    11371138                    q{select okey from %s where attr = ? %s}, 
    11381139                    $base->db->quote_identifier( 
    1139                         $class->_object_table . '_attributes' 
     1140                        $class->_object_table_attributes_read 
    11401141                    ), 
    11411142                    $val eq '*' 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm

    r2083 r2090  
    11121112        }, 
    11131113        { 
    1114             ver => 26, 
     1114            ver => '26', 
    11151115            sql => [ ], 
    11161116        }, 
     1117        { 
     1118            ver => 27, 
     1119            sql => [ 
     1120                q{ 
     1121                CREATE OR REPLACE VIEW nethost_attributes_netzone AS 
     1122                SELECT netzone.name AS value, 'netZone' AS attr, nethost_attributes_ips.attr_key, nethost_attributes_ips.okey 
     1123                FROM nethost_attributes_ips, netzone_attributes, netzone 
     1124                WHERE netzone.ikey = netzone_attributes.okey AND netzone_attributes.attr = 'net'::text AND nethost_attributes_ips.value::inet <<= netzone_attributes.value::inet 
     1125                EXCEPT 
     1126                SELECT netzone.name AS value, 'netZone' AS attr, nethost_attributes_ips.attr_key, nethost_attributes_ips.okey 
     1127                FROM nethost_attributes_ips, netzone_attributes, netzone 
     1128                WHERE netzone.ikey = netzone_attributes.okey AND netzone_attributes.attr = 'netExclude'::text AND nethost_attributes_ips.value::inet <<= netzone_attributes.value::inet; 
     1129                }, 
     1130                q{ 
     1131                CREATE OR REPLACE VIEW nethost_attributes_read AS 
     1132                SELECT nethost_attributes.value, nethost_attributes.attr, nethost_attributes.attr_key, nethost_attributes.okey 
     1133                FROM nethost_attributes 
     1134                UNION 
     1135                SELECT nethost_attributes_netzone.value, nethost_attributes_netzone.attr, nethost_attributes_netzone.attr_key, nethost_attributes_netzone.okey 
     1136                FROM nethost_attributes_netzone; 
     1137                } 
     1138            ], 
     1139        } 
    11171140    ); 
    11181141 
     
    12151238                return; 
    12161239            } 
    1217                  
     1240 
    12181241            if ($self->_CreateInternalObjects) { 
    12191242                $self->log(LA_DEBUG, "upgrade::_CreateInternalObjects done"); 
Note: See TracChangeset for help on using the changeset viewer.