Revision c2cf302a
Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt
SL/DB/CsvImportProfile.pm | ||
---|---|---|
1 |
package SL::DB::CsvImportProfile; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use List::Util qw(first); |
|
6 |
|
|
7 |
use SL::DB::MetaSetup::CsvImportProfile; |
|
8 |
|
|
9 |
__PACKAGE__->meta->add_relationship( |
|
10 |
settings => { |
|
11 |
type => 'one to many', |
|
12 |
class => 'SL::DB::CsvImportProfileSetting', |
|
13 |
column_map => { id => 'csv_import_profile_id' }, |
|
14 |
}, |
|
15 |
); |
|
16 |
|
|
17 |
__PACKAGE__->meta->initialize; |
|
18 |
|
|
19 |
__PACKAGE__->meta->make_manager_class; |
|
20 |
|
|
21 |
__PACKAGE__->before_save('_before_save_unset_default_on_others'); |
|
22 |
|
|
23 |
# |
|
24 |
# public functions |
|
25 |
# |
|
26 |
|
|
27 |
sub set { |
|
28 |
my ($self, %params) = @_; |
|
29 |
|
|
30 |
while (my ($key, $value) = each %params) { |
|
31 |
my $setting = $self->_get_setting($key); |
|
32 |
|
|
33 |
if (!$setting) { |
|
34 |
$setting = SL::DB::CsvImportProfileSetting->new(key => $key); |
|
35 |
$self->add_settings($setting); |
|
36 |
} |
|
37 |
|
|
38 |
$setting->value($value); |
|
39 |
} |
|
40 |
|
|
41 |
return $self; |
|
42 |
} |
|
43 |
|
|
44 |
sub get { |
|
45 |
my ($self, $key, $default) = @_; |
|
46 |
|
|
47 |
my $setting = $self->_get_setting($key); |
|
48 |
return $setting ? $setting->value : $default; |
|
49 |
} |
|
50 |
|
|
51 |
# |
|
52 |
# hooks |
|
53 |
# |
|
54 |
|
|
55 |
sub _before_save_unset_default_on_others { |
|
56 |
my ($self) = @_; |
|
57 |
|
|
58 |
if ($self->is_default) { |
|
59 |
SL::DB::Manager::CsvImportProfile->update_all(set => { is_default => 0 }, |
|
60 |
where => [ type => $self->type, |
|
61 |
'!id' => $self->id ]); |
|
62 |
} |
|
63 |
|
|
64 |
return 1; |
|
65 |
} |
|
66 |
|
|
67 |
# |
|
68 |
# helper functions |
|
69 |
# |
|
70 |
|
|
71 |
sub _get_setting { |
|
72 |
my ($self, $key) = @_; |
|
73 |
return first { $_->key eq $key } @{ $self->settings }; |
|
74 |
} |
|
75 |
|
|
76 |
1; |
SL/DB/CsvImportProfileSetting.pm | ||
---|---|---|
1 |
# This file has been auto-generated only because it didn't exist. |
|
2 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
3 |
|
|
4 |
package SL::DB::CsvImportProfileSetting; |
|
5 |
|
|
6 |
use strict; |
|
7 |
|
|
8 |
use SL::DB::MetaSetup::CsvImportProfileSetting; |
|
9 |
|
|
10 |
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. |
|
11 |
__PACKAGE__->meta->make_manager_class; |
|
12 |
|
|
13 |
1; |
SL/DB/Helper/ALL.pm | ||
---|---|---|
13 | 13 |
use SL::DB::Business; |
14 | 14 |
use SL::DB::Chart; |
15 | 15 |
use SL::DB::Contact; |
16 |
use SL::DB::CsvImportProfile; |
|
17 |
use SL::DB::CsvImportProfileSetting; |
|
16 | 18 |
use SL::DB::CustomVariable; |
17 | 19 |
use SL::DB::CustomVariableConfig; |
18 | 20 |
use SL::DB::CustomVariableValidity; |
SL/DB/Helper/Mappings.pm | ||
---|---|---|
39 | 39 |
bank_accounts => 'bank_account', |
40 | 40 |
buchungsgruppen => 'buchungsgruppe', |
41 | 41 |
contacts => 'contact', |
42 |
csv_import_profiles => 'csv_import_profile', |
|
43 |
csv_import_profile_settings => 'csv_import_profile_setting', |
|
42 | 44 |
custom_variable_configs => 'custom_variable_config', |
43 | 45 |
custom_variables => 'custom_variable', |
44 | 46 |
custom_variables_validity => 'custom_variable_validity', |
SL/DB/MetaSetup/CsvImportProfile.pm | ||
---|---|---|
1 |
# This file has been auto-generated. Do not modify it; it will be overwritten |
|
2 |
# by rose_auto_create_model.pl automatically. |
|
3 |
package SL::DB::CsvImportProfile; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use base qw(SL::DB::Object); |
|
8 |
|
|
9 |
__PACKAGE__->meta->setup( |
|
10 |
table => 'csv_import_profiles', |
|
11 |
|
|
12 |
columns => [ |
|
13 |
id => { type => 'serial', not_null => 1 }, |
|
14 |
name => { type => 'text', not_null => 1 }, |
|
15 |
type => { type => 'varchar', length => 20, not_null => 1 }, |
|
16 |
is_default => { type => 'boolean', default => 'false' }, |
|
17 |
], |
|
18 |
|
|
19 |
primary_key_columns => [ 'id' ], |
|
20 |
|
|
21 |
unique_key => [ 'name' ], |
|
22 |
); |
|
23 |
|
|
24 |
1; |
|
25 |
; |
SL/DB/MetaSetup/CsvImportProfileSetting.pm | ||
---|---|---|
1 |
# This file has been auto-generated. Do not modify it; it will be overwritten |
|
2 |
# by rose_auto_create_model.pl automatically. |
|
3 |
package SL::DB::CsvImportProfileSetting; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use base qw(SL::DB::Object); |
|
8 |
|
|
9 |
__PACKAGE__->meta->setup( |
|
10 |
table => 'csv_import_profile_settings', |
|
11 |
|
|
12 |
columns => [ |
|
13 |
id => { type => 'serial', not_null => 1 }, |
|
14 |
csv_import_profile_id => { type => 'integer', not_null => 1 }, |
|
15 |
key => { type => 'text', not_null => 1 }, |
|
16 |
value => { type => 'text' }, |
|
17 |
], |
|
18 |
|
|
19 |
primary_key_columns => [ 'id' ], |
|
20 |
|
|
21 |
unique_key => [ 'csv_import_profile_id', 'key' ], |
|
22 |
|
|
23 |
foreign_keys => [ |
|
24 |
csv_import_profile => { |
|
25 |
class => 'SL::DB::CsvImportProfile', |
|
26 |
key_columns => { csv_import_profile_id => 'id' }, |
|
27 |
}, |
|
28 |
], |
|
29 |
); |
|
30 |
|
|
31 |
1; |
|
32 |
; |
sql/Pg-upgrade2/csv_import_profiles.sql | ||
---|---|---|
1 |
-- @tag: csv_import_profiles |
|
2 |
-- @description: CSV-Import-Profile für Stammdaten |
|
3 |
-- @depends: release_2_6_1 |
|
4 |
-- @charset: utf-8 |
|
5 |
CREATE TABLE csv_import_profiles ( |
|
6 |
id SERIAL NOT NULL, |
|
7 |
name text NOT NULL, |
|
8 |
type varchar(20) NOT NULL, |
|
9 |
is_default boolean DEFAULT FALSE, |
|
10 |
|
|
11 |
PRIMARY KEY (id), |
|
12 |
UNIQUE (name) |
|
13 |
); |
|
14 |
|
|
15 |
CREATE TABLE csv_import_profile_settings ( |
|
16 |
id SERIAL NOT NULL, |
|
17 |
csv_import_profile_id integer NOT NULL, |
|
18 |
key text NOT NULL, |
|
19 |
value text, |
|
20 |
|
|
21 |
PRIMARY KEY (id), |
|
22 |
FOREIGN KEY (csv_import_profile_id) REFERENCES csv_import_profiles (id), |
|
23 |
UNIQUE (csv_import_profile_id, key) |
|
24 |
); |
Auch abrufbar als: Unified diff
Datenbanktabelle und -modelle für CSV-Stammdatenimportprofile