[otrs-cvs] Survey/var/packagesetup Survey.pm,1.1,1.2

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/Survey/var/packagesetup
In directory lancelot:/tmp/cvs-serv32497/var/packagesetup

Modified Files:
	Survey.pm 
Log Message:
Added answer required functionality in Survey for 3.1.x.

Author: jh

Index: Survey.pm
===================================================================
RCS file: /home/cvs/Survey/var/packagesetup/Survey.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -2 -u -d -r1.1 -r1.2
--- Survey.pm	15 Dec 2011 15:43:52 -0000	1.1
+++ Survey.pm	20 Nov 2012 15:55:02 -0000	1.2
@@ -1,5 +1,5 @@
 # --
 # Survey.pm - code to excecute during package installation
-# Copyright (C) 2001-2011 OTRS AG, http://otrs.org/
+# Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
 # --
 # $Id$
@@ -197,4 +197,77 @@
 }
 
+# ---
+# AnswerRequired
+# ---
+
+=item CodeUpgradeFromLowerThan_2_1_4()
+
+This function is only executed if the installed module version is smaller than 2.1.4.
+
+my $Result = $CodeObject->CodeUpgradeFromLowerThan_2_1_4();
+
+=cut
+
+sub CodeUpgradeFromLowerThan_2_1_4 {
+    my ( $Self, %Param ) = @_;
+
+    # set all survey_question records
+    # that don't have answer_required set to something
+    # to 0
+    $Self->_Prefill_AnswerRequiredFromSurveyQuestion_2_0_5();
+
+    return 1;
+}
+
+=item _Prefill_AnswerRequiredFromSurveyQuestion_2_1_4()
+
+Inserts 0 into all answer_required records of table suvey_question
+where there is no entry present.
+
+    my $Success = $PackageSetup->_Prefill_AnswerRequiredFromSurveyQuestion_2_1_4();
+
+=cut
+
+sub _Prefill_AnswerRequiredFromSurveyQuestion_2_1_4 {
+    my ($Self) = @_;
+
+    return if !$Self->{DBObject}->Prepare(
+        SQL => 'SELECT id, answer_required '
+            . 'FROM survey_question',
+        Limit => 0,
+    );
+    my @IdsToUpdate;
+    while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
+
+        # if we had an id
+        # but no answer_required or answer_required isn't 0 or 1
+        # collect the ID in @IdsToUpdate
+        if (
+            defined $Row[0]
+            && length $Row[0]
+            && (
+                !defined $Row[1]
+                || ( $Row[1] ne '0' && $Row[1] ne '1' )
+            )
+            )
+        {
+            push @IdsToUpdate, $Row[0];
+        }
+    }
+
+    for my $QuestionID (@IdsToUpdate) {
+        $Self->{DBObject}->Do(
+            SQL =>
+                'UPDATE survey_question SET answer_required = 0 WHERE id = ?',
+            Bind => [
+                \$QuestionID,
+            ],
+        );
+    }
+    return 1;
+}
+
+# ---
+
 1;
 
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.