Chapter 15. Cron Jobs

Table of Contents

1. Cron Jobs
1.1. Search
1.2. Circulation
1.3. Notices
1.4. In Processing/Book Cart
1.5. Catalog
1.6. OPAC
1.7. System Administration
1.8. Deprecated scripts

1. Cron Jobs

The locations below assume a dev install which puts the crons in misc/, if you have a standard install you may want to look in bin/ for these files if you cannot find them in misc/

1.1. Search

1.1.1. Rebuild Index

Script path: misc/migration_tools/rebuild_zebra.pl

Does: Updates Zebra indexes with recently changed data.

Required by: Zebra

Frequency suggestion: every x minutes, (between 5-15 minutes) depending on performance needs

1.2. Circulation

1.2.1. Holds Queue

Script path: misc/cronjobs/holds/build_holds_queue.pl

Does: Updates holds queue report

Required by: Holds Queue Report

Frequency suggestion: every 1-4 hours

1.2.1.1. Perl Documentation

GetBibsWithPendingHoldRequests

my $biblionumber_aref = GetBibsWithPendingHoldRequests();

Return an arrayref of the biblionumbers of all bibs that have one or more unfilled hold requests.

GetPendingHoldRequestsForBib

my $requests = GetPendingHoldRequestsForBib($biblionumber);

Returns an arrayref of hashrefs to pending, unfilled hold requests on

the bib identified by $biblionumber. The following keys are present in each hashref:

  • biblionumber

  • borrowernumber

  • itemnumber

  • priority

  • branchcode

  • reservedate

  • reservenotes

  • borrowerbranch

The arrayref is sorted in order of increasing priority.

GetItemsAvailableToFillHoldRequestsForBib

my $available_items =

GetItemsAvailableToFillHoldRequestsForBib($biblionumber);

Returns an arrayref of items available to fill hold requests for the bib identified by $biblionumber. An item is available to fill a hold

request if and only if:

  • it is not on loan

  • it is not withdrawn

  • it is not marked notforloan

  • it is not currently in transit

  • it is not lost

  • it is not sitting on the hold shelf

MapItemsToHoldRequests

MapItemsToHoldRequests($hold_requests, $available_items);

CreatePickListFromItemMap

AddToHoldTargetMap

_get_branches_to_pull_from

Query system preferences to get ordered list of branches to use to fill hold requests.

1.2.2. Expired Holds

Script path: misc/cronjobs/holds/cancel_expired_holds.pl

Does: Cancels holds that have past their expiration.

Frequency suggestion: daily

1.2.3. Fines

Script path: misc/cronjobs/fines.pl

Required by: finesMode system preference

Frequency suggestion: nightly

1.2.4. Long Overdues

Script path: misc/cronjobs/longoverdue.pl

Does: allows one to specify delays for changing items to different lost statuses, and optionally charge for them.

Required by: Frequency suggestion: nightly

1.2.4.1. Perl Documentation

NAME

longoverdue.pl cron script to set lost statuses on overdue materials. Execute without options for help.

1.3. Notices

1.3.1. Message Queue

Script path: misc/cronjobs/process_message_queue.pl

Does: processes the message queue to send emails and SMS messages to users. sends outgoing emails to patrons.

Frequency suggestion: 1-4 hours

1.3.2. Advanced Notice

Script path: misc/cronjobs/advance_notices.pl

Does: prepares "pre-due" notices and "item due" notices for patrons who request them prepares notices for patrons for items just due or coming due soon. requires EnhancedMessagingPreferences to be on

Frequency suggestion: nightly

Note

This script does not actually send the notices. It queues them in the message queue for later

1.3.2.1. Perl Documentation

NAME

advance_notices.pl - cron script to put item due reminders into message queue

SYNOPSIS

./advance_notices.pl -c

or, in crontab: 0 1 * * * advance_notices.pl -c

DESCRIPTION

This script prepares pre-due and item due reminders to be sent to patrons. It queues them in the message queue, which is processed by the process_message_queue.pl cronjob. The type and timing of the messages can be configured by the patrons in their "My Alerts" tab in the OPAC.

METHODS

parse_letter

1.3.3. Overdue Notice

Script path: misc/cronjobs/overdue_notices.pl

