]> Frank Brehm's Git Trees - books.git/commitdiff
Sessions ermoeglicht
authorFrank Brehm <frank@brehm-online.com>
Wed, 19 Mar 2008 21:54:02 +0000 (21:54 +0000)
committerFrank Brehm <frank@brehm-online.com>
Wed, 19 Mar 2008 21:54:02 +0000 (21:54 +0000)
bin/show_sessions.pl [new file with mode: 0755]
frbr_books.yml
lib/FrBr/Books.pm
lib/FrBr/Books/Db/Buecher.pm
lib/FrBr/Books/Util/Book.pm
root/src/books/list.tt2

diff --git a/bin/show_sessions.pl b/bin/show_sessions.pl
new file mode 100755 (executable)
index 0000000..1b83392
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/local/bin/perl
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+# Own modules
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use FrBr::Common;
+use FrBr::Books::Db;
+use MIME::Base64 ();
+use Storable;
+use Data::Dumper;
+
+$Data::Dumper::Indent   = 1;
+$Data::Dumper::Sortkeys = 1;
+
+my $db  = 'books';
+my $title = "Sitzungsdaten:";
+
+my $dsn = 'DBI:mysql:database=' . $db . ';host=localhost';
+my $user = 'books';
+my $password = 'uhu';
+my $attrs    = {
+    'AutoCommit' => 1,
+    'PrintError' => 0,
+    'RaiseError' => 0,
+};
+
+my $schema = FrBr::Books::Db->connect( $dsn, $user, $password, $attrs );
+
+my @all_items = $schema->resultset('Session')->search( undef, {
+                'columns' => [ qw/
+                id
+                session_data
+                expires
+        / ],
+        'order_by' => 'expires' },
+      );
+
+print $title . "\n\n";
+
+for ( @all_items ) {
+    print( ( '-' x 80 ) . "\n");
+    my $data = $_->session_data;
+    $data =~ s/\s+$//s;
+    my $sess_data = Storable::thaw(MIME::Base64::decode($data));
+    my $create_time = $sess_data->{'__created'} ? ( $sess_data->{'__created'} . " (" . localtime($sess_data->{'__created'}) . ")" ) : '<undef>';
+    my $update_time = $sess_data->{'__updated'} ? ( $sess_data->{'__updated'} . " (" . localtime($sess_data->{'__updated'}) . ")" ) : '<undef>';
+        print( $_->id . ": " . Dumper($sess_data) );
+    print( "Created: " . $create_time . "\n" );
+    print( "Updated: " . $update_time . "\n" );
+    print( "Expires: " . $_->expires . " (" . localtime($_->expires) . ")\n\n");
+}
+
+exit 0;
+
index ca5378f5d8c84f3e60ef5e0db06e905e9bfcdf3b..311bfa4b63ebf17be2c9427fe22843265217c723 100644 (file)
@@ -1,10 +1,24 @@
 ---
-name: FrBr::Books
+# Der Name der Anwendung
+#;name:        Buchdatenbank Frank Brehm
+# Debug-Level
+debug_level:    0
+# Ist diese laufende Instanz eine Testumgebung?
+# is_test_environment: 0
+# Log-Level fue log4perl
+# Moegliche Werte: fatal, error, warn, info, debug
+log_level:      info
+# Soll die Log-Ausgabe farbig erfolgen ?
+colored_log:    0
+#
+# Sitzungsparameter
+session:
+   expires:     7200
 database:
-   host:   localhost
-   port:   3306
-   schema: books
-   user:   books
+   host:        localhost
+   port:        3306
+   schema:      books
+   user:        books
    # passwd:
 authentication:
    dbic:
@@ -27,4 +41,3 @@ authentication:
        # Other options can go here for hashed passwords
        password_type:      salted_hash
        password_salt_len:  4
