summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VNDB/ExtLinks.pm16
-rw-r--r--lib/VNWeb/Releases/Edit.pm6
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/VNDB/ExtLinks.pm b/lib/VNDB/ExtLinks.pm
index 97dcd682..d0d19e08 100644
--- a/lib/VNDB/ExtLinks.pm
+++ b/lib/VNDB/ExtLinks.pm
@@ -6,7 +6,7 @@ use VNDB::Config;
use VNDB::Schema;
use Exporter 'import';
-our @EXPORT = ('enrich_extlinks', 'revision_extlinks', 'validate_extlinks');
+our @EXPORT = ('enrich_extlinks', 'revision_extlinks', 'validate_extlinks', 'empty_extlinks');
# column name in wikidata table => \%info
@@ -308,6 +308,20 @@ sub validate_extlinks {
}
+# Generate a struct with empty/default values according to the structure defined in validate_extlinks().
+sub empty_extlinks {
+ my($type) = @_;
+ my($schema) = grep +($_->{dbentry_type}||'') eq $type, values VNDB::Schema::schema->%*;
+ +{
+ map {
+ my($f, $p) = ($_, $LINKS{$type}{$_});
+ my($s) = grep $_->{name} eq $f, $schema->{cols}->@*;
+ ($f, $s->{type} =~ /\[\]/ ? [] : $s->{type} =~ /^int/ ? 0 : '')
+ } grep $LINKS{$type}{$_}{regex}, keys $LINKS{$type}->%*
+ }
+}
+
+
# Returns a list of sites for use in VNWeb::Elm:
# { id => $id, name => $label, fmt => $label, regex => $regex, int => $bool, multi => $bool, default => 0||'""'||'[]', pattern => [..] }
sub extlinks_sites {
diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm
index 802f8370..02e7a537 100644
--- a/lib/VNWeb/Releases/Edit.pm
+++ b/lib/VNWeb/Releases/Edit.pm
@@ -80,6 +80,12 @@ TUWF::get qr{/$RE{rrev}/(?<action>edit|copy)} => sub {
enrich_merge vid => 'SELECT id AS vid, title FROM vn WHERE id IN', $e->{vn};
enrich_merge pid => 'SELECT id AS pid, name FROM producers WHERE id IN', $e->{producers};
+ if($copy) {
+ $e->{gtin} = 0;
+ $e->{catalog} = 0;
+ $e->{extlinks} = empty_extlinks 'r';
+ }
+
my $title = ($copy ? 'Copy ' : 'Edit ').$e->{title};
framework_ title => $title, type => 'r', dbobj => $e, tab => tuwf->capture('action'),
sub {