Does: prepares messages to alert patrons of overdue messages (both via email and print)

Frequency suggestion: nightly

Note

This script does not actually send the notices. It queues them in the message queue for later or generates the HTML for later printing

1.3.3.1. Perl Documentation

NAME

overdue_notices.pl - prepare messages to be sent to patrons for overdue items

SYNOPSIS

overdue_notices.pl [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] [ -max <number of days> ] [ -csv [ <filename> ] ] [-itemscontent <field list> ]

Options:

-help brief help message

-man full documentation

-n No email will be sent

-max <days> maximum days overdue to deal with

-library <branchname> only deal with overdues from this library (repeatable : several libraries can be given)

-csv <filename> populate CSV file

-html <filename> Output html to file

-itemscontent <list of fields> item information in templates

-borcat <categorycode> category code that must be included

-borcatout <categorycode> category code that must be excluded

OPTIONS

-help Print a brief help message and exits.

-man Prints the manual page and exits.

-v Verbose. Without this flag set, only fatal errors are reported.

-n Do not send any email. Overdue notices that would have been sent to the patrons or to the admin are printed to standard out. CSV data (if the -csv flag is set) is written to standard out or to any csv filename given.

-max Items older than max days are assumed to be handled somewhere else, probably the longoverdues.pl script. They are therefore ignored by this program. No notices are sent for them, and they are not added to any CSV files. Defaults to 90 to match longoverdues.pl.

-library

select overdues for one specific library. Use the value in the branches.branchcode table. This option can be repeated in order to select overdues for a group of libraries.

-csv Produces CSV data. if -n (no mail) flag is set, then this CSV data is sent to standard out or to a filename if provided. Otherwise, only overdues that could not be emailed are sent in CSV format to the admin.

-itemscontent

comma separated list of fields that get substituted into templates in places of the <<items.content>> placeholder. This defaults to issuedate,title,barcode,author

Other possible values come from fields in the biblios, items, and issues tables.

-borcat Repetable field, that permit to select only few of patrons categories.

-borcatout

Repetable field, permis to exclude some patrons categories.

-t | --triggered

This option causes a notice to be generated if and only if an item is overdue by the number of days defined in a notice trigger.

By default, a notice is sent each time the script runs, which is suitable for less frequent run cron script, but requires syncing notice triggers with the cron schedule to ensure proper behavior. Add the --triggered option for daily cron, at the risk of no notice being generated if the cron fails to run on time.

-list-all

Default items.content lists only those items that fall in the range of the currently processing notice. Choose list-all to include all overdue items in the list (limited by -max setting).

DESCRIPTION

This script is designed to alert patrons and administrators of overdue items.

Configuration

This script pays attention to the overdue notice configuration performed in the "Overdue notice/status triggers" section of the "Tools" area of the staff interface to Koha. There, you can choose which letter templates are sent out after a configurable number of days to patrons of each library. More information about the use of this section of Koha is available in the Koha manual.

The templates used to craft the emails are defined in the "Tools: Notices" section of the staff interface to Koha.

Outgoing emails

Typically, messages are prepared for each patron with overdue items. Messages for whom there is no email address on file are collected and sent as attachments in a single email to each library administrator, or if that is not set, then to the email address in the "KohaAdminEmailAddress" system preference.

These emails are staged in the outgoing message queue, as are messages produced by other features of Koha. This message queue must be processed regularly by the misc/cronjobs/process_message_queue.pl program.

In the event that the "-n" flag is passed to this program, no emails are sent. Instead, messages are sent on standard output from this program. They may be redirected to a file if desired.

Templates

Templates can contain variables enclosed in double angle brackets like <<this>>. Those variables will be replaced with values specific to the overdue items or relevant patron. Available variables are:

<<bib>>

the name of the library

<<items.content>>

one line for each item, each line containing a tab separated list of title, author, barcode, issuedate

<<borrowers.*>>

any field from the borrowers table

<<branches.*>>

any field from the branches table

CSV output

The "-csv" command line option lets you specify a file to which overdues data should be output in CSV format.

With the "-n" flag set, data about all overdues is written to the file. Without that flag, only information about overdues that were unable to be sent directly to the patrons will be written. In other words, this CSV file replaces the data that is typically sent to the administrator email address.

