]> wagnertech.de Git - mfinanz.git/commitdiff
Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
authorSven Schöling <s.schoeling@linet-services.de>
Wed, 8 Aug 2012 15:48:29 +0000 (17:48 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Wed, 8 Aug 2012 15:48:29 +0000 (17:48 +0200)
13 files changed:
SL/Controller/CsvImport/Part.pm
SL/IR.pm
SL/SessionFile.pm
SL/System/Process.pm [new file with mode: 0644]
SL/System/TaskServer.pm [new file with mode: 0644]
doc/Lx-Office-Dokumentation.pdf
doc/dokumentation.xml
doc/html/ch02s06.html
scripts/boot/system-v/kivitendo-task-server [new file with mode: 0755]
scripts/boot/system-v/lx-office-task-server [deleted file]
scripts/boot/upstart/kivitendo-task-server.conf [new file with mode: 0644]
scripts/boot/upstart/lx-office-task-server.conf [deleted file]
scripts/task_server.pl

index 6c056d0f96e8fb68ed80dbb258a8b399017d74a4..3be6f2a4421b8e3b6eaf9285e62a0851ec4162eb 100644 (file)
@@ -201,7 +201,7 @@ sub check_existing {
 
   if ($self->settings->{article_number_policy} eq 'update_prices') {
     if ($entry->{part}) {
-      map { $entry->{part}->$_( $object->$_ ) } qw(sellprice listprice lastcost);
+      map { $entry->{part}->$_( $object->$_ ) if defined $object->$_ } qw(sellprice listprice lastcost);   
 
       # merge prices
       my %prices_by_pricegroup_id = map { $_->pricegroup->id => $_ } $entry->{part}->prices, $object->prices;
index d8569acaa9f2bd6b4da55c6730af045f55e09b66..444dffceba7e4c40ee20d661cdf09da5a916fbbd 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -210,7 +210,7 @@ sub post_invoice {
 
       # update parts table by setting lastcost to current price, don't allow negative values by using abs
       $query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|;
-      @values = (abs($form->{"sellprice_$i"}), conv_i($form->{"id_$i"}));
+      @values = (abs($form->{"sellprice_$i"} / $basefactor), conv_i($form->{"id_$i"}));
       do_query($form, $dbh, $query, @values);
 
       # check if we sold the item already and
@@ -338,7 +338,7 @@ sub post_invoice {
 
       # update lastcost
       $query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|;
-      do_query($form, $dbh, $query, $form->{"sellprice_$i"}, conv_i($form->{"id_$i"}));
+      do_query($form, $dbh, $query, $form->{"sellprice_$i"} / $basefactor, conv_i($form->{"id_$i"}));
     }
 
     next if $payments_only;
index dbed4154b9a8d153494802d2f52e9ae8ac538696..69997e9a160003d4e5c0a65f54a9a7049bb8488b 100644 (file)
@@ -95,7 +95,7 @@ destroyed or expires
   use SL::SessionFile;
 
   # Create a session file named "customer.csv" (relative names only)
-  my $sfile = SL::SessionFile->new("customer.csv", "w");
+  my $sfile = SL::SessionFile->new('customer.csv', mode => 'w');
   $sfile->fh->print("col1;col2;col3\n" .
                     "value1;value2;value3\n");
   $sfile->fh->close;
diff --git a/SL/System/Process.pm b/SL/System/Process.pm
new file mode 100644 (file)
index 0000000..0bddfd6
--- /dev/null
@@ -0,0 +1,61 @@
+package SL::System::Process;
+
+use strict;
+
+use parent qw(Rose::Object);
+
+use English qw(-no_match_vars);
+use File::Spec;
+use File::Basename;
+
+sub exe_dir {
+  my $dir        = dirname(File::Spec->rel2abs($PROGRAM_NAME));
+  my $system_dir = File::Spec->catdir($dir, 'SL', 'System');
+  return $dir if -d $system_dir && -f File::Spec->catfile($system_dir, 'TaskServer.pm');
+
+  my @dirs = reverse File::Spec->splitdir($dir);
+  shift @dirs;
+  $dir        = File::Spec->catdir(reverse @dirs);
+  $system_dir = File::Spec->catdir($dir, 'SL', 'System');
+  return File::Spec->curdir unless -d $system_dir && -f File::Spec->catfile($system_dir, 'TaskServer.pm');
+
+  return $dir;
+}
+
+1;
+__END__
+
+=pod
+
+=encoding utf8
+
+=head1 NAME
+
+SL::System::Process - assorted system-relevant functions
+
+=head1 SYNOPSIS
+
+  # Get base path to Kivitendo scripts
+  my $path = SL::System::Process->exe_dir;
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<exe_dir>
+
+Returns the absolute path to the directory the Kivitendo executables
+(C<login.pl> etc.) and modules (sub-directory C<SL/> etc.) are located
+in.
+
+=back
+
+=head1 BUGS
+
+Nothing here yet.
+
+=head1 AUTHOR
+
+Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
+
+=cut
diff --git a/SL/System/TaskServer.pm b/SL/System/TaskServer.pm
new file mode 100644 (file)
index 0000000..bceb8f5
--- /dev/null
@@ -0,0 +1,185 @@
+package SL::System::TaskServer;
+
+use strict;
+
+use parent qw(Rose::Object);
+
+use Rose::Object::MakeMethods::Generic (
+  scalar => [ qw(last_command_output) ],
+);
+
+use File::Slurp;
+use File::Spec::Functions qw(:ALL);
+
+use SL::System::Process;
+
+use constant {
+  OK           =>  0,
+  ERR_PID_FILE => -1,
+  ERR_PROCESS  => -2,
+};
+
+sub status {
+  my ($self) = @_;
+
+  my $pid = $self->_read_pid;
+  return ERR_PID_FILE unless $pid;
+
+  return kill(0, $pid) ? OK : ERR_PROCESS;
+}
+
+sub is_running {
+  my ($self) = @_;
+
+  return $self->status == OK;
+}
+
+sub start {
+  my ($self) = @_;
+
+  return $self->_run_script_command('start');
+}
+
+sub stop {
+  my ($self) = @_;
+
+  return $self->_run_script_command('stop');
+}
+
+sub wake_up {
+  my ($self) = @_;
+
+  my $pid = $self->_read_pid;
+  return undef unless $pid;
+  return kill('ALRM', $pid) ? 1 : undef;
+}
+
+#
+# private methods
+#
+
+sub _read_pid {
+  my ($self) = @_;
+
+  my $exe_dir       = SL::System::Process->exe_dir;
+  my $pid_file_name = join '.', splitdir($exe_dir), 'config.lx_office.conf.pid';
+  my $pid_file_path = catfile(catdir($exe_dir, 'users', 'pid'), $pid_file_name);
+
+  return undef unless -f $pid_file_path;
+  return join('', read_file($pid_file_path)) * 1;
+}
+
+sub _run_script_command {
+  my ($self, $command) = @_;
+
+  my $exe = catfile(catdir(SL::System::Process->exe_dir, 'scripts'), 'task_server.pl');
+  $self->last_command_output(`${exe} ${command}`);
+
+  return $? == 0 ? 1 : undef;
+}
+
+1;
+__END__
+
+=pod
+
+=encoding utf8
+
+=head1 NAME
+
+SL::System::TaskServer - programmatic interface to the external task server component
+
+=head1 SYNOPSIS
+
+  # Create interface
+  my $task_server = SL->TaskServer->new;
+
+  # Start the server if it is not running
+  if (!$task_server->is_running) {
+    $task_server->start;
+  }
+
+  # Stop it if it is running
+  if ($task_server->is_running) {
+    $task_server->stop;
+  }
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<is_running>
+
+Returns C<trueish> if the server is running. This is done by using
+Perl's C<kill> function with a "signal" of C<0> for the process ID
+which in turn is read from the daemon's PID file.
+
+If the PID file is not found or if C<kill> returns a non-successful
+value then a C<falsish> value is returned.
+
+=item C<last_command_output>
+
+Returns the output of the last C<system> command executed, e.g. from a
+call to L<start> or L<stop>.
+
+=item C<start>
+
+Starts the task server. Does not check whether or not it is running,
+neither before not after trying to start it.
+
+Returns C<1> if the system command C<./scripts/task_server.pl start>
+exits with an exit code of C<0> and C<undef> otherwise.
+
+The command's output can be queried with L<last_command_output>.
+
+=item C<status>
+
+Queries the task server status. Returns one of these values:
+
+=over 4
+
+=item *
+
+C<OK> or C<0>: the task server is running and signals can be sent to
+it.
+
+=item *
+
+C<ERR_PID_FILE> or C<-1>: the PID file could not be found or read
+
+=item *
+
+C<ERR_PROCESS> or C<-2>: the PID file could was found and read, but
+it's not possible to send signals to the process, e.g. because it is
+not running or owned by a different user ID.
+
+=back
+
+=item C<stop>
+
+Stops the task server. Does not check whether or not it is running,
+neither before not after trying to start it.
+
+Returns C<1> if the system command C<./scripts/task_server.pl stop>
+exits with an exit code of C<0> and C<undef> otherwise.
+
+The command's output can be queried with L<last_command_output>.
+
+=item C<wake_up>
+
+Sends a signal to the task server process causing it to wake up and
+process its job queue immediately.
+
+Returns C<1> if the signal could be sent and C<undef> otherwise.
+
+=back
+
+=head1 BUGS
+
+Nothing here yet.
+
+=head1 AUTHOR
+
+Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
+
+=cut
index 24c0ebc9567b128dcfb1b6fd2dd439646f2a7da8..fe1d25d6723e52713ce0f44e8771e10168612edb 100644 (file)
Binary files a/doc/Lx-Office-Dokumentation.pdf and b/doc/Lx-Office-Dokumentation.pdf differ
index 76a5b64a1cd244b4e5bc5dc21858f3d006bc8b24..5e14aa3a156c59b27a3cc7b0991eb820cbd6eace 100644 (file)
@@ -808,8 +808,8 @@ Alias       /url/for/lx-office-erp-fcgid/          /path/to/lx-office-erp/</prog
           Core)</title>
 
           <para>Kopieren Sie die Datei
-          <filename>scripts/boot/system-v/lx-office-task-server</filename>
-          nach <filename>/etc/init.d/lx-office-task-server</filename>. Passen
+          <filename>scripts/boot/system-v/kivitendo-server</filename>
+          nach <filename>/etc/init.d/kivitendo-server</filename>. Passen
           Sie in der kopierten Datei den Pfad zum Task-Server an (Zeile
           <literal>DAEMON=....</literal>). Binden Sie das Script in den
           Boot-Prozess ein. Dies ist distributionsabhängig:</para>
@@ -818,20 +818,20 @@ Alias       /url/for/lx-office-erp-fcgid/          /path/to/lx-office-erp/</prog
             <listitem>
               <para>Debian-basierende Systeme:</para>
 
-              <programlisting>update-rc.d lx-office-task-server defaults
+              <programlisting>update-rc.d kivitendo-task-server defaults
 # Nur bei Debian Squeeze und neuer:
-insserv lx-office-task-server</programlisting>
+insserv kivitendo-task-server</programlisting>
             </listitem>
 
             <listitem>
               <para>OpenSuSE und Fedora Core:</para>
 
-              <programlisting>chkconfig --add lx-office-task-server</programlisting>
+              <programlisting>chkconfig --add kivitendo-task-server</programlisting>
             </listitem>
           </itemizedlist>
 
           <para>Danach kann der Task-Server mit dem folgenden Befehl gestartet
-          werden: <command>/etc/init.d/lx-office-task-server
+          werden: <command>/etc/init.d/kivitendo-task-server
           start</command></para>
         </sect3>
 
@@ -839,13 +839,13 @@ insserv lx-office-task-server</programlisting>
           <title>Upstart-basierende Systeme (z.B. Ubuntu)</title>
 
           <para>Kopieren Sie die Datei
-          <filename>scripts/boot/upstart/lx-office-task-server.conf</filename>
-          nach <filename>/etc/init/lx-office-task-server.conf</filename>.
+          <filename>scripts/boot/upstart/kivitendo-task-server.conf</filename>
+          nach <filename>/etc/init/kivitendo-task-server.conf</filename>.
           Passen Sie in der kopierten Datei den Pfad zum Task-Server an (Zeile
           <literal>exec ....</literal>).</para>
 
           <para>Danach kann der Task-Server mit dem folgenden Befehl gestartet
-          werden: <command>service lx-office-task-server
+          werden: <command>service kivitendo-task-server
           start</command></para>
         </sect3>
       </sect2>
index 0cfc2a9bb212f4e911e733d55eab2fe05527d49f..bbcde3205c96e15e472608e0ae37e1a1c195db75 100644 (file)
         zwangsläufig funktioniert, werden auch Start-Scripte mitgeliefert, die
         anstelle eines symbolischen Links verwendet werden können.</p><div class="sect3" title="2.6.2.1. SystemV-basierende Systeme (z.B. Debian, OpenSuSE, Fedora Core)"><div class="titlepage"><div><div><h4 class="title"><a name="d0e695"></a>2.6.2.1. SystemV-basierende Systeme (z.B. Debian, OpenSuSE, Fedora
           Core)</h4></div></div></div><p>Kopieren Sie die Datei
-          <code class="filename">scripts/boot/system-v/lx-office-task-server</code>
-          nach <code class="filename">/etc/init.d/lx-office-task-server</code>. Passen
+          <code class="filename">scripts/boot/system-v/kivitendo-server</code>
+          nach <code class="filename">/etc/init.d/kivitendo-server</code>. Passen
           Sie in der kopierten Datei den Pfad zum Task-Server an (Zeile
           <code class="literal">DAEMON=....</code>). Binden Sie das Script in den
-          Boot-Prozess ein. Dies ist distributionsabhängig:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Debian-basierende Systeme:</p><pre class="programlisting">update-rc.d lx-office-task-server defaults
+          Boot-Prozess ein. Dies ist distributionsabhängig:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Debian-basierende Systeme:</p><pre class="programlisting">update-rc.d kivitendo-task-server defaults
 # Nur bei Debian Squeeze und neuer:
-insserv lx-office-task-server</pre></li><li class="listitem"><p>OpenSuSE und Fedora Core:</p><pre class="programlisting">chkconfig --add lx-office-task-server</pre></li></ul></div><p>Danach kann der Task-Server mit dem folgenden Befehl gestartet
-          werden: <span class="command"><strong>/etc/init.d/lx-office-task-server
+insserv kivitendo-task-server</pre></li><li class="listitem"><p>OpenSuSE und Fedora Core:</p><pre class="programlisting">chkconfig --add kivitendo-task-server</pre></li></ul></div><p>Danach kann der Task-Server mit dem folgenden Befehl gestartet
+          werden: <span class="command"><strong>/etc/init.d/kivitendo-task-server
           start</strong></span>
                </p></div><div class="sect3" title="2.6.2.2. Upstart-basierende Systeme (z.B. Ubuntu)"><div class="titlepage"><div><div><h4 class="title"><a name="d0e725"></a>2.6.2.2. Upstart-basierende Systeme (z.B. Ubuntu)</h4></div></div></div><p>Kopieren Sie die Datei
-          <code class="filename">scripts/boot/upstart/lx-office-task-server.conf</code>
-          nach <code class="filename">/etc/init/lx-office-task-server.conf</code>.
+          <code class="filename">scripts/boot/upstart/kivitendo-task-server.conf</code>
+          nach <code class="filename">/etc/init/kivitendo-task-server.conf</code>.
           Passen Sie in der kopierten Datei den Pfad zum Task-Server an (Zeile
           <code class="literal">exec ....</code>).</p><p>Danach kann der Task-Server mit dem folgenden Befehl gestartet
-          werden: <span class="command"><strong>service lx-office-task-server
+          werden: <span class="command"><strong>service kivitendo-task-server
           start</strong></span>
                </p></div></div><div class="sect2" title="2.6.3. Wie der Task-Server gestartet und beendet wird"><div class="titlepage"><div><div><h3 class="title"><a name="Prozesskontrolle"></a>2.6.3. Wie der Task-Server gestartet und beendet wird</h3></div></div></div><p>Der Task-Server wird wie folgt kontrolliert:</p><pre class="programlisting">./scripts/task_server.pl Befehl</pre><p>
                <code class="literal">Befehl</code> ist dabei eine der folgenden
diff --git a/scripts/boot/system-v/kivitendo-task-server b/scripts/boot/system-v/kivitendo-task-server
new file mode 100755 (executable)
index 0000000..cab5696
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides:          kivitendo-task-server
+# Required-Start:    $local_fs $remote_fs $network $syslog $named
+# Required-Stop:     $local_fs $remote_fs $network $syslog $named
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# X-Interactive:     true
+# Short-Description: Start/stop the Kivitendo task server
+### END INIT INFO
+
+set -e
+
+# Change this to point to the Kivitendo "task_server.pl" location.
+DAEMON="/opt/kivitendo/scripts/task_server.pl"
+TOPIC="Kivitendo task server"
+
+if [ ! -x $DAEMON ] ; then
+  echo "$TOPIC executable not found"
+  exit 1
+fi
+
+case $1 in
+  start)
+    echo "Starting the $TOPIC"
+    $DAEMON start
+    ;;
+  stop)
+    echo "Stopping the $TOPIC"
+    $DAEMON stop
+    ;;
+  restart)
+    echo "Restarting the $TOPIC"
+    $DAEMON restart
+    ;;
+  status)
+    if $DAEMON status > /dev/null 2> /dev/null; then
+      echo "The $TOPIC is running"
+    else
+      echo "The $TOPIC is not running"
+      exit 1
+    fi
+    ;;
+  *)
+    echo "Usage: /etc/init.d/kivitendo-task-server {start|stop|reload|status}"
+    exit 1
+    ;;
+esac
diff --git a/scripts/boot/system-v/lx-office-task-server b/scripts/boot/system-v/lx-office-task-server
deleted file mode 100755 (executable)
index 1beb1d8..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-
-### BEGIN INIT INFO
-# Provides:          lx-office-task-server
-# Required-Start:    $local_fs $remote_fs $network $syslog $named
-# Required-Stop:     $local_fs $remote_fs $network $syslog $named
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# X-Interactive:     true
-# Short-Description: Start/stop the Lx-Office task server
-### END INIT INFO
-
-set -e
-
-# Change this to point to the Lx-Office "task_server.pl" location.
-DAEMON="/opt/lx-office/scripts/task_server.pl"
-TOPIC="Lx-Office task server"
-
-if [ ! -x $DAEMON ] ; then
-  echo "$TOPIC executable not found"
-  exit 1
-fi
-
-case $1 in
-  start)
-    echo "Starting the $TOPIC"
-    $DAEMON start
-    ;;
-  stop)
-    echo "Stopping the $TOPIC"
-    $DAEMON stop
-    ;;
-  restart)
-    echo "Restarting the $TOPIC"
-    $DAEMON restart
-    ;;
-  status)
-    if $DAEMON status > /dev/null 2> /dev/null; then
-      echo "The $TOPIC is running"
-    else
-      echo "The $TOPIC is not running"
-      exit 1
-    fi
-    ;;
-  *)
-    echo "Usage: /etc/init.d/lx-office-task-server {start|stop|reload|status}"
-    exit 1
-    ;;
-esac
diff --git a/scripts/boot/upstart/kivitendo-task-server.conf b/scripts/boot/upstart/kivitendo-task-server.conf
new file mode 100644 (file)
index 0000000..b3666db
--- /dev/null
@@ -0,0 +1,11 @@
+# kivitendo-task-server - Task server for Kivitendo
+
+description    "Kivitendo task server"
+
+start on runlevel [2345]
+stop on runlevel [!2345]
+
+respawn
+
+# Adjust path
+exec /opt/kivitendo/scripts/task_server.pl -f start
diff --git a/scripts/boot/upstart/lx-office-task-server.conf b/scripts/boot/upstart/lx-office-task-server.conf
deleted file mode 100644 (file)
index fa00ba2..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-# lx-office-task-server - Task server for Lx-Office
-
-description    "Lx-Office task server"
-
-start on runlevel [2345]
-stop on runlevel [!2345]
-
-respawn
-
-# Adjust path
-exec /opt/lx-office/scripts/task_server.pl -f start
-
index 2c4a05fd45dcbdadffbdb9415850fa33bb3c7aa9..8c17ca70a6de97e4ada01f0250681b05459f618e 100755 (executable)
@@ -125,7 +125,16 @@ sub gd_run {
     }
 
     my $seconds = 60 - (localtime)[0];
-    sleep($seconds < 30 ? $seconds + 60 : $seconds);
+    if (!eval {
+      local $SIG{'ALRM'} = sub {
+        $::lxdebug->message(0, "Got woken up by SIGALRM") if $lx_office_conf{task_server}->{debug};
+        die "Alarm!\n"
+      };
+      sleep($seconds < 30 ? $seconds + 60 : $seconds);
+      1;
+    }) {
+      die $@ unless $@ eq "Alarm!\n";
+    }
   }
 }
 
@@ -136,7 +145,7 @@ mkdir($pidbase) if !-d $pidbase;
 
 my $file = -f "${cwd}/config/lx_office.conf" ? "${cwd}/config/lx_office.conf" : "${cwd}/config/lx_office.conf.default";
 newdaemon(configfile => $file,
-          progname   => 'lx-office-task-server',
+          progname   => 'kivitendo-task-server',
           pidbase    => "${pidbase}/",
           );