Bug 9032: enforce consistent behavior when deleting lists
DelShelf deletes a list regardless whether it is private, shared or public. HandleDelBorrower had another approach, trying to save shared and public lists by setting the owner to NULL. This patch makes both routines behave consistently. A new report 11889 has been opened to discuss the 'disowning' feature. NOTE: I did not add a db revision here to handle possible cases of lists without owner in the current data. Such public (or shared) lists can still be used without any problem. Bug 11889 and a new planned report for a lists management tool will address this topic further on. After that, all goals of umbrella report 7310 should be realized. Test plan: Create a list P1 with user1 that allows adding by other users. Add a patron (user2). Login as user2 and create some lists, add some items. Let user2 add some entries to P1 too. Delete patron user2. Verify that his lists are gone, but his entries in P1 are kept (nullified). Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
parent
d1244ad33f
commit
4c877bb7c9
1 changed files with 16 additions and 25 deletions
|
@ -631,8 +631,8 @@ sub ShelvesMax {
|
|||
|
||||
When a member is deleted (DelMember in Members.pm), you should call me first.
|
||||
This routine deletes/moves lists and entries for the deleted member/borrower.
|
||||
You could just delete everything (and lose more than you want), but instead we
|
||||
now try to save all public/shared stuff and keep others happy.
|
||||
Lists owned by the borrower are deleted, but entries from the borrower to
|
||||
other lists are kept.
|
||||
|
||||
=cut
|
||||
|
||||
|
@ -641,31 +641,22 @@ sub HandleDelBorrower {
|
|||
my $query;
|
||||
my $dbh = C4::Context->dbh;
|
||||
|
||||
#Delete shares of this borrower (not lists !)
|
||||
#Although this would be done later via the FK cascaded delete, we do it now.
|
||||
#Because it makes the following delete statement on shelves more meaningful.
|
||||
$query="DELETE FROM virtualshelfshares WHERE borrowernumber=?";
|
||||
#Delete all lists and all shares of this borrower
|
||||
#Consistent with the approach Koha uses on deleting individual lists
|
||||
#Note that entries in virtualshelfcontents added by this borrower to
|
||||
#lists of others will be handled by a table constraint: the borrower
|
||||
#is set to NULL in those entries.
|
||||
$query="DELETE FROM virtualshelves WHERE owner=?";
|
||||
$dbh->do($query,undef,($borrower));
|
||||
|
||||
#Delete private lists without owner that now have no shares anymore
|
||||
$query="DELETE vs.* FROM virtualshelves vs LEFT JOIN virtualshelfshares sh USING (shelfnumber) WHERE category=1 AND vs.owner IS NULL AND sh.shelfnumber IS NULL";
|
||||
$dbh->do($query);
|
||||
|
||||
#Change owner for private lists which have shares
|
||||
$query="UPDATE virtualshelves LEFT JOIN virtualshelfshares sh USING (shelfnumber) SET owner=NULL where owner=? AND category=1 AND sh.borrowernumber IS NOT NULL";
|
||||
$dbh->do($query,undef,($borrower));
|
||||
|
||||
#Delete unshared private lists
|
||||
$query="DELETE FROM virtualshelves WHERE owner=? AND category=1";
|
||||
$dbh->do($query,undef,($borrower));
|
||||
|
||||
#Handle public lists owned by borrower
|
||||
$query="UPDATE virtualshelves SET owner=NULL WHERE owner=? AND category=2";
|
||||
$dbh->do($query,undef,($borrower));
|
||||
|
||||
#Handle entries added by borrower to lists of others
|
||||
$query="UPDATE virtualshelfcontents SET borrowernumber=NULL WHERE borrowernumber=?";
|
||||
$dbh->do($query,undef,($borrower));
|
||||
#NOTE:
|
||||
#We could handle the above deletes via a constraint too.
|
||||
#But a new BZ report 11889 has been opened to discuss another approach.
|
||||
#Instead of deleting we could also disown lists (based on a pref).
|
||||
#In that way we could save shared and public lists.
|
||||
#The current table constraints support that idea now.
|
||||
#This pref should then govern the results of other routines such as
|
||||
#DelShelf too.
|
||||
}
|
||||
|
||||
=head2 AddShare
|
||||
|
|
Loading…
Reference in a new issue