From: Moritz Bunkus Date: Wed, 23 Feb 2011 10:06:32 +0000 (+0100) Subject: Datenbanktabelle und -modelle für CSV-Stammdatenimportprofile X-Git-Tag: release-2.7.0beta1~396^2~59 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=c2cf302a52645c06687d49496ea4a42471ea095c;p=kivitendo-erp.git Datenbanktabelle und -modelle für CSV-Stammdatenimportprofile --- diff --git a/SL/DB/CsvImportProfile.pm b/SL/DB/CsvImportProfile.pm new file mode 100644 index 000000000..85033e181 --- /dev/null +++ b/SL/DB/CsvImportProfile.pm @@ -0,0 +1,76 @@ +package SL::DB::CsvImportProfile; + +use strict; + +use List::Util qw(first); + +use SL::DB::MetaSetup::CsvImportProfile; + +__PACKAGE__->meta->add_relationship( + settings => { + type => 'one to many', + class => 'SL::DB::CsvImportProfileSetting', + column_map => { id => 'csv_import_profile_id' }, + }, +); + +__PACKAGE__->meta->initialize; + +__PACKAGE__->meta->make_manager_class; + +__PACKAGE__->before_save('_before_save_unset_default_on_others'); + +# +# public functions +# + +sub set { + my ($self, %params) = @_; + + while (my ($key, $value) = each %params) { + my $setting = $self->_get_setting($key); + + if (!$setting) { + $setting = SL::DB::CsvImportProfileSetting->new(key => $key); + $self->add_settings($setting); + } + + $setting->value($value); + } + + return $self; +} + +sub get { + my ($self, $key, $default) = @_; + + my $setting = $self->_get_setting($key); + return $setting ? $setting->value : $default; +} + +# +# hooks +# + +sub _before_save_unset_default_on_others { + my ($self) = @_; + + if ($self->is_default) { + SL::DB::Manager::CsvImportProfile->update_all(set => { is_default => 0 }, + where => [ type => $self->type, + '!id' => $self->id ]); + } + + return 1; +} + +# +# helper functions +# + +sub _get_setting { + my ($self, $key) = @_; + return first { $_->key eq $key } @{ $self->settings }; +} + +1; diff --git a/SL/DB/CsvImportProfileSetting.pm b/SL/DB/CsvImportProfileSetting.pm new file mode 100644 index 000000000..6da5b34be --- /dev/null +++ b/SL/DB/CsvImportProfileSetting.pm @@ -0,0 +1,13 @@ +# This file has been auto-generated only because it didn't exist. +# Feel free to modify it at will; it will not be overwritten automatically. + +package SL::DB::CsvImportProfileSetting; + +use strict; + +use SL::DB::MetaSetup::CsvImportProfileSetting; + +# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. +__PACKAGE__->meta->make_manager_class; + +1; diff --git a/SL/DB/Helper/ALL.pm b/SL/DB/Helper/ALL.pm index c030bed92..54b4b49f3 100644 --- a/SL/DB/Helper/ALL.pm +++ b/SL/DB/Helper/ALL.pm @@ -13,6 +13,8 @@ use SL::DB::Buchungsgruppe; use SL::DB::Business; use SL::DB::Chart; use SL::DB::Contact; +use SL::DB::CsvImportProfile; +use SL::DB::CsvImportProfileSetting; use SL::DB::CustomVariable; use SL::DB::CustomVariableConfig; use SL::DB::CustomVariableValidity; diff --git a/SL/DB/Helper/Mappings.pm b/SL/DB/Helper/Mappings.pm index 4fe4ac94f..7f281e34c 100644 --- a/SL/DB/Helper/Mappings.pm +++ b/SL/DB/Helper/Mappings.pm @@ -39,6 +39,8 @@ my %lxoffice_package_names = ( bank_accounts => 'bank_account', buchungsgruppen => 'buchungsgruppe', contacts => 'contact', + csv_import_profiles => 'csv_import_profile', + csv_import_profile_settings => 'csv_import_profile_setting', custom_variable_configs => 'custom_variable_config', custom_variables => 'custom_variable', custom_variables_validity => 'custom_variable_validity', diff --git a/SL/DB/MetaSetup/CsvImportProfile.pm b/SL/DB/MetaSetup/CsvImportProfile.pm new file mode 100644 index 000000000..0acc97d94 --- /dev/null +++ b/SL/DB/MetaSetup/CsvImportProfile.pm @@ -0,0 +1,25 @@ +# This file has been auto-generated. Do not modify it; it will be overwritten +# by rose_auto_create_model.pl automatically. +package SL::DB::CsvImportProfile; + +use strict; + +use base qw(SL::DB::Object); + +__PACKAGE__->meta->setup( + table => 'csv_import_profiles', + + columns => [ + id => { type => 'serial', not_null => 1 }, + name => { type => 'text', not_null => 1 }, + type => { type => 'varchar', length => 20, not_null => 1 }, + is_default => { type => 'boolean', default => 'false' }, + ], + + primary_key_columns => [ 'id' ], + + unique_key => [ 'name' ], +); + +1; +; diff --git a/SL/DB/MetaSetup/CsvImportProfileSetting.pm b/SL/DB/MetaSetup/CsvImportProfileSetting.pm new file mode 100644 index 000000000..d1822a358 --- /dev/null +++ b/SL/DB/MetaSetup/CsvImportProfileSetting.pm @@ -0,0 +1,32 @@ +# This file has been auto-generated. Do not modify it; it will be overwritten +# by rose_auto_create_model.pl automatically. +package SL::DB::CsvImportProfileSetting; + +use strict; + +use base qw(SL::DB::Object); + +__PACKAGE__->meta->setup( + table => 'csv_import_profile_settings', + + columns => [ + id => { type => 'serial', not_null => 1 }, + csv_import_profile_id => { type => 'integer', not_null => 1 }, + key => { type => 'text', not_null => 1 }, + value => { type => 'text' }, + ], + + primary_key_columns => [ 'id' ], + + unique_key => [ 'csv_import_profile_id', 'key' ], + + foreign_keys => [ + csv_import_profile => { + class => 'SL::DB::CsvImportProfile', + key_columns => { csv_import_profile_id => 'id' }, + }, + ], +); + +1; +; diff --git a/sql/Pg-upgrade2/csv_import_profiles.sql b/sql/Pg-upgrade2/csv_import_profiles.sql new file mode 100644 index 000000000..2efac0457 --- /dev/null +++ b/sql/Pg-upgrade2/csv_import_profiles.sql @@ -0,0 +1,24 @@ +-- @tag: csv_import_profiles +-- @description: CSV-Import-Profile für Stammdaten +-- @depends: release_2_6_1 +-- @charset: utf-8 +CREATE TABLE csv_import_profiles ( + id SERIAL NOT NULL, + name text NOT NULL, + type varchar(20) NOT NULL, + is_default boolean DEFAULT FALSE, + + PRIMARY KEY (id), + UNIQUE (name) +); + +CREATE TABLE csv_import_profile_settings ( + id SERIAL NOT NULL, + csv_import_profile_id integer NOT NULL, + key text NOT NULL, + value text, + + PRIMARY KEY (id), + FOREIGN KEY (csv_import_profile_id) REFERENCES csv_import_profiles (id), + UNIQUE (csv_import_profile_id, key) +);