From: Frank Brehm Date: Wed, 19 Mar 2008 21:54:02 +0000 (+0000) Subject: Sessions ermoeglicht X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=5c1d9c1a21948b0ec596728580dbbb8e5d175674;p=books.git Sessions ermoeglicht --- diff --git a/bin/show_sessions.pl b/bin/show_sessions.pl new file mode 100755 index 0000000..1b83392 --- /dev/null +++ b/bin/show_sessions.pl @@ -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'}) . ")" ) : ''; + my $update_time = $sess_data->{'__updated'} ? ( $sess_data->{'__updated'} . " (" . localtime($sess_data->{'__updated'}) . ")" ) : ''; + print( $_->id . ": " . Dumper($sess_data) ); + print( "Created: " . $create_time . "\n" ); + print( "Updated: " . $update_time . "\n" ); + print( "Expires: " . $_->expires . " (" . localtime($_->expires) . ")\n\n"); +} + +exit 0; + diff --git a/frbr_books.yml b/frbr_books.yml index ca5378f..311bfa4 100644 --- a/frbr_books.yml +++ b/frbr_books.yml @@ -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 - diff --git a/lib/FrBr/Books.pm b/lib/FrBr/Books.pm index b4c5963..550fe50 100644 --- a/lib/FrBr/Books.pm +++ b/lib/FrBr/Books.pm @@ -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 diff --git a/lib/FrBr/Books/Db/Buecher.pm b/lib/FrBr/Books/Db/Buecher.pm index 26af92f..1a195dd 100644 --- a/lib/FrBr/Books/Db/Buecher.pm +++ b/lib/FrBr/Books/Db/Buecher.pm @@ -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, }, diff --git a/lib/FrBr/Books/Util/Book.pm b/lib/FrBr/Books/Util/Book.pm index 8d6987c..90b1661 100644 --- a/lib/FrBr/Books/Util/Book.pm +++ b/lib/FrBr/Books/Util/Book.pm @@ -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(); diff --git a/root/src/books/list.tt2 b/root/src/books/list.tt2 index 56ca081..6500469 100644 --- a/root/src/books/list.tt2 +++ b/root/src/books/list.tt2 @@ -14,24 +14,14 @@ Kategorie Verlag ISBN - Buch-Nummer - Ausgabejahr - Preis - Seiten - Typ [%- FOREACH book IN books -%][% buch_id = book.id %] [% tt_authors = [ ]; tt_authors.push(autor) FOREACH autor = book.autoren %][% tt_authors.join(', ') %] - [% book.title %][% IF book.title_original %] ([% book.title_original %])[% END %] + [% book.title %] [% tt_cat = [ ]; tt_cat.push(cat) FOREACH cat = book.kategorien %][% tt_cat.join(',
') %] [% book.verlagsname_short %] [% book.isbn %] - [% book.buch_nr %] - [% book.ausgabejahr %] - [% book.preis | format '%0.2f' | replace('\.', ',') %][% IF book.waehrungs_kuerzel %] [% book.waehrungs_kuerzel %][% END %] - [% book.seiten %] - [% book.bindungsart %] [% END -%]