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

(-)a/C4/Items.pm (-3 / +3 lines)
Lines 474-480 sub _build_default_values_for_mod_marc { Link Here
474
        location                 => undef,
474
        location                 => undef,
475
        permanent_location       => undef,
475
        permanent_location       => undef,
476
        materials                => undef,
476
        materials                => undef,
477
        new                      => undef,
477
        new_status               => undef,
478
        notforloan               => 0,
478
        notforloan               => 0,
479
        # paidfor => undef, # commented, see bug 12817
479
        # paidfor => undef, # commented, see bug 12817
480
        price                    => undef,
480
        price                    => undef,
Lines 2201-2207 sub _koha_new_item { Link Here
2201
            more_subfields_xml  = ?,
2201
            more_subfields_xml  = ?,
2202
            copynumber          = ?,
2202
            copynumber          = ?,
2203
            stocknumber         = ?,
2203
            stocknumber         = ?,
2204
            new                 = ?
2204
            new_status          = ?
2205
          ";
2205
          ";
2206
    my $sth = $dbh->prepare($query);
2206
    my $sth = $dbh->prepare($query);
2207
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
2207
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
Lines 2245-2251 sub _koha_new_item { Link Here
2245
            $item->{'more_subfields_xml'},
2245
            $item->{'more_subfields_xml'},
2246
            $item->{'copynumber'},
2246
            $item->{'copynumber'},
2247
            $item->{'stocknumber'},
2247
            $item->{'stocknumber'},
2248
            $item->{'new'},
2248
            $item->{'new_status'},
2249
    );
2249
    );
2250
2250
2251
    my $itemnumber;
2251
    my $itemnumber;
(-)a/installer/data/mysql/atomicupdate/bug_xxxx-change_new_to_new_status.sql (+3 lines)
Line 0 Link Here
1
ALTER TABLE items CHANGE new new_status VARCHAR(32) NULL;
2
ALTER TABLE deleteditems CHANGE new new_status VARCHAR(32) NULL;
3
UPDATE systempreferences SET value=REPLACE(value, '"items.new"', '"items.new_status"') WHERE variable="automatic_item_modification_by_age_configuration";
(-)a/installer/data/mysql/kohastructure.sql (-2 / +2 lines)
Lines 971-977 CREATE TABLE `deleteditems` ( Link Here
971
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
971
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
972
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
972
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
973
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
973
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
974
  `new` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
974
  `new_status` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
975
  PRIMARY KEY  (`itemnumber`),
975
  PRIMARY KEY  (`itemnumber`),
976
  KEY `delitembarcodeidx` (`barcode`),
976
  KEY `delitembarcodeidx` (`barcode`),
977
  KEY `delitemstocknumberidx` (`stocknumber`),
977
  KEY `delitemstocknumberidx` (`stocknumber`),
Lines 1267-1273 CREATE TABLE `items` ( -- holdings/item information Link Here
1267
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1267
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1268
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1268
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1269
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1269
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1270
  `new` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
1270
  `new_status` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
1271
  PRIMARY KEY  (`itemnumber`),
1271
  PRIMARY KEY  (`itemnumber`),
1272
  UNIQUE KEY `itembarcodeidx` (`barcode`),
1272
  UNIQUE KEY `itembarcodeidx` (`barcode`),
1273
  KEY `itemstocknumberidx` (`stocknumber`),
1273
  KEY `itemstocknumberidx` (`stocknumber`),
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-29 / +28 lines)
Lines 18-30 $dbh->{RaiseError} = 1; Link Here
18
18
19
$dbh->do(q|
19
$dbh->do(q|
20
    DELETE FROM marc_subfield_structure
20
    DELETE FROM marc_subfield_structure
21
    WHERE kohafield = 'items.new' OR kohafield = 'items.stocknumber'
21
    WHERE kohafield = 'items.new_status' OR kohafield = 'items.stocknumber'
22
|);
22
|);
23
23
24
my $new_tagfield = 'i';
24
my $new_tagfield = 'i';
25
$dbh->do(qq|
25
$dbh->do(qq|
26
    INSERT INTO marc_subfield_structure(tagfield, tagsubfield, kohafield, frameworkcode)
26
    INSERT INTO marc_subfield_structure(tagfield, tagsubfield, kohafield, frameworkcode)
27
    VALUES ( 952, '$new_tagfield', 'items.new', '' )
27
    VALUES ( 952, '$new_tagfield', 'items.new_status', '' )
28
|);
28
|);
29
29
30
my $record = MARC::Record->new();
30
my $record = MARC::Record->new();
Lines 39-58 my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem( Link Here
39
    {
39
    {
40
        homebranch => 'CPL',
40
        homebranch => 'CPL',
41
        holdingbranch => 'CPL',
41
        holdingbranch => 'CPL',
42
        new => 'new_value',
42
        new_status => 'new_value',
43
        ccode => 'FIC',
43
        ccode => 'FIC',
44
    },
44
    },
45
    $biblionumber
45
    $biblionumber
46
);
46
);
47
47
48
my $item = C4::Items::GetItem( $itemnumber );
48
my $item = C4::Items::GetItem( $itemnumber );
49
is ( $item->{new}, 'new_value', q|AddItem insert the 'new' field| );
49
is ( $item->{new_status}, 'new_value', q|AddItem insert the 'new_status' field| );
50
50
51
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', '');
51
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', '');
52
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
52
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
53
is( $marc_item->subfield($tagfield, $new_tagfield), 'new_value', q|Koha mapping is correct|);
53
is( $marc_item->subfield($tagfield, $new_tagfield), 'new_value', q|Koha mapping is correct|);
54
54
55
# Update the items.new field if items.ccode eq 'FIC' => should be updated
55
# Update the items.new_status field if items.ccode eq 'FIC' => should be updated
56
my @rules = (
56
my @rules = (
57
    {
57
    {
58
        conditions => [
58
        conditions => [
Lines 63-69 my @rules = ( Link Here
63
        ],
63
        ],
64
        substitutions => [
64
        substitutions => [
65
            {
65
            {
66
                field => 'items.new',
66
                field => 'items.new_status',
67
                value => 'updated_value',
67
                value => 'updated_value',
68
             },
68
             },
69
        ],
69
        ],
Lines 74-84 my @rules = ( Link Here
74
C4::Items::ToggleNewStatus( { rules => \@rules } );
74
C4::Items::ToggleNewStatus( { rules => \@rules } );
75
75
76
my $modified_item = C4::Items::GetItem( $itemnumber );
76
my $modified_item = C4::Items::GetItem( $itemnumber );
77
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is updated|);
77
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is updated|);
78
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
78
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
79
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is updated| );
79
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| );
80
80
81
# Update the items.new field if items.ccode eq 'DONT_EXIST' => should not be updated
81
# Update the items.new_status field if items.ccode eq 'DONT_EXIST' => should not be updated
82
@rules = (
82
@rules = (
83
    {
83
    {
84
        conditions => [
84
        conditions => [
Lines 89-95 is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew Link Here
89
        ],
89
        ],
90
        substitutions => [
90
        substitutions => [
91
            {
91
            {
92
                field => 'items.new',
92
                field => 'items.new_status',
93
                value => 'new_updated_value',
93
                value => 'new_updated_value',
94
             },
94
             },
95
        ],
95
        ],
Lines 100-108 is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew Link Here
100
C4::Items::ToggleNewStatus( { rules => \@rules } );
100
C4::Items::ToggleNewStatus( { rules => \@rules } );
101
101
102
$modified_item = C4::Items::GetItem( $itemnumber );
102
$modified_item = C4::Items::GetItem( $itemnumber );
103
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is not updated|);
103
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|);
104
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
104
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
105
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is not updated| );
105
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| );
106
106
107
# Play with age
107
# Play with age
108
$item = C4::Items::GetItem( $itemnumber );
108
$item = C4::Items::GetItem( $itemnumber );
Lines 122-128 $item = C4::Items::GetItem( $itemnumber ); Link Here
122
        ],
122
        ],
123
        substitutions => [
123
        substitutions => [
124
            {
124
            {
125
                field => 'items.new',
125
                field => 'items.new_status',
126
                value => 'new_updated_value',
126
                value => 'new_updated_value',
127
             },
127
             },
128
        ],
128
        ],
Lines 131-155 $item = C4::Items::GetItem( $itemnumber ); Link Here
131
);
131
);
132
C4::Items::ToggleNewStatus( { rules => \@rules } );
132
C4::Items::ToggleNewStatus( { rules => \@rules } );
133
$modified_item = C4::Items::GetItem( $itemnumber );
133
$modified_item = C4::Items::GetItem( $itemnumber );
134
is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new value is not updated|);
134
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|);
135
135
136
$rules[0]->{age} = 5;
136
$rules[0]->{age} = 5;
137
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
137
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
138
C4::Items::ToggleNewStatus( { rules => \@rules } );
138
C4::Items::ToggleNewStatus( { rules => \@rules } );
139
$modified_item = C4::Items::GetItem( $itemnumber );
139
$modified_item = C4::Items::GetItem( $itemnumber );
140
is( $modified_item->{new}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new value is updated|);
140
is( $modified_item->{new_status}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|);
141
141
142
$rules[0]->{age} = '';
142
$rules[0]->{age} = '';
143
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
143
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
144
C4::Items::ToggleNewStatus( { rules => \@rules } );
144
C4::Items::ToggleNewStatus( { rules => \@rules } );
145
$modified_item = C4::Items::GetItem( $itemnumber );
145
$modified_item = C4::Items::GetItem( $itemnumber );
146
is( $modified_item->{new}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new value is updated|);
146
is( $modified_item->{new_status}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|);
147
147
148
$rules[0]->{age} = undef;
148
$rules[0]->{age} = undef;
149
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
149
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
150
C4::Items::ToggleNewStatus( { rules => \@rules } );
150
C4::Items::ToggleNewStatus( { rules => \@rules } );
151
$modified_item = C4::Items::GetItem( $itemnumber );
151
$modified_item = C4::Items::GetItem( $itemnumber );
152
is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new value is updated|);
152
is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|);
153
153
154
# Field deletion
154
# Field deletion
155
@rules = (
155
@rules = (
Lines 162-168 is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = u Link Here
162
        ],
162
        ],
