Copy locations table should have a 'deleted' flag

Bug #1210541 reported by Michele Morgan
52
This bug affects 9 people
Affects Status Importance Assigned to Milestone
Evergreen
Fix Released
Wishlist
Unassigned

Bug Description

Evergreen 2.3.7

When a copy location is no longer in use, it is preferable for a library to remove it from their list of locations so users don't see the defunct location and potentially choose it in error. Users with permission are able to delete copy locations in the copy locations editor. When a copy location is deleted successfully, the row is removed from asset.copy_location.

This presents several problems:

If items are coded with the location, the deletion fails. Even if the items have been deleted, it is not possible to delete the location.

The asset.copy_location.id field is referenced by action.circulation.copy_location and action.aged_circulation.copy_location. If the row in the copy_location table is deleted, circulation by location statistcs are lost.

If there were a deleted flag in the copy location table that was set to TRUE when the location was deleted, these relationships would be preserved.

The deleted flag in the copy location table should cause the location not to display in the library's list of locations. Checks should be made against undeleted items, before the deleted flag can be set to TRUE. Ideally, checks should also be made against saved copy templates.

Ben Shum (bshum)
Changed in evergreen:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
tji@sitka.bclibraries.ca (tji) wrote :

This is related to #979302.

Shelving locations used by only deleted items should be allowed to be deleted, or marked deleted. This is causing lots of confusion and trouble. The deleted items are invisible on the client. Staff can't do anything with them.

Revision history for this message
Lindsay Stratton (lstratton) wrote :

Pioneer agrees that this is a problem, and agrees that: there should be a deleted flag in the copy locations table, and that deleted locations should not display in the library's list of locations.

This crops up regularly as libraries re-arrange and update their collections.

Revision history for this message
Jason Boyer (jboyer) wrote :

I've got a squashed branch at http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/collab/jboyer/lp1210541_del_acpl that addresses this. I'd appreciate some testing (especially the db upgrade bits) and we might finally be able to wipe out some old locations.

Note: Even though there's an error message defined for trying to delete a location that's not empty, it's never displayed. The copy location editor is one of those interfaces that fails silently into the JS Console. I haven't taken the time to change that in addition to this.

Jason Boyer (jboyer)
Changed in evergreen:
assignee: nobody → Jason Boyer (jboyer)
Kathy Lussier (klussier)
Changed in evergreen:
assignee: Jason Boyer (jboyer) → nobody
tags: added: pullrequest
Revision history for this message
Blake GH (bmagic) wrote :

Im setting this up in a sandbox for bug squashing day. I had a problem seeding the database. It errored here:

040.schema.asset.sql:

CREATE OR REPLACE RULE protect_copy_location_delete AS ON DELETE TO asset.copy_location
DO INSTEAD (
UPDATE asset.copy_location SET deleted = TRUE WHERE OLD.id = asset.copy_location.id;
DELETE FROM asset.copy_location_order WHERE location = OLD.id;
DELETE FROM asset.copy_location_group_map WHERE location = OLD.id;
);

The database has not yet created asset.copy_location_order and asset.copy_location_group_map and therefore it throws an error. I edited this file and put that stanza on line 73

directly after the CREATE TABLE asset.copy_location_group_map stanza. That fixed the seeding issue.

Revision history for this message
Jason Boyer (jboyer) wrote :

Ugh, thanks for the catch. I'll update my branch. :(

Revision history for this message
Jason Boyer (jboyer) wrote :

I force-pushed an update to correct the rule placement.

Michele Morgan (mmorgan)
Changed in evergreen:
assignee: nobody → Michele Morgan (mmorgan)
Revision history for this message
Michele Morgan (mmorgan) wrote :

This is looking very promising!

There are a few issues I came across in testing. Not sure all of these should be considered showstoppers, I have listed them here in order of most to least importance (IMO) :

1. Copy templates containing deleted locations can be applied to items. The item can then be saved with the applied deleted copy location. One approach would be to prevent the saving of an item with a deleted copy location with an appropriate failure message.

2. If an undeleted item is in a deleted copy location, the item is opac visible. In theory, this should never happen, but perhaps deleted copy locations should NOT show in the opac by default.

3. If a copy location has been deleted, a new copy location with the same name cannot be added.

5. Deleted copy locations appear in Admin - Local Administration - Copy Location Groups.

6. Deleted copy locations appear in Admin - Local Administration - Copy Location Order

4. A Copy location that is referenced in a location group can be deleted.

7. A Copy location that is referenced in a circulation policy can be deleted.

Changed in evergreen:
assignee: Michele Morgan (mmorgan) → nobody
Revision history for this message
Jason Boyer (jboyer) wrote :

Good news, I found time to really look this thing over and added a bunch of changes that would have been really irritating to track down later. The branch above has been updated against master as of 12/3. I may not have time to do much testing before the 7th, so if anyone else has time, try your best to break it!

A few responses re: Michele's notes:

1: Good point, added a check for that.

2: Once the bugs have been shaken out the only way for this to happen is playing around in psql (or pgadmin, etc.). I'd rather that reporting be accurate even though this isn't necessarily the kind of thing that people would often look for. If there are strong feelings either way one more line could be added to the delete protection rule.

3, 5, 6: Should be taken care of. I made the mistake of modeling my deleted location handling too closely on bibs, which you can pull up by id, rather than call numbers, which you can't.

4,7: Anywhere that had "ON DELETE CASCADE" I tried to address in the delete rule, not many things outside of action.circulation depend on them sticking around. I intentionally didn't remove circ rules referencing a deleted location though, but if it's desired those rules could have their active flag turned off. (I didn't want there to be any mysterious changes to circ policies unless you actively make changes to them.)

Michele Morgan (mmorgan)
Changed in evergreen:
assignee: nobody → Michele Morgan (mmorgan)
Revision history for this message
Jason Boyer (jboyer) wrote :

Finally, I have had time to look into this a bit. I was missing multiple direct pcrud searches for acpl's. One more forced update to that branch and now locations should no longer show up in any interface. Feeling much better about this one.

Revision history for this message
Michele Morgan (mmorgan) wrote :

This is looking great!

I tested Jason’s fixes to the issues above and everything looks good!

I have added my signoff:

http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/mmorgan/LP1210541_Copy_Location_Deleted_Flag_signoff

One tiny issue remains in that deleted copy locations still show in the Copy Locations Order interface. I will open a separate bug for that.

Thanks for the great work, Jason!

Revision history for this message
Jason Boyer (jboyer) wrote :

I missed a one-line change in a call to pcrud.search in the copy locations order editor, that's been added and updated and it's ready to test. It should be ready to go now.

Revision history for this message
Michele Morgan (mmorgan) wrote :

Retested this and everything now looks good! Force pushed my new signoff to the branch above.

Changed in evergreen:
assignee: Michele Morgan (mmorgan) → nobody
Revision history for this message
Kathy Lussier (klussier) wrote :
tags: added: signedoff
Revision history for this message
Ben Shum (bshum) wrote :

Pushed along to master for 2.8 beta.

Changed in evergreen:
milestone: none → 2.8-beta
status: Confirmed → Fix Committed
Changed in evergreen:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.