USAGE EXAMPLES

"overdue_notices.pl" - In this most basic usage, with no command line arguments, all libraries are procesed individually, and notices are prepared for all patrons with overdue items for whom we have email addresses. Messages for those patrons for whom we have no email address are sent in a single attachment to the library administrator's email address, or to the address in the KohaAdminEmailAddress system preference.

"overdue_notices.pl -n -csv /tmp/overdues.csv" - sends no email and populates /tmp/overdues.csv with information about all overdue items.

"overdue_notices.pl -library MAIN max 14" - prepare notices of overdues in the last 2 weeks for the MAIN library.

SEE ALSO

The misc/cronjobs/advance_notices.pl program allows you to send messages to patrons in advance of thier items becoming due, or to alert them of items that have just become due.

INTERNAL METHODS

These methods are internal to the operation of overdue_notices.pl.

parse_letter

parses the letter template, replacing the placeholders with data specific to this patron, biblio, or item

named parameters:

letter - required hashref

borrowernumber - required integer

substitute - optional hashref of other key/value pairs that should be substituted in the letter content

returns the "letter" hashref, with the content updated to reflect the substituted keys and values.

prepare_letter_for_printing

returns a string of text appropriate for printing in the event that an overdue notice will not be sent to the patron's email address. Depending on the desired output format, this may be a CSV string, or a human-readable representation of the notice.

required parameters:

letter

borrowernumber

optional parameters:

outputformat

1.3.4. Print Hold Notices

Script path: misc/cronjobs/gather_print_notices.pl

Does: looks through the message queue for hold notices that didn't go through because the patron didn't have an email address and generates a print notice

Frequency suggestion: nightly

1.4. In Processing/Book Cart

Script path: misc/cronjobs/cart_to_shelf.pl

Does: Updates all items with a location of CART to the item's permanent location.

Required by: NewItemsDefaultLocation, InProcessingToShelvingCart, & ReturnToShelvingCart system preferences

Frequency suggestion: hourly

1.4.1. Perl Documentation

NAME

cart_to_shelf.pl cron script to set items with location of CART to original shelving location after X hours. Execute without options for help.

1.5. Catalog

1.5.1. Check URLs

Script path: misc/cronjobs/check-url.pl

Does: checks URLs in 856$u field. Script output can now be formatted in CSV or HTML. The HTML version links directly to MARC biblio record editor.

Frequency suggestion: monthly

Learn more: http://wiki.koha-community.org/wiki/Check-url_enhancements

1.5.1.1. Perl Documentation

NAME

C4::URL::Checker - base object for checking URL stored in Koha DB

SYNOPSIS

use C4::URL::Checker;

        my $checker = C4::URL::Checker->new( );
        $checker->{ host_default } = 'http://mylib.kohalibrary.com';
        my $checked_urls = $checker->check_biblio( 123 );
        foreach my $url ( @$checked_urls ) {
            print "url:        ", $url->{ url       A }, "\n",
                  "is_success: ", $url->{ is_success }, "\n",
                  "status:     ", $url->{ status     }, "\n";
        } 

FUNCTIONS

new

Create a URL Checker. The returned object can be used to set default host variable :

my $checker = C4::URL::Checker->new( );
        $checker->{ host_default } = 'http://mylib.kohalibrary.com'; 

check_biblio

Check all URL from a biblio record. Returns a pointer to an array containing all URLs with checking for each of them.

 my $checked_urls = $checker->check_biblio( 123 ); 

With 2 URLs, the returned array will look like that:

     [
           {
             'url' => 'http://mylib.tamil.fr/img/62265_0055B.JPG',
             'is_success' => 1,
             'status' => 'ok'
           },
           {
             'url' => 'http://mylib.tamil.fr//img/62265_0055C.JPG',
             'is_success' => 0,
             'status' => '404 - Page not found'
           }
         ], 

NAME

check-url.pl - Check URLs from 856$u field.

USAGE

