X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=sql%2FPg-upgrade2%2Fcp_greeting_migration.pl;h=176516572fbe8064e3d1e3068434a74778eda1e0;hb=3a7d0b6be7c5b679e8b2a00d326998a39c6e0529;hp=3b978a542aa6090de95cbc13dd48dac4320ebf4a;hpb=03ca3d74f96bf05a9c632b3e0f9538785d8a0fc6;p=kivitendo-erp.git
diff --git a/sql/Pg-upgrade2/cp_greeting_migration.pl b/sql/Pg-upgrade2/cp_greeting_migration.pl
index 3b978a542..176516572 100644
--- a/sql/Pg-upgrade2/cp_greeting_migration.pl
+++ b/sql/Pg-upgrade2/cp_greeting_migration.pl
@@ -8,8 +8,7 @@ die("This script cannot be run from the command line.") unless ($main::form);
sub mydberror {
my ($msg) = @_;
- die($dbup_locale->text("Database update error:") .
- "
$msg
" . $DBI::errstr);
+ die($dbup_locale->text("Database update error:") . "
$msg
" . $DBI::errstr);
}
sub do_query {
@@ -39,16 +38,16 @@ sub query_result {
while (my $row = $sth2->fetchrow_hashref()) {
if ($main::form->{"gender_$i"} eq "f" ) {
- $mchecked = "";
- $fchecked = "checked";
- } else {
- $mchecked = "checked";
- $fchecked = "";
- };
+ $mchecked = "";
+ $fchecked = "checked";
+ } else {
+ $mchecked = "checked";
+ $fchecked = "";
+ };
- $gender_table .= "
{cp_id}\"> $row->{cp_givenname} | $row->{cp_name} | $row->{cp_title} | $row->{cp_greeting} | |
\n";
- $i++;
- };
+ $gender_table .= "{cp_id}\"> $row->{cp_givenname} | $row->{cp_name} | $row->{cp_title} | $row->{cp_greeting} | |
\n";
+ $i++;
+ }
$gender_table .= "";
$gender_table .= "";
@@ -67,21 +66,18 @@ sub query_result {
my $j = 1;
while (my $row = $sth3->fetchrow_hashref()) {
# Vorschlagsfeld fuer neuen Titel mit Werten von cp_greeting und cp_title vorbelegen
- my $value = "$row->{cp_greeting}";
- $value .= " " if $row->{cp_greeting};
- $value .= "$row->{cp_title}";
+ my $value = "$row->{cp_greeting}";
+ $value .= " " if $row->{cp_greeting};
+ $value .= "$row->{cp_title}";
- $title_table .= " {cp_id}> $row->{cp_givenname} | $row->{cp_name} | $row->{cp_title} | $row->{cp_greeting} | |
\n";
- $j++;
- };
+ $title_table .= " {cp_id}> $row->{cp_givenname} | $row->{cp_name} | $row->{cp_title} | $row->{cp_greeting} | |
\n";
+ $j++;
+ }
$title_table .= "";
$title_table .= "";
$main::form->{title_table} = $title_table;
-
-};
-
-
+}
sub print_question {
query_result();
@@ -89,9 +85,26 @@ sub print_question {
print $main::form->parse_html_template("dbupgrade/cp_greeting_update_form");
}
+sub alter_schema_only {
+ my $sqlcode = <do($sqlcode);
+}
+
sub do_update {
# main function
+ # Do not ask the user anything if there are no entries in the
+ # contacts table.
+ my ($data_exists) = $dbh->selectrow_array("SELECT * FROM contacts LIMIT 1");
+ if (!$data_exists) {
+ alter_schema_only();
+ return 1;
+ }
+
# first of all check if gender.sql was already run and thus cp_gender exists
# if it exists there is no need for this update anymore, so return
# without doing anything
@@ -113,9 +126,9 @@ sub do_update {
} else {
# case 2: submit button was pressed, hidden field do_migrate was set
migrate_data();
- };
+ }
-return 1;
+ return 1;
}
@@ -133,15 +146,15 @@ EOF
for (my $i = 1; $i <= $main::form->{number_of_gender_entries}; $i++ ) {
next unless $main::form->{"cp_id_$i"};
- if ( $main::form->{"gender_$i"} eq "f" ) {
- $sqlcode .= "UPDATE contacts SET cp_gender = \'f\' WHERE cp_id = $main::form->{\"cp_id_$i\"};\n";
- };
- };
+ if ( $main::form->{"gender_$i"} eq "f" ) {
+ $sqlcode .= "UPDATE contacts SET cp_gender = \'f\' WHERE cp_id = $main::form->{\"cp_id_$i\"};\n";
+ }
+ }
for (my $i = 1; $i <= $main::form->{number_of_title_entries}; $i++ ) {
next unless $main::form->{"cp_id_title_$i"} and $main::form->{"cp_id_$i"};
- $sqlcode .= "UPDATE contacts SET cp_title = \'$main::form->{\"cp_name_$i\"}\' WHERE cp_id = $main::form->{\"cp_id_$i\"};\n";
- };
+ $sqlcode .= "UPDATE contacts SET cp_title = \'$main::form->{\"cp_name_$i\"}\' WHERE cp_id = $main::form->{\"cp_id_$i\"};\n";
+ }
$sqlcode .= "ALTER TABLE contacts DROP COLUMN cp_greeting;";
# insert chosen default values
@@ -150,22 +163,18 @@ EOF
my $query = $sqlcode;
do_query($query);
-};
-
-
+}
sub set_default_greetings {
# add html input boxes to template so user can specify default greetings
- my $default_male = "Herr";
- my $default_female = "Frau";
-
- my $default_greeting_text_male = "
";
- my $default_greeting_text_female = "
";
- $main::form->{default_greeting_text_male} = $default_greeting_text_male;
+ my $default_male = "Herr";
+ my $default_female = "Frau";
+ my $default_greeting_text_male = "
";
+ my $default_greeting_text_female = "
";
+ $main::form->{default_greeting_text_male} = $default_greeting_text_male;
$main::form->{default_greeting_text_female} = $default_greeting_text_female;
-};
-
+}
return do_update();