[open-ils-commits] r10926 - in branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application: . Cat

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Oct 27 17:49:14 EDT 2008


Author: erickson
Date: 2008-10-27 17:49:05 -0400 (Mon, 27 Oct 2008)
New Revision: 10926

Modified:
   branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
   branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm
   branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm
Log:
moving some more code out to the common packages

Modified: branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm
===================================================================
--- branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm	2008-10-27 21:26:16 UTC (rev 10925)
+++ branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/AssetCommon.pm	2008-10-27 21:49:05 UTC (rev 10926)
@@ -1,5 +1,6 @@
 package OpenILS::Application::Cat::AssetCommon;
 use strict; use warnings;
+use OpenILS::Application::Cat::BibCommon;
 use OpenILS::Utils::CStoreEditor q/:funcs/;
 use OpenSRF::Utils::Logger qw($logger);
 use OpenILS::Application::Cat::Merge;
@@ -152,7 +153,7 @@
 	$class->fix_copy_price($copy);
 
 	return $editor->event unless $editor->update_asset_copy($copy);
-	return remove_empty_objects($editor, $override, $orig_vol);
+	return $class->remove_empty_objects($editor, $override, $orig_vol);
 }
 
 
@@ -191,7 +192,7 @@
 		$copy->clear_stat_cat_entries;
 
 		if( $copy->isdeleted ) {
-			$evt = delete_copy($editor, $override, $vol, $copy);
+			$evt = $class->delete_copy($editor, $override, $vol, $copy);
 			return $evt if $evt;
 
 		} elsif( $copy->isnew ) {
@@ -214,6 +215,44 @@
 	return undef;
 }
 
+
+sub delete_copy {
+	my($class, $editor, $override, $vol, $copy ) = @_;
+
+   return $editor->event unless 
+      $editor->allowed('DELETE_COPY',copy_perm_org($vol, $copy));
+
+	my $stat = $U->copy_status($copy->status)->id;
+
+	unless($override) {
+		return OpenILS::Event->new('COPY_DELETE_WARNING', payload => $copy->id )
+			if $stat == OILS_COPY_STATUS_CHECKED_OUT or
+				$stat == OILS_COPY_STATUS_IN_TRANSIT or
+				$stat == OILS_COPY_STATUS_ON_HOLDS_SHELF or
+				$stat == OILS_COPY_STATUS_ILL;
+	}
+
+	$logger->info("vol-update: deleting copy ".$copy->id);
+	$copy->deleted('t');
+
+	$copy->editor($editor->requestor->id);
+	$copy->edit_date('now');
+	$editor->update_asset_copy($copy) or return $editor->event;
+
+	# Delete any open transits for this copy
+	my $transits = $editor->search_action_transit_copy(
+		{ target_copy=>$copy->id, dest_recv_time => undef } );
+
+	for my $t (@$transits) {
+		$editor->delete_action_transit_copy($t)
+			or return $editor->event;
+	}
+
+	return $class->remove_empty_objects($editor, $override, $vol);
+}
+
+
+
 sub create_volume {
 	my($class, $override, $editor, $vol) = @_;
 	my $evt;
@@ -322,4 +361,36 @@
 }
 
 
+sub remove_empty_objects {
+	my($class, $editor, $override, $vol) = @_; 
 
+    my $koe = $U->ou_ancestor_setting_value(
+        $editor->requestor->ws_ou, 'cat.bib.keep_on_empty', $editor);
+    my $aoe =  $U->ou_ancestor_setting_value(
+        $editor->requestor->ws_ou, 'cat.bib.alert_on_empty', $editor);
+
+	if( OpenILS::Application::Cat::BibCommon->title_is_empty($editor, $vol->record, $vol->id) ) {
+
+        # delete this volume if it's not already marked as deleted
+        unless( $U->is_true($vol->deleted) || $vol->isdeleted ) {
+            $vol->deleted('t');
+            $vol->editor($editor->requestor->id);
+            $vol->edit_date('now');
+            $editor->update_asset_call_number($vol) or return $editor->event;
+        }
+
+        unless($koe) {
+            # delete the bib record if the keep-on-empty setting is not set
+            my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($editor, $vol->record);
+            return $evt if $evt;
+        }
+
+        # return the empty alert if the alert-on-empty setting is set
+        return OpenILS::Event->new('TITLE_LAST_COPY', payload => $vol->record ) if $aoe;
+	}
+
+	return undef;
+}
+
+
+

