Bill Erickson said the following on 12/06/2010 11:03 AM:
On Wed, Dec 1, 2010 at 10:03 AM, Bill Ott <[email protected]
<mailto:[email protected]>> wrote:
We sometimes encounter disputes over when exactly a new library
card was issued. Particularly when it comes to lost cards and
checkouts on reportedly lost cards. While we can gleen much of
the information from the auditor tables, it's still not an exact
science.
Long ago I mentioned the possibility of adding a timestamp to the
card. While it involves a dreaded schema change, the code to
store the data is very basic. I also added a creator, as it's
another piece of information that is sometimes hard to track down.
For your review. The attached, is against trunk.
Hi Bill. Thanks for the patch! I have a couple of comments:
1. For the date display in the registration UI, you can use something
like this to get a nice locale-friendly date:
getByName(row, 'create_date').innerHTML =
openils.Util.timeStamp( card.create_date(), {"formatLength":
"short"} );
In en-US, this would be dd/mm/yyyy
2. "create_date" should also be added to CDBI/actor.pm <http://actor.pm>.
3. As of 2.0, there is a user purging database function that scrubs
away the existence of a user. The staff version of this call requires
that any object linked to a staff user be handed over to another staff
account during purge. As such, any new fields added to the DB that
link to (what in practice would have to be) a staff account, need to
be accounted for in the purge routine. The code lives
in 999.functions.global.sql and it's called actor.usr_purge_data. In
here, there are a series of update commands grouped by schema for
convenience. Something like this should do it:
UPDATE actor.card SET creator = dest_usr WHERE creator = src_usr;
-b
--
Bill Erickson
| VP, Software Development & Integration
| Equinox Software, Inc. / Your Library's Guide to Open Source
| phone: 877-OPEN-ILS (673-6457)
| email: [email protected] <mailto:[email protected]>
| web: http://esilibrary.com
Thanks for the feedback Bill. I've attached another patch with the
noted changes, and included the SQL changes in the appropriate create
scripts.
Index: Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm (revision 18872)
+++ Open-ILS/src/perlmods/OpenILS/Application/Actor.pm (working copy)
@@ -775,6 +775,7 @@
my $session = shift;
my $patron = shift;
my $new_patron = shift;
+ my $user = shift;
my $evt;
@@ -786,7 +787,7 @@
if(ref($card) and $card->isnew()) {
$virtual_id = $card->id();
- ( $card, $evt ) = _add_card($session,$card);
+ ( $card, $evt ) = _add_card($session,$card,$user);
return (undef, $evt) if $evt;
#if(ref($patron->card)) { $patron->card($patron->card->id); }
@@ -807,8 +808,9 @@
# adds an card to the db and returns the card with new id
sub _add_card {
- my( $session, $card ) = @_;
+ my( $session, $card, $user ) = @_;
$card->clear_id();
+ $card->creator($user->id);
$logger->info("Adding new patron card ".$card->barcode);
Index: Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm
===================================================================
--- Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm (revision 18872)
+++ Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm (working copy)
@@ -141,7 +141,7 @@
__PACKAGE__->table( 'actor_card' );
__PACKAGE__->columns( Primary => qw/id/ );
-__PACKAGE__->columns( Essential => qw/usr barcode active/ );
+__PACKAGE__->columns( Essential => qw/usr barcode active creator create_date/ );
#-------------------------------------------------------------------------------
package actor::user_access_entry;
Index: Open-ILS/src/sql/Pg/005.schema.actors.sql
===================================================================
--- Open-ILS/src/sql/Pg/005.schema.actors.sql (revision 18872)
+++ Open-ILS/src/sql/Pg/005.schema.actors.sql (working copy)
@@ -286,7 +286,10 @@
id SERIAL PRIMARY KEY,
usr INT NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
barcode TEXT NOT NULL UNIQUE,
- active BOOL NOT NULL DEFAULT TRUE
+ active BOOL NOT NULL DEFAULT TRUE,
+ creator INT NOT NULL DEFAULT 1,
+ create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ CONSTRAINT actor_card_creator_fkey FOREIGN KEY (creator) REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED
);
COMMENT ON TABLE actor.card IS $$
/*
@@ -318,6 +321,7 @@
CREATE INDEX actor_card_usr_idx ON actor.card (usr);
CREATE INDEX actor_card_barcode_lower_idx ON actor.card (lower(barcode));
+
CREATE TABLE actor.org_unit_type (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
Index: Open-ILS/src/sql/Pg/999.functions.global.sql
===================================================================
--- Open-ILS/src/sql/Pg/999.functions.global.sql (revision 18872)
+++ Open-ILS/src/sql/Pg/999.functions.global.sql (working copy)
@@ -437,6 +437,7 @@
UPDATE action.fieldset SET owner = dest_usr WHERE owner = src_usr;
-- actor.*
+ UPDATE actor.card SET creator = dest_usr WHERE creator = src_usr;
DELETE FROM actor.card WHERE usr = src_usr;
DELETE FROM actor.stat_cat_entry_usr_map WHERE target_usr = src_usr;
Index: Open-ILS/web/js/ui/default/actor/user/register.js
===================================================================
--- Open-ILS/web/js/ui/default/actor/user/register.js (revision 18872)
+++ Open-ILS/web/js/ui/default/actor/user/register.js (working copy)
@@ -174,6 +174,7 @@
dojo.byId('true').cloneNode(true) :
dojo.byId('false').cloneNode(true)
);
+ getByName(row, 'create_date').innerHTML = openils.Util.timeStamp( card.create_date(), {"formatLength": "short"} );
tbody.appendChild(row);
first = false;
Index: Open-ILS/web/templates/default/actor/user/register.tt2
===================================================================
--- Open-ILS/web/templates/default/actor/user/register.tt2 (revision 18872)
+++ Open-ILS/web/templates/default/actor/user/register.tt2 (working copy)
@@ -48,17 +48,19 @@
<tr>
<th>Barcode</th>
<th>Active</th>
+ <th>Created</th>
</tr>
</thead>
<tbody id='uedit-all-cards-tbody'>
<tr id='uedit-all-cards-tr-template'>
<td><div name='barcode'></div></td>
<td><div name='active'></div></td>
+ <td><div name='create_date'></div></td>
</tr>
</tbody>
<tbody>
<tr>
- <td colspan='2' style='text-align:center;'>
+ <td colspan='3' style='text-align:right;'>
<button dojoType='dijit.form.Button' onClick='allCardsDialog.hide()' scrollOnFocus='false'>Close</button>
</td>
</tr>
Index: Open-ILS/examples/fm_IDL.xml
===================================================================
--- Open-ILS/examples/fm_IDL.xml (revision 18872)
+++ Open-ILS/examples/fm_IDL.xml (working copy)
@@ -4020,9 +4020,12 @@
<field reporter:label="Barcode" name="barcode" reporter:datatype="text"/>
<field reporter:label="Card ID" name="id" reporter:datatype="id" />
<field reporter:label="User" name="usr" reporter:datatype="link"/>
+ <field reporter:label="Creator" name="creator" reporter:datatype="link"/>
+ <field reporter:label="Create Date" name="create_date" reporter:datatype="timestamp"/>
</fields>
<links>
<link field="usr" reltype="has_a" key="id" map="" class="au"/>
+ <link field="creator" reltype="has_a" key="id" map="" class="au"/>
</links>
</class>
<class id="actsc" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::stat_cat" oils_persist:tablename="actor.stat_cat" reporter:label="User Statistical Category">