163
        substitutions => [
163
        substitutions => [
164
            {
164
            {
165
                field => 'items.new',
165
                field => 'items.new_status',
166
                value => '',
166
                value => '',
167
             },
167
             },
168
        ],
168
        ],
Lines 173-181 is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = u Link Here
173
C4::Items::ToggleNewStatus( { rules => \@rules } );
173
C4::Items::ToggleNewStatus( { rules => \@rules } );
174
174
175
$modified_item = C4::Items::GetItem( $itemnumber );
175
$modified_item = C4::Items::GetItem( $itemnumber );
176
is( $modified_item->{new}, '', q|ToggleNewStatus: The new value is empty|);
176
is( $modified_item->{new_status}, '', q|ToggleNewStatus: The new_status value is empty|);
177
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
177
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
178
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new field is removed from the item marc| );
178
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| );
179
179
180
# conditions multiple
180
# conditions multiple
181
@rules = (
181
@rules = (
Lines 192-198 is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th Link Here
192
        ],
192
        ],
193
        substitutions => [
193
        substitutions => [
194
            {
194
            {
195
                field => 'items.new',
195
                field => 'items.new_status',
196
                value => 'new_value',
196
                value => 'new_value',
197
             },
197
             },
198
        ],
198
        ],
Lines 203-209 is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th Link Here
203
C4::Items::ToggleNewStatus( { rules => \@rules } );
203
C4::Items::ToggleNewStatus( { rules => \@rules } );
204
204
205
$modified_item = C4::Items::GetItem( $itemnumber );
205
$modified_item = C4::Items::GetItem( $itemnumber );
206
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new value is updated|);
206
is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|);
207
207
208
@rules = (
208
@rules = (
209
    {
209
    {
Lines 219-225 is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: Link Here
219
        ],
219
        ],
220
        substitutions => [
220
        substitutions => [
221
            {
221
            {
222
                field => 'items.new',
222
                field => 'items.new_status',
223
                value => 'new_updated_value',
223
                value => 'new_updated_value',
224
             },
224
             },
225
        ],
225
        ],
Lines 230-236 is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: Link Here
230
C4::Items::ToggleNewStatus( { rules => \@rules } );
230
C4::Items::ToggleNewStatus( { rules => \@rules } );
231
231
232
$modified_item = C4::Items::GetItem( $itemnumber );
232
$modified_item = C4::Items::GetItem( $itemnumber );
233
is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new value is not updated|);
233
is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|);
234
234
235
@rules = (
235
@rules = (
236
    {
236
    {
Lines 246-252 is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: Link Here
246
        ],
246
        ],
247
        substitutions => [
247
        substitutions => [
248
            {
248
            {
249
                field => 'items.new',
249
                field => 'items.new_status',
250
                value => 'new_updated_value',
250
                value => 'new_updated_value',
251
             },
251
             },
252
        ],
252
        ],
Lines 257-263 is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: Link Here
257
C4::Items::ToggleNewStatus( { rules => \@rules } );
257
C4::Items::ToggleNewStatus( { rules => \@rules } );
258
258
259
$modified_item = C4::Items::GetItem( $itemnumber );
259
$modified_item = C4::Items::GetItem( $itemnumber );
260
is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new value is updated|);
260
is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|);
261
261
262
@rules = (
262
@rules = (
263
    {
263
    {
Lines 269-275 is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu Link Here
269
        ],
269
        ],
270
        substitutions => [
270
        substitutions => [
271
            {
271
            {
272
                field => 'items.new',
272
                field => 'items.new_status',
273
                value => 'another_new_updated_value',
273
                value => 'another_new_updated_value',
274
             },
274
             },
275
        ],
275
        ],
Lines 280-283 is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu Link Here
280
C4::Items::ToggleNewStatus( { rules => \@rules } );
280
C4::Items::ToggleNewStatus( { rules => \@rules } );
281
281
282
$modified_item = C4::Items::GetItem( $itemnumber );
282
$modified_item = C4::Items::GetItem( $itemnumber );
283
is( $modified_item->{new}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
283
is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
284
- 

Return to bug 16004