check-url.pl [--verbose|--help] [--host=http://default.tld]

Scan all URLs found in 856$u of bib records and display if resources are available or not.

PARAMETERS

--host=http://default.tld

Server host used when URL doesn't have one, ie doesn't begin with 'http:'. For example, if --host=http://www.mylib.com, then when 856$u contains 'img/image.jpg', the url checked is: http://www.mylib.com/image.jpg'.

--verbose|-v

Outputs both successful and failed URLs.

--html

Formats output in HTML. The result can be redirected to a file accessible by http. This way, it's possible to link directly to biblio record in edit mode. With this parameter --host-pro is required.

--host-pro=http://koha-pro.tld

Server host used to link to biblio record editing page.

--help|-h

Print this help page.

1.5.2. Merge Authorities

Script path: misc/migration_tools/merge_authorities.pl

Does: Updates biblio data with changes to authorities records

Required by: dontmerge system preference

Frequency suggestion: nightly

1.5.3. Serials Update

Script path: misc/cronjobs/serialsUpdate.pl

Does: checks if there is a "late" issue on active subscriptions, and if there is, the script will set it as late, and add the next one as expected.

Frequency suggestion: nightly

1.6. OPAC

1.6.1. RSS Feeds

Script path: misc/cronjobs/rss/rss.pl

Does: Produces an RSS XML document for any SQL query (not used for search results RSS feed). Learn more.

Frequency suggestion: hourly

1.6.2. Authorities Browser

Script path: misc/cronjobs/build_browser_and_cloud.pl

Does: Generate content for authories browse in OPAC

Required by: OpacBrowser system preference

1.6.3. Subject/Author Clouds

Script path: misc/cronjobs/cloud-kw.pl

Does: Generates HTML keywords clouds from Koha Zebra indexes. misc/cronjobs/cloud-sample.conf has a sample of how this script operates.

Frequency: This is the type of script you can run once a month or so, the content generated isn't going to change very much over time.

1.6.3.1. Perl Documentation

NAME

cloud-kw.pl - Creates HTML keywords clouds from Koha Zebra Indexes

USAGE

cloud-kw.pl [--verbose|--help] --conf=cloud.conf

Creates multiple HTML files containing kewords cloud with top terms sorted by their logarithmic weight. cloud.conf is a YAML configuration file driving cloud generation process.

PARAMETERS

--conf=configuration file

Specify configuration file name

--verbose|-v

Enable script verbose mode.

--help|-h

Print this help page.

CONFIGURATION

Configuration file looks like that:

  ---
         # Koha configuration file for a specific installation
         # If not present, defaults to KOHA_CONF
         KohaConf: /home/koha/mylibray/etc/koha-conf.xml
         # Zebra index to scan
         ZebraIndex: Author
         # Koha index used to link found kewords with an opac search URL
         KohaIndex: au
         # Number of top keyword to use for the cloud
         Count: 50
         # Include CSS style directives with the cloud
         # This could be used as a model and then CSS directives are
         # put in the appropriate CSS file directly.
         Withcss: Yes
         # HTML file where to output the cloud
         Output: /home/koha/mylibrary/koharoot/koha-tmpl/cloud-author.html
        ---
         KohaConf: /home/koha/yourlibray/etc/koha-conf.xml
         ZebraIndex: Subject
         KohaIndex: su
         Count: 200
         Withcss: no
         Output: /home/koha/yourlibrary/koharoot/koha-tmpl/cloud-subject.html

IMPROVEMENTS

Generated top terms have more informations than those outputted from the time being. Some parameters could be easily added to improve this script:

WithCount

In order to output terms with the number of occurences they have been found in Koha Catalogue by Zebra.

CloudLevels

Number of levels in the cloud. Now 24 levels are hardcoded.

Weighting

Weighting method used to distribute terms in the cloud. We could have two values: Logarithmic and Linear. Now it's Logarithmic by default.

Order

Now terms are outputted in the lexical order. They could be sorted by their weight.

1.7. System Administration

1.7.1. Clean up Database

Script path: misc/cronjobs/cleanup_database.pl

Does: Truncates the sessions table and cleans out old zebraqueue entries.

1.8. Deprecated scripts

These should not be run without modification:

Script path: misc/cronjobs/update_items.pl

Script path:misc/cronjobs/smsoverdues.pl

Script path:misc/cronjobs/notifyMailsOp.pl

Script path:misc/cronjobs/reservefix.pl

Script path:misc/cronjobs/zebraqueue_start.pl

Script path:misc/cronjobs/j2a.pl