Datenbanktabelle und -modelle für CSV-Stammdatenimportprofile
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 23 Feb 2011 10:06:32 +0000 (11:06 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 16 Jun 2011 06:44:13 +0000 (08:44 +0200)
SL/DB/CsvImportProfile.pm [new file with mode: 0644]
SL/DB/CsvImportProfileSetting.pm [new file with mode: 0644]
SL/DB/Helper/ALL.pm
SL/DB/Helper/Mappings.pm
SL/DB/MetaSetup/CsvImportProfile.pm [new file with mode: 0644]
SL/DB/MetaSetup/CsvImportProfileSetting.pm [new file with mode: 0644]
sql/Pg-upgrade2/csv_import_profiles.sql [new file with mode: 0644]

diff --git a/SL/DB/CsvImportProfile.pm b/SL/DB/CsvImportProfile.pm
new file mode 100644 (file)
index 0000000..85033e1
--- /dev/null
@@ -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 (file)
index 0000000..6da5b34
--- /dev/null
@@ -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;
index c030bed..54b4b49 100644 (file)
@@ -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;
index 4fe4ac9..7f281e3 100644 (file)
@@ -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 (file)
index 0000000..0acc97d
--- /dev/null
@@ -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 (file)
index 0000000..d1822a3
--- /dev/null
@@ -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 (file)
index 0000000..2efac04
--- /dev/null
@@ -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)
+);