[interchange-cvs] interchange - racke modified 2 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Fri May 24 16:35:01 2002
User: racke
Date: 2002-05-24 20:34:44 GMT
Modified: dist/lib/UI/pages/admin Tag: STABLE_4_8-branch
Modified: import_table.html
Modified: dist/lib/UI/usertag Tag: STABLE_4_8-branch import_fields.tag
Log:
added option to replace items in the database
Revision Changes Path
No revision
No revision
2.0.2.3 +15 -0 interchange/dist/lib/UI/pages/admin/import_table.html
rev 2.0.2.3, prev_rev 2.0.2.2
Index: import_table.html
===================================================================
RCS file: /anon_cvs/repository/interchange/dist/lib/UI/pages/admin/import_table.html,v
retrieving revision 2.0.2.2
retrieving revision 2.0.2.3
diff -u -r2.0.2.2 -r2.0.2.3
--- import_table.html 19 Sep 2001 19:08:04 -0000 2.0.2.2
+++ import_table.html 24 May 2002 20:34:44 -0000 2.0.2.3
@@ -93,6 +93,20 @@
table="[cgi mv_data_table]"
]
[/elsif]
+ [elsif cgi ui_upload_ext eq cleanse]
+ [import-fields
+ add=1
+ convert="[cgi ui_import_convert]"
+ cleanse=1
+ delete="[cgi ui_allow_delete]"
+ dir=backup
+ file="upload/[cgi ui_upload_filename]"
+ move=1
+ multiple="[cgi ui_allow_multiple]"
+ quiet="[cgi ui_import_quiet]"
+ table="[cgi mv_data_table]"
+ ]
+ [/elsif]
[/if]
[/if]
@@ -119,6 +133,7 @@
<hr>
<SELECT NAME=ui_upload_ext>
<OPTION VALUE=add> [L]Add new items if present[/L]
+ <OPTION VALUE=cleanse> [L]Replace existing items[/L]
<OPTION VALUE=update> [L]Ignore new items[/L]
</SELECT> <SMALL><INPUT TYPE=checkbox NAME=ui_allow_delete VALUE=1> [L]Allow delete[/L]
<INPUT TYPE=checkbox NAME=ui_autonumber VALUE=1 CHECKED> [L]Autonumber if no key[/L]</SMALL>
No revision
No revision
2.0.2.1 +17 -1 interchange/dist/lib/UI/usertag/Attic/import_fields.tag
rev 2.0.2.1, prev_rev 2.0
Index: import_fields.tag
===================================================================
RCS file: /anon_cvs/repository/interchange/dist/lib/UI/usertag/Attic/import_fields.tag,v
retrieving revision 2.0
retrieving revision 2.0.2.1
diff -u -r2.0 -r2.0.2.1
--- import_fields.tag 18 Jul 2001 02:22:15 -0000 2.0
+++ import_fields.tag 24 May 2002 20:34:44 -0000 2.0.2.1
@@ -193,7 +193,7 @@
my $k;
my @f;
@names = split /\s+/, $fields;
- shift @names;
+ my $key = shift @names;
my @set;
my $i = 0;
my $idx = 0;
@@ -201,6 +201,12 @@
$db->column_index($_);
$set[$idx++] = $db->field_settor($_);
}
+ my %keys;
+ if ($opt->{cleanse}) {
+ # record existing columns
+ my $recs = $db->query("select $key from $table");
+ $keys{$_->[0]} = 1 for @$recs;
+ }
my $count = 0;
my $totcount = 0;
my $delcount = 0;
@@ -246,8 +252,18 @@
}
for ($i = 0; $i < $idx; $i++) {
$set[$i]->($k, $f[$i]);
+ if ($opt->{cleanse}) {
+ delete $keys{$k};
+ }
}
$count++;
+ }
+ if ($opt->{cleanse}) {
+ # remove any record which hasn't updated
+ for (keys(%keys)) {
+ $db->delete_record($_);
+ $delcount++;
+ }
}
$out .= "${tmsg}$count records processed of $totcount input lines.\n";
$out .= "${tmsg}$delcount records deleted.\n" if $delcount;