[open-ils-commits] r12043 - in trunk/Open-ILS/src: extras perlmods/OpenILS/Application/Circ
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Feb 3 11:27:00 EST 2009
Author: erickson
Date: 2009-02-03 11:26:58 -0500 (Tue, 03 Feb 2009)
New Revision: 12043
Modified:
trunk/Open-ILS/src/extras/ils_events.xml
trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Survey.pm
Log:
added a cascading survey delete operation.
Modified: trunk/Open-ILS/src/extras/ils_events.xml
===================================================================
--- trunk/Open-ILS/src/extras/ils_events.xml 2009-02-02 20:12:10 UTC (rev 12042)
+++ trunk/Open-ILS/src/extras/ils_events.xml 2009-02-03 16:26:58 UTC (rev 12043)
@@ -719,6 +719,9 @@
<event code='1712' textcode='AUTH_QUEUE_EXISTS'>
<desc xml:lang="en-US">An authority record queue with the same name already exists</desc>
</event>
+ <event code='1713' textcode='SURVEY_RESPONSES_EXIST'>
+ <desc xml:lang="en-US">Responses to this survey exist</desc>
+ </event>
<event code='2000' textcode='BAD_PARAMS'>
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Survey.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Survey.pm 2009-02-02 20:12:10 UTC (rev 12042)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Survey.pm 2009-02-03 16:26:58 UTC (rev 12043)
@@ -19,6 +19,7 @@
use OpenSRF::EX qw/:try/;
use OpenILS::Application::AppUtils;
use Data::Dumper;
+use OpenILS::Event;
use Time::HiRes qw(time);
use OpenILS::Utils::CStoreEditor qw/:funcs/;
@@ -395,17 +396,52 @@
}
+__PACKAGE__->register_method (
+ method => 'delete_survey',
+ api_name => 'open-ils.circ.survey.delete.cascade'
+);
+__PACKAGE__->register_method (
+ method => 'delete_survey',
+ api_name => 'open-ils.circ.survey.delete.cascade.override'
+);
+sub delete_survey {
+ my($self, $conn, $auth, $survey_id) = @_;
+ my $e = new_editor(authtoken => $auth, xact => 1);
+ return $e->die_event unless $e->checkauth;
+ my $survey = $e->retrieve_action_survey($survey_id)
+ or return $e->die_event;
+ return $e->die_event unless $e->allowed('ADMIN_SURVEY', $survey->owner);
+ my $questions = $e->search_action_survey_question({survey => $survey_id});
+ my @answers;
+ push(@answers, @{$e->search_action_survey_answer({question => $_->id})}) for @$questions;
+ my $responses = $e->search_action_survey_response({survey => $survey_id});
+ return OpenILS::Event->new('SURVEY_RESPONSES_EXIST')
+ if @$responses and $self->api_name =! /override/;
+ for my $resp (@$responses) {
+ $e->delete_action_survey_response($resp) or return $e->die_event;
+ }
+ for my $ans (@answers) {
+ $e->delete_action_survey_answer($ans) or return $e->die_event;
+ }
+ for my $quest (@$questions) {
+ $e->delete_action_survey_question($quest) or return $e->die_event;
+ }
-1;
+ $e->delete_action_survey($survey) or return $e->die_event;
+ $e->commit;
+ return 1;
+}
+
+1;
More information about the open-ils-commits
mailing list