Modified: branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm
===================================================================
--- branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm	2008-10-27 21:26:16 UTC (rev 10925)
+++ branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm	2008-10-27 21:49:05 UTC (rev 10926)
@@ -290,4 +290,53 @@
 	return 0;
 }
 
+
+sub delete_rec {
+   my($class, $editor, $rec_id ) = @_;
+
+   my $rec = $editor->retrieve_biblio_record_entry($rec_id)
+      or return $editor->event;
+
+   return undef if $U->is_true($rec->deleted);
+   
+   $rec->deleted('t');
+   $rec->active('f');
+   $rec->editor( $editor->requestor->id );
+   $rec->edit_date('now');
+   $editor->update_biblio_record_entry($rec) or return $editor->event;
+
+   return undef;
+}
+
+
+# ---------------------------------------------------------------------------
+# returns true if the given title (id) has no un-deleted volumes or 
+# copies attached.  If a context volume is defined, a record
+# is considered empty only if the context volume is the only
+# remaining volume on the record.  
+# ---------------------------------------------------------------------------
+sub title_is_empty {
+	my($class, $editor, $rid, $vol_id) = @_;
+
+	return 0 if $rid == OILS_PRECAT_RECORD;
+
+	my $cnlist = $editor->search_asset_call_number(
+		{ record => $rid, deleted => 'f' }, { idlist => 1 } );
+
+	return 1 unless @$cnlist; # no attached volumes
+    return 0 if @$cnlist > 1; # multiple attached volumes
+    return 0 unless $$cnlist[0] == $vol_id; # attached volume is not the context vol.
+
+    # see if the sole remaining context volume has any attached copies
+	for my $cn (@$cnlist) {
+		my $copylist = $editor->search_asset_copy(
+			[
+				{ call_number => $cn, deleted => 'f' }, 
+				{ limit => 1 },
+			], { idlist => 1 });
+		return 0 if @$copylist; # false if we find any copies
+	}
+
+	return 1;
+}
 1;

Modified: branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
===================================================================
--- branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm	2008-10-27 21:26:16 UTC (rev 10925)
+++ branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm	2008-10-27 21:49:05 UTC (rev 10926)
@@ -516,40 +516,6 @@
 }
 
 
-
-
-# ---------------------------------------------------------------------------
-# returns true if the given title (id) has no un-deleted volumes or 
-# copies attached.  If a context volume is defined, a record
-# is considered empty only if the context volume is the only
-# remaining volume on the record.  
-# ---------------------------------------------------------------------------
-sub title_is_empty {
-	my( $editor, $rid, $vol_id ) = @_;
-
-	return 0 if $rid == OILS_PRECAT_RECORD;
-
-	my $cnlist = $editor->search_asset_call_number(
-		{ record => $rid, deleted => 'f' }, { idlist => 1 } );
-
-	return 1 unless @$cnlist; # no attached volumes
-    return 0 if @$cnlist > 1; # multiple attached volumes
-    return 0 unless $$cnlist[0] == $vol_id; # attached volume is not the context vol.
-
-    # see if the sole remaining context volume has any attached copies
-	for my $cn (@$cnlist) {
-		my $copylist = $editor->search_asset_copy(
-			[
-				{ call_number => $cn, deleted => 'f' }, 
-				{ limit => 1 },
-			], { idlist => 1 });
-		return 0 if @$copylist; # false if we find any copies
-	}
-
-	return 1;
-}
-
-
 __PACKAGE__->register_method(
 	method	=> "fleshed_volume_update",
 	api_name	=> "open-ils.cat.asset.volume.fleshed.batch.update",);
@@ -652,38 +618,6 @@
 }
 
 
-sub remove_empty_objects {
-	my( $editor, $override, $vol ) = @_; 
-
-    my $koe = $U->ou_ancestor_setting_value(
-        $editor->requestor->ws_ou, 'cat.bib.keep_on_empty', $editor);
-    my $aoe =  $U->ou_ancestor_setting_value(
-        $editor->requestor->ws_ou, 'cat.bib.alert_on_empty', $editor);
-
-	if( title_is_empty($editor, $vol->record, $vol->id) ) {
-
-        # delete this volume if it's not already marked as deleted
-        unless( $U->is_true($vol->deleted) || $vol->isdeleted ) {
-            $vol->deleted('t');
-            $vol->editor($editor->requestor->id);
-            $vol->edit_date('now');
-            $editor->update_asset_call_number($vol) or return $editor->event;
-        }
-
-        unless($koe) {
-            # delete the bib record if the keep-on-empty setting is not set
-            my $evt = delete_rec($editor, $vol->record);
-            return $evt if $evt;
-        }
-
-        # return the empty alert if the alert-on-empty setting is set
-        return OpenILS::Event->new('TITLE_LAST_COPY', payload => $vol->record ) if $aoe;
-	}
-
-	return undef;
-}
-
-
 __PACKAGE__->register_method (
 	method => 'delete_bib_record',
 	api_name => 'open-ils.cat.biblio.record_entry.delete');