-
index b4c59639a9b75ecc9baaec80abf3ef7f2ccc14b2..550fe5024c2ab801e2e6d7c457118e8ef9736cd3 100644 (file)
@@ -8,6 +8,8 @@ use warnings;
 
 use Catalyst::Runtime '5.70';
 
+use Sys::Hostname;
+use Catalyst::Log::Log4perl;
 use FrBr::Common;
 
 # Set flags and add plugins for the application
@@ -24,6 +26,12 @@ use Catalyst qw/
 
     Static::Simple
 
+    StackTrace
+
+    Session
+    Session::Store::DBIC
+    Session::State::Cookie
+
 /;
 
 our $VERSION = '0.01';
@@ -47,7 +55,13 @@ my %LangsToUseInDates = (
 # with a external configuration file acting as an override for
 # local deployment.
 
-__PACKAGE__->config( name => 'FrBr::Books' );
+__PACKAGE__->config(
+    'name' => 'FrBr::Books',
+    'session' => {
+        'dbic_class' => 'Schema::Session',
+        'expires'    => 3600,
+    },
+);
 
 # Start the application
 __PACKAGE__->setup;
@@ -59,6 +73,9 @@ sub auto : Private {
     my ( $self, $c ) = @_;
     my $K = __PACKAGE__ . "::auto(): ";
 
+    my $storage = $c->model('Schema')->storage;
+    $c->stash->{'storage'} = $storage;
+
     $c->config->{'debug_level'} = 0 unless defined $c->config->{'debug_level'};
     $c->log->debug( get_output_string( $K, "Aktuelle Konfiguration: ", $c->config ) ) if $c->config->{'debug_level'} >= 3;
 
@@ -67,6 +84,38 @@ sub auto : Private {
     $c->stash->{'debug_level'} = $env_debug_level if $env_debug_level and $env_debug_level > $c->stash->{'debug_level'};
     $c->log->debug( $K . "Aktuelles Debug-Level: " . $c->stash->{'debug_level'} ) if $c->stash->{'debug_level'};
 
+    $c->log->debug( get_output_string( $K . "Speicher-Objekt: ", $storage ) ) if $c->stash->{'debug_level'} >= 6;
+
+    # Feststellen, ob es eine Testumgebung ist
+    $c->stash->{'is_test_environment'} = 0;
+    if ( $c->config->{'is_test_environment'} ) {
+        $c->log->debug( $K . "TEST-Umgebung" ) if $c->stash->{'debug_level'};
+        $c->stash->{'is_test_environment'} = 1;
+    }
+
+    $storage->sql_maker->quote_char( [qw/` `/] );
+    $storage->sql_maker->name_sep('.');
+
+    $c->session->{'last_run'} = localtime();
+
+    # Letzten und aktuellen Pfad behalten
+    my $last_path = $c->session->{'last_path'} || '';
+    my $cur_path  = $c->session->{'cur_path'}  || '';
+    my $req_path  = '/' . $c->request->path();
+    if ( $req_path ne $cur_path ) {
+        $c->session->{'last_path'} = $cur_path;
+        $c->session->{'cur_path'}  = $req_path;
+    }
+
+    $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
+    push @{ $c->stash->{'menu_path'} }, { 'path' => $c->uri_for("/"), 'name' => "Home" };
+
+    # Request-URI in Sitzung einpflegen
+    $c->session->{'request'}           = {};
+    $c->session->{'request'}{'uri'}    = $c->req->uri();
+    $c->session->{'request'}{'host'}   = hostname();
+    $c->session->{'request'}{'client'} = $c->req->address();
+    $c->session->{'request'}{'uagent'} = $c->req->user_agent();
 
     ########################
     # Sprachabhaengige Dinge
index 26af92f5af84a4cc24acd734fe93d99ee72b3d99..1a195dddecbb9a268a64eb74dc137b926520974c 100644 (file)
@@ -14,6 +14,7 @@ __PACKAGE__->add_columns(
   "id"             => { data_type => "INT",       default_value => undef, is_nullable => 0, size => 10 },
   "title"          => { data_type => "VARCHAR",   default_value => undef, is_nullable => 0, size => 250, },
   "title_original" => { data_type => "VARCHAR",   default_value => undef, is_nullable => 1, size => 250, },
+  "untertitel"     => { data_type => "VARCHAR",   default_value => undef, is_nullable => 1, size => 250, },
   "bindungsart_id" => { data_type => "INT",       default_value => undef, is_nullable => 1, size => 10 },
   "verlags_id"     => { data_type => "INT",       default_value => undef, is_nullable => 0, size => 10 },
   "isbn"           => { data_type => "VARCHAR",   default_value => undef, is_nullable => 1, size => 20, },
index 8d6987c1583e73785cac010e00777dd5836c4829..90b1661ec3ef56e775a5e7e78050025a9891f1ed 100644 (file)
@@ -87,8 +87,9 @@ sub get_booklist {
         'me.id',
         'me.title',
         'me.title_original',
+        'me.untertitel',
         'me.bindungsart_id',
-        'bindungsart.art_name AS `bindungsart`',
+        'bindungsart.art_name',
         'me.verlags_id',
         'me.isbn',
         'me.buch_nr',
@@ -100,14 +101,15 @@ sub get_booklist {
         'waehrung.waehrungs_kuerzel',
         'waehrung.waehrungs_name',
         'waehrung.umrechnung_in_euro',
-        'verlag.name_short AS `verlagsname_short`',
-        'verlag.name_long AS `verlagsname_long`',
+        'verlag.name_short',
+        'verlag.name_long',
         
     ];
     $other_params->{'as'} = [
         'id',
         'title',
         'title_original',
+        'untertitel',
         'bindungsart_id',
         'bindungsart',
         'verlags_id',
@@ -132,6 +134,7 @@ sub get_booklist {
         $buch->{'id'}                 = $id;
         $buch->{'title'}              = $book->title();
         $buch->{'title_original'}     = $book->title_original();
+        $buch->{'untertitel'}         = $book->untertitel();
         $buch->{'bindungsart_id'}     = $book->bindungsart_id();
         $buch->{'bindungsart'}        = $book->get_column('bindungsart');
         $buch->{'verlags_id'}         = $book->verlags_id();
index 56ca081501d6d342da60c2a9364d872a9da84de6..6500469d9afea711f3b07ab7ded47e201849fe9a 100644 (file)
     <th>Kategorie</th>
     <th>Verlag</th>
     <th>ISBN</th>
-    <th>Buch-Nummer</th>
-    <th>Ausgabejahr</th>
-    <th>Preis</th>
-    <th>Seiten</th>
-    <th>Typ</th>
   </tr>
 [%- FOREACH book IN books -%][% buch_id = book.id %]
   <tr>
     <td>[% tt_authors = [ ]; tt_authors.push(autor) FOREACH autor = book.autoren %][% tt_authors.join(', ') %]</td>
-    <td>[% book.title %][% IF book.title_original %] ([% book.title_original %])[% END %]</td>
+    <td>[% book.title %]</td>
     <td>[% tt_cat = [ ]; tt_cat.push(cat) FOREACH cat = book.kategorien %][% tt_cat.join(',<br />') %]</td>
     <td>[% book.verlagsname_short %]</td>
     <td>[% book.isbn %]</td>
-    <td>[% book.buch_nr %]</td>
-    <td>[% book.ausgabejahr %]</td>
-    <td style="text-align: right;">[% book.preis | format '%0.2f' | replace('\.', ',') %][% IF book.waehrungs_kuerzel %]&nbsp;[% book.waehrungs_kuerzel %][% END %]</td>
-    <td style="text-align: right;">[% book.seiten %]</td>
-    <td>[% book.bindungsart %]</td>
   </tr>
 [% END -%]
 </table>