View | Details | Raw Unified | Return to bug 9192
Collapse All | Expand All

(-)a/misc/maintenance/UNIMARC_sync_date_created_with_marc_biblio.pl (-12 / +42 lines)
Lines 52-57 $verbose and print "================================\n"; Link Here
52
$date_created_marc = '099c' unless $date_created_marc;
52
$date_created_marc = '099c' unless $date_created_marc;
53
my ( $c_field, $c_subfield ) = _read_marc_code($date_created_marc);
53
my ( $c_field, $c_subfield ) = _read_marc_code($date_created_marc);
54
die "date-created-marc '$date_created_marc' is not correct." unless $c_field;
54
die "date-created-marc '$date_created_marc' is not correct." unless $c_field;
55
die "date-created-marc field is greated that 009, it should have a subfield."
56
  if ( $c_field > 9 && !defined $c_subfield );
57
die "date-created-marc field is lower that 010, it should not have a subfield."
58
  if ( $c_field < 10 && defined $c_subfield );
55
if ($verbose) {
59
if ($verbose) {
56
    print "Date created on $c_field";
60
    print "Date created on $c_field";
57
    print $c_subfield if defined $c_subfield;    # use of defined to allow 0
61
    print $c_subfield if defined $c_subfield;    # use of defined to allow 0
Lines 62-67 if ($verbose) { Link Here
62
$date_modified_marc = '099d' unless $date_modified_marc;
66
$date_modified_marc = '099d' unless $date_modified_marc;
63
my ( $m_field, $m_subfield ) = _read_marc_code($date_modified_marc);
67
my ( $m_field, $m_subfield ) = _read_marc_code($date_modified_marc);
64
die "date-modified-marc '$date_modified_marc' is not correct." unless $m_field;
68
die "date-modified-marc '$date_modified_marc' is not correct." unless $m_field;
69
die "date-modified-marc field is greated that 009, it should have a subfield."
70
  if ( $m_field > 9 && !defined $m_subfield );
71
die "date-modified-marc field is lower that 010, it should not have a subfield."
72
  if ( $m_field < 10 && defined $m_subfield );
65
die
73
die
66
"When date-created-marc and date-modified-marc are on same field, they should have distinct subfields"
74
"When date-created-marc and date-modified-marc are on same field, they should have distinct subfields"
67
  if ( $c_field eq $m_field )
75
  if ( $c_field eq $m_field )
Lines 133-139 sub updateMarc { Link Here
133
141
134
    # date created field
142
    # date created field
135
    unless ($c_marc_field) {
143
    unless ($c_marc_field) {
136
        $biblio->add_fields( new MARC::Field( $c_field, '', '' ) );
144
        if ( defined $c_subfield ) {
145
            $biblio->add_fields(
146
                new MARC::Field(
147
                    $c_field, ' ', ' ', $c_subfield => $c_db_value
148
                )
149
            );
150
        }
151
        else {
152
            $biblio->add_fields( new MARC::Field( $c_field, $c_db_value ) );
153
        }
137
        $debug and warn "[WARN] $c_field did not exist.";
154
        $debug and warn "[WARN] $c_field did not exist.";
138
        $c_marc_field = $biblio->field($c_field);
155
        $c_marc_field = $biblio->field($c_field);
139
156
Lines 142-165 sub updateMarc { Link Here
142
            $m_marc_field = $c_marc_field;
159
            $m_marc_field = $c_marc_field;
143
        }
160
        }
144
    }
161
    }
145
    if ( defined $c_subfield ) {
146
        $c_marc_field->update( $c_subfield, $c_db_value );
147
    }
148
    else {
162
    else {
149
        $c_marc_field->update($c_db_value);
163
        if ( defined $c_subfield ) {
164
            $c_marc_field->update( $c_subfield, $c_db_value );
165
        }
166
        else {
167
            $c_marc_field->update($c_db_value);
168
        }
150
    }
169
    }
151
170
152
    # date last modified field
171
    # date last modified field
153
    unless ($m_marc_field) {
172
    unless ($m_marc_field) {
154
        $biblio->add_fields( new MARC::Field( $m_field, '', '' ) );
173
        if ( defined $m_subfield ) {
174
            $biblio->add_fields(
175
                new MARC::Field(
176
                    $m_field, ' ', ' ', $m_subfield => $m_db_value
177
                )
178
            );
179
        }
180
        else {
181
            $biblio->add_fields( new MARC::Field( $m_field, $m_db_value ) );
182
        }
183
155
        $debug and warn "[WARN] $m_field did not exist.";
184
        $debug and warn "[WARN] $m_field did not exist.";
156
        $m_marc_field = $biblio->field($m_field);
185
        $m_marc_field = $biblio->field($m_field);
157
    }
186
    }
158
    if ( defined $m_subfield ) {
159
        $m_marc_field->update( $m_subfield, $m_db_value );
160
    }
161
    else {
187
    else {
162
        $m_marc_field->update($m_db_value);
188
        if ( defined $m_subfield ) {
189
            $m_marc_field->update( $m_subfield, $m_db_value );
190
        }
191
        else {
192
            $m_marc_field->update($m_db_value);
193
        }
163
    }
194
    }
164
195
165
    # apply to databse
196
    # apply to databse
Lines 222-228 UNIMARC specific. Link Here
222
Parameters:
253
Parameters:
223
    --help or -h                show this message
254
    --help or -h                show this message
224
    --verbose or -v             verbose logging
255
    --verbose or -v             verbose logging
225
    --run                       run the command else modifications will not be applyed to database
256
    --run                       run the command else modifications will not be applied to database
226
    --where                     (optional) use this to limit execution to some biblios :
257
    --where                     (optional) use this to limit execution to some biblios :
227
                                write a SQL where clause using biblio and/or biblioitems fields
258
                                write a SQL where clause using biblio and/or biblioitems fields
228
    --date-created-marc or c    (optional) date created MARC field and optional subfield,
259
    --date-created-marc or c    (optional) date created MARC field and optional subfield,
229
- 

Return to bug 9192