- if (%{ $self->{SESSION} }) {
- my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|;
- my $sth = prepare_query($::form, $dbh, $query);
+ if ($self->{column_information}->has('api_token', 'session')) {
+ my ($stored_api_token) = $dbh->selectrow_array(qq|SELECT api_token FROM auth.session WHERE id = ?|, undef, $session_id);
+ do_query($::form, $dbh, qq|UPDATE auth.session SET api_token = ? WHERE id = ?|, $self->_create_session_id, $session_id) unless $stored_api_token;
+ }
+
+ my @values_to_save = grep { $_->{fetched} }
+ values %{ $self->{SESSION} };
+ if (@values_to_save) {
+ my ($columns, $placeholders) = ('', '');
+ my $auto_restore = $self->{column_information}->has('auto_restore');
+
+ if ($auto_restore) {
+ $columns .= ', auto_restore';
+ $placeholders .= ', ?';
+ }
+
+ $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value ${columns}) VALUES (?, ?, ? ${placeholders})|;
+ my $sth = prepare_query($::form, $dbh, $query);
+
+ foreach my $value (@values_to_save) {
+ my @values = ($value->{key}, $value->get_dumped);
+ push @values, $value->{auto_restore} if $auto_restore;