From e84a4d2033636709d6c7e5540956b1f369ca3dfe Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Mon, 10 Dec 2018 16:04:56 +0100 Subject: [PATCH] add multi-valued federations column --- bin/update-metadata.in | 40 ++++++++++++++++++++++-------------- conf/manager.sql | 3 ++- lib/AccountManager/Entity.pm | 1 + 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/bin/update-metadata.in b/bin/update-metadata.in index 95d8182..840e486 100755 --- a/bin/update-metadata.in +++ b/bin/update-metadata.in @@ -86,25 +86,35 @@ foreach my $id (split(/, */, $configuration->{groups}->{list})) { } foreach my $entry (@$entities) { - # skip duplicates - next if $seen{$entry->{entityid}}++; - # skip entities different from SP or IdP next if !$entry->{type}; - my $entity = AccountManager::Entity->new( - db => $db, - type => $entry->{type}, - entityid => $entry->{entityid}, - displayname => $entry->{display_name}, - information_url => $entry->{information_url}, - organization_url => $entry->{organization_url}, - ); - - $entity->contacts(uniq map { $_->{EmailAddress} } @{$entry->{contacts}}) - if $entry->{contacts}; + my $entity; + if ($seen{$entry->{entityid}}++) { + $entity = AccountManager::Entity->new( + db => $db, + entityid => $entry->{entityid}, + ); + $entity->load(); + $entity->federations( + $entity->federations(), $id + ); + $entity->update(); + } else { + $entity = AccountManager::Entity->new( + db => $db, + type => $entry->{type}, + entityid => $entry->{entityid}, + displayname => $entry->{display_name}, + information_url => $entry->{information_url}, + organization_url => $entry->{organization_url}, + ); + $entity->contacts(uniq map { $_->{EmailAddress} } @{$entry->{contacts}}) + if $entry->{contacts}; + $entity->federations($id); + $entity->save(); + } - $entity->save(); } } diff --git a/conf/manager.sql b/conf/manager.sql index b9b5c13..61a576d 100644 --- a/conf/manager.sql +++ b/conf/manager.sql @@ -19,8 +19,9 @@ CREATE TABLE entities ( organization_url varchar(200) DEFAULT NULL, displayname varchar(500) DEFAULT NULL, contacts varchar(2000) DEFAULT NULL, + federations varchar(50) DEFAULT NULL, PRIMARY KEY (id), - UNIQUE KEY entityid (entityid) + KEY entityid (entityid) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; CREATE TABLE accounts ( diff --git a/lib/AccountManager/Entity.pm b/lib/AccountManager/Entity.pm index 2b05788..6e219f1 100644 --- a/lib/AccountManager/Entity.pm +++ b/lib/AccountManager/Entity.pm @@ -19,6 +19,7 @@ __PACKAGE__->meta->setup( information_url => { type => 'varchar', length => 200 }, organization_url => { type => 'varchar', length => 200 }, contacts => { type => 'array' }, + federations => { type => 'array' }, ], primary_key_columns => [ 'id' ], -- GitLab