@@ -, +, @@ - a new DB field items.new. - a new page to configure this new status (tools/toggle_new_status.pl). - a new cronjob script (misc/cronjob/toggle_new_status.pl). - to know easily what are the new items (with a simple sql query). - to display an icon in the search results. - issuing rules can be adapt for new items. Automatically (using the cronjob script), the status change (depending the configuration) and the item can be issued, for example. - a RSS/Atom feeds can be created on these new items. - log in with a librarian having the tools > items_batchmod permission. - navigate to Home > Tools > Toggle new status - click on the edit button - there are 3 "blocks": * duration: the duration during an item is considered as new. * conditions: the status will change only if the conditions are meet. * substitutions: if there is no substitution, no action will be done. You can add some change to apply to the matching items. E.g. ccode=3 new='' If the value is an empty string (in other words, the input does not contain anything), the field will be deleted. You can create as many rules as you want. - test the interface : add/remove rule, conditions, substitutions, submit the form, edit, etc. (There is a looot of JS everywhere, so certainly a looot of bugs...). - when you have your rules defined, you can now launch the cronjob script without any parameter. A report will be displayed with the matching itemnumber and the substitutions to apply. Verify results are consistent. - launch the script with the -c argument and verify values have been modified depending the substitution rules. --- C4/Items.pm | 91 +++++- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 17 ++ .../intranet-tmpl/prog/en/css/staff-global.css | 29 ++ .../en/modules/help/tools/toggle_new_status.tt | 45 +++ .../prog/en/modules/tools/toggle_new_status.tt | 294 ++++++++++++++++++++ .../prog/en/modules/tools/tools-home.tt | 5 + misc/cronjobs/toggle_new_status.pl | 106 +++++++ tools/toggle_new_status.pl | 116 ++++++++ 9 files changed, 704 insertions(+), 1 deletion(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt create mode 100755 misc/cronjobs/toggle_new_status.pl create mode 100755 tools/toggle_new_status.pl --- a/C4/Items.pm +++ a/C4/Items.pm @@ -461,6 +461,7 @@ my %default_values_for_mod_from_marc = ( location => undef, permanent_location => undef, materials => undef, + new => undef, notforloan => 0, paidfor => undef, price => undef, @@ -2147,7 +2148,8 @@ sub _koha_new_item { enumchron = ?, more_subfields_xml = ?, copynumber = ?, - stocknumber = ? + stocknumber = ?, + new = ? "; my $sth = $dbh->prepare($query); my $today = C4::Dates->today('iso'); @@ -2190,6 +2192,7 @@ sub _koha_new_item { $item->{'more_subfields_xml'}, $item->{'copynumber'}, $item->{'stocknumber'}, + $item->{'new'}, ); my $itemnumber; @@ -2870,4 +2873,90 @@ sub PrepareItemrecordDisplay { }; } +=head2 columns + + my @columns = C4::Items::columns(); + +Returns an array of items' table columns on success, +and an empty array on failure. + +=cut + +sub columns { + # Pure ANSI SQL goodness. + my $sql = 'SELECT * FROM items WHERE 1=0;'; + + # Get the database handle. + my $dbh = C4::Context->dbh; + + # Run the SQL statement to load STH's readonly properties. + my $sth = $dbh->prepare($sql); + my $rv = $sth->execute(); + + # This only fails if the table doesn't exist. + # This will always be called AFTER an install or upgrade, + # so borrowers will exist! + my @data; + if ($sth->{NUM_OF_FIELDS}>0) { + @data = @{$sth->{NAME}}; + } + else { + @data = (); + } + return @data; +} + +sub ToggleNewStatus { + my ( $params ) = @_; + my @rules = @{ $params->{rules} }; + my $report_only = $params->{report_only}; + + my $dbh = C4::Context->dbh; + my @errors; + my @items_columns = C4::Items::columns; + my $report; + for my $rule ( @rules ) { + my $duration = $rule->{duration}; + my $conditions = $rule->{conditions}; + my $substitutions = $rule->{substitutions}; + my @params; + + my $query = q|SELECT biblionumber, itemnumber FROM items WHERE 1 |; + for my $condition ( @$conditions ) { + if ( grep {/^$condition->{field}$/} @items_columns ) { + if ( $condition->{value} =~ /\|/ ) { + my @values = split /\|/, $condition->{value}; + $query .= qq| AND $condition->{field} IN (| + . join( ',', ('?') x scalar @values ) + . q|)|; + push @params, @values; + } else { + $query .= qq| AND $condition->{field} = ?|; + push @params, $condition->{value}; + } + } + } + if ( defined $duration ) { + $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; + push @params, $duration; + } + my $sth = $dbh->prepare($query); + $sth->execute( @params ); + while ( my $values = $sth->fetchrow_hashref ) { + my $biblionumber = $values->{biblionumber}; + my $itemnumber = $values->{itemnumber}; + my $item = C4::Items::GetItem( $itemnumber ); + for my $substitution ( @$substitutions ) { + next unless $substitution->{field}; + C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber ) + unless $report_only; + push @{ $report->{$itemnumber} }, $substitution; + } + } + } + + return $report; +} + + 1; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -917,6 +917,7 @@ CREATE TABLE `deleteditems` ( `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h) `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t) `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i) + `new` VARCHAR(32) DEFAULT NULL, -- new flag PRIMARY KEY (`itemnumber`), KEY `delitembarcodeidx` (`barcode`), KEY `delitemstocknumberidx` (`stocknumber`), @@ -1211,6 +1212,7 @@ CREATE TABLE `items` ( -- holdings/item information `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h) `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t) `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i) + `new` VARCHAR(32) DEFAULT NULL, -- new flag PRIMARY KEY (`itemnumber`), UNIQUE KEY `itembarcodeidx` (`barcode`), KEY `itemstocknumberidx` (`stocknumber`), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -8083,6 +8083,23 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } + + + + + +$DBversion = "3.15.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(q{ + ALTER TABLE `items` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`; + }); + $dbh->do(q{ + ALTER TABLE `deleteditems` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`; + }); + print "Upgrade to $DBversion done (Bug 11012: Adds field 'new' in items and deleteditems tables)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -2725,3 +2725,32 @@ span.browse-button { font-size:0.8em; padding:0.5em; } + +/* Tools > toggle_new_status */ +div.rules { + display: block; +} +div#new_rule, div.rule { + background-color: #F4F8F9; + border: 2px solid #B9D8D9; + border-radius: 5px; + margin: .3em; + padding: .3em; +} + +div.duration, div.blocks { + border: 2px solid #B9D8D9; + border-radius: 5px 5px 5px 5px; + margin: .3em; + padding: 0 .3em .3em .3em; +} + +div.duration h5, div.blocks h5 { + padding-bottom: 4px; + padding-left: 0.2em; + background-color: #E6F0F2; + border-radius: 1px; +} +div.duration span, div.blocks div { + display:block; +} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt @@ -0,0 +1,45 @@ +[% INCLUDE 'help-top.inc' %] +
This configuration page allows to configure the rules for the toggle new status cronjob script.
+ +Libraries can manage the 'new' status for items. With this script, it will be possible to:
+
There are 3 values to define:
+This value corresponds to the duration an item is considered as new.
+Conditions should be defined if you want to test some values before to substitute fields in the items.
+They are cumulatives but you can separate with a pipe '|' for a field with several values.
+Substitutions are changes to apply to the matching items.
+At least one substitution must be defined, else there is no sense to launch the script.
+If the value is an empty string, the field will be deleted.
+You want to remove the items.new value for items created 10 days ago:
+You want to change the items.ccode=1 to items.ccode=2 for items created 7 days ago. +
The cronjob script is misc/cronjobs/toggle_new_status.pl.
+Try the -h parameter in order to see the help.
+Without any parameter, the script will be launched in a dry-run mode. If the -c (or --confirm) flag is given, the script will apply the changes.
+ +[% INCLUDE 'help-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt @@ -0,0 +1,294 @@ +[% INCLUDE 'doc-head-open.inc' %] +