X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/1c603341fc02e3a5a7b5126cd7df6478d2e34700..946324538fb1706eb9f3ff7f98ecad8e27710c95:/sql/Pg-upgrade2/cp_greeting_migration.pl
diff --git a/sql/Pg-upgrade2/cp_greeting_migration.pl b/sql/Pg-upgrade2/cp_greeting_migration.pl
new file mode 100644
index 000000000..1ee6abd61
--- /dev/null
+++ b/sql/Pg-upgrade2/cp_greeting_migration.pl
@@ -0,0 +1,170 @@
+# @tag: cp_greeting_migration
+# @description: Migration of cp_greeting to cp_gender
+# @depends: generic_translations
+
+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);
+}
+
+sub do_query {
+ my ($query, $may_fail) = @_;
+
+ if (!$dbh->do($query)) {
+ mydberror($query) unless ($may_fail);
+ $dbh->rollback();
+ $dbh->begin_work();
+ }
+}
+
+
+sub query_result {
+
+ # list of all entries where cp_greeting is empty, meaning can't determine gender from parsing Herr/Frau/...
+ # this assumes cp_greeting still exists, i.e. gender.sql was not run yet
+ my $gender_table;
+
+ my $sql2 = "select cp_id,cp_givenname,cp_name,cp_title,cp_greeting from contacts where not (cp_greeting ILIKE '%frau%' OR cp_greeting ILIKE '%herr%' or cp_greeting ILIKE '%mrs.%' or cp_greeting ILIKE '%miss%') ";
+ my $sth2 = $dbh->prepare($sql2) or die $dbh->errstr();
+ $sth2->execute() or die $dbh->errstr();
+
+ my $i = 1;
+ $gender_table .= '
";
+
+ $main::form->{gender_table} = $gender_table;
+
+ my $title_table;
+
+ my $sql3 = "select cp_id,cp_givenname,cp_name,cp_title,cp_greeting from contacts where not ( (cp_greeting ILIKE '%frau%' OR cp_greeting ILIKE '%herr%' or cp_greeting ILIKE '%mrs.%' or cp_greeting ILIKE '%miss%')) and not (cp_greeting like ''); ";
+
+ my $sth3 = $dbh->prepare($sql3) or die $dbh->errstr();
+ $sth3->execute() or die $dbh->errstr();
+
+ $title_table = '
cp_givenname
cp_name
cp_title
cp_greeting
cp_title new
';
+
+ 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}";
+
+ $title_table .= "