@@ -695,70 +629,14 @@
     return $e->die_event unless $e->allowed('DELETE_RECORD', $e->requestor->ws_ou);
     my $vols = $e->search_asset_call_number({record=>$rec_id, deleted=>'f'});
     return OpenILS::Event->new('RECORD_NOT_EMPTY', payload=>$rec_id) if @$vols;
-    my $evt = delete_rec($e, $rec_id);
+    my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $rec_id);
     if($evt) { $e->rollback; return $evt; }   
     $e->commit;
     return 1;
 }
 
 
-# marks a record as deleted
-sub delete_rec {
-   my( $editor, $rec_id ) = @_;
 
-   my $rec = $editor->retrieve_biblio_record_entry($rec_id)
-      or return $editor->event;
-
-   return undef if $U->is_true($rec->deleted);
-   
-   $rec->deleted('t');
-   $rec->active('f');
-   $rec->editor( $editor->requestor->id );
-   $rec->edit_date('now');
-   $editor->update_biblio_record_entry($rec) or return $editor->event;
-
-   return undef;
-}
-
-
-sub delete_copy {
-	my( $editor, $override, $vol, $copy ) = @_;
-
-   return $editor->event unless 
-      $editor->allowed('DELETE_COPY',copy_perm_org($vol, $copy));
-
-	my $stat = $U->copy_status($copy->status)->id;
-
-	unless($override) {
-		return OpenILS::Event->new('COPY_DELETE_WARNING', payload => $copy->id )
-			if $stat == OILS_COPY_STATUS_CHECKED_OUT or
-				$stat == OILS_COPY_STATUS_IN_TRANSIT or
-				$stat == OILS_COPY_STATUS_ON_HOLDS_SHELF or
-				$stat == OILS_COPY_STATUS_ILL;
-	}
-
-	$logger->info("vol-update: deleting copy ".$copy->id);
-	$copy->deleted('t');
-
-	$copy->editor($editor->requestor->id);
-	$copy->edit_date('now');
-	$editor->update_asset_copy($copy) or return $editor->event;
-
-	# Delete any open transits for this copy
-	my $transits = $editor->search_action_transit_copy(
-		{ target_copy=>$copy->id, dest_recv_time => undef } );
-
-	for my $t (@$transits) {
-		$editor->delete_action_transit_copy($t)
-			or return $editor->event;
-	}
-
-	return remove_empty_objects($editor, $override, $vol);
-}
-
-
-
-
 __PACKAGE__->register_method (
 	method => 'batch_volume_transfer',
 	api_name => 'open-ils.cat.asset.volume.batch.transfer',
@@ -801,8 +679,8 @@
 
 	for my $vol (@$vols) {
 
-		# if we've already looked at this volume, go to the next
-		next if !$vol or grep { $vol->id == $_ } @seen;
+        # if we've already looked at this volume, go to the next
+        next if !$vol or grep { $vol->id == $_ } @seen;
 
 		# grab all of the volumes in the list that have 
 		# the same label so they can be merged
@@ -810,7 +688,7 @@
 
 		# take note of the fact that we've looked at this set of volumes
 		push( @seen, $_->id ) for @all;
-      push( @rec_ids, $_->record ) for @all;
+        push( @rec_ids, $_->record ) for @all;
 
 		# for each volume, see if there are any copies that have a 
 		# remote circ_lib (circ_lib != vol->owning_lib and != $o_lib ).  
@@ -896,15 +774,12 @@
 
 		# Now see if any empty records need to be deleted after all of this
 
-      for(@rec_ids) {
-         $logger->debug("merge: seeing if we should delete record $_...");
-         $evt = delete_rec($e, $_) if title_is_empty($e, $_);
-			return $evt if $evt;
-      }
-
-		#for(@all) {
-		#	$evt = remove_empty_objects($e, $override, $_);
-		#}
+        for(@rec_ids) {
+            $logger->debug("merge: seeing if we should delete record $_...");
+            $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $_) 
+                if OpenILS::Application::Cat::BibCommon->title_is_empty($e, $_);
+            return $evt if $evt;
+        }
 	}
 
 	$logger->info("merge: transfer succeeded");



More information about the open-ils-commits mailing list