my( $evt, $tcn, $tcn_source, $marcdoc );
- if( $auto_tcn ) {
+ my $use_id = $e->retrieve_config_global_flag('cat.bib.use_id_for_tcn');
+ $use_id = ($use_id and $U->is_true($use_id->enabled));
+
+ if( $auto_tcn or $use_id ) {
# auto_tcn forces a blank TCN value so the DB will have to generate one for us
$marcdoc = __make_marc_doc($xml);
} else {
$record->marc($U->entityize($marcdoc->documentElement->toString));
$record = $e->create_biblio_record_entry($record) or return $e->die_event;
- $logger->info("marc create/import created new record ".$record->id);
+ if($use_id) {
+ my $existing = $e->search_biblio_record_entry(
+ {
+ tcn_value => $record->id,
+ deleted => 'f'
+ }, {
+ idlist => 1
+ }
+ );
+
+ if(@$existing) {
+ # leave the auto-generated tcn_value in place
+ $logger->warn("Collision using internal ID as tcn_value for record " . $record->id);
+ } else {
+ $record->tcn_value($record->id);
+ $e->update_biblio_record_entry($record) or return $e->die_event;
+ }
+ }
+
+ $logger->info("marc create/import created new record ".$record->id);
return $record;
}
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0248'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0249'); -- berick
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
'bool'
);
+INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE
+ VALUES (
+ 'cat.bib.use_id_for_tcn',
+ oils_i18n_gettext(
+ 'cat.bib.use_id_for_tcn',
+ 'Cat: Use Internal ID for TCN Value',
+ 'cgf',
+ 'label'
+ )
+ );
+
+
+
--- /dev/null
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0249');
+
+INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE
+ VALUES (
+ 'cat.bib.use_id_for_tcn',
+ oils_i18n_gettext(
+ 'cat.bib.use_id_for_tcn',
+ 'Cat: Use Internal ID for TCN Value',
+ 'cgf',
+ 'label'
+ )
+ );
+
+COMMIT;