View | Details | Raw Unified | Return to bug 28410
Collapse All | Expand All

(-)a/C4/Context.pm (-35 / +9 lines)
Lines 41-49 use File::Spec; Link Here
41
use List::MoreUtils qw(any);
41
use List::MoreUtils qw(any);
42
42
43
use Koha::Caches;
43
use Koha::Caches;
44
use Koha::Config::SysPref;
45
use Koha::Config::SysPrefs;
46
use Koha::Config;
44
use Koha::Config;
45
use Koha::Database;
47
use Koha;
46
use Koha;
48
47
49
=head1 NAME
48
=head1 NAME
Lines 316-324 sub preference { Link Here
316
        return $cached_var if defined $cached_var;
315
        return $cached_var if defined $cached_var;
317
    }
316
    }
318
317
319
    my $syspref;
318
    my ($value) = $self->dbh()->selectrow_array("SELECT value FROM systempreferences WHERE variable like '$var'"); 
320
    eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) };
321
    my $value = $syspref ? $syspref->value() : undef;
322
319
323
    if ( $use_syspref_cache ) {
320
    if ( $use_syspref_cache ) {
324
        my $syspref_cache = Koha::Caches->get_instance('syspref');
321
        my $syspref_cache = Koha::Caches->get_instance('syspref');
Lines 430-439 sub set_preference { Link Here
430
    my $variable_case = $variable;
427
    my $variable_case = $variable;
431
    $variable = lc $variable;
428
    $variable = lc $variable;
432
429
433
    my $syspref = Koha::Config::SysPrefs->find($variable);
430
    my ($oldvalue, $oldtype) = $self->dbh()->selectrow_array("SELECT value FROM systempreferences WHERE variable like '$variable'");
434
    $type =
431
    $type =
435
        $type    ? $type
432
        $type    ? $type
436
      : $syspref ? $syspref->type
433
      : defined $oldtype ? $oldtype
437
      :            undef;
434
      :            undef;
438
435
439
    $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' );
436
    $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' );
Lines 443-473 sub set_preference { Link Here
443
        $value = 'http://' . $value;
440
        $value = 'http://' . $value;
444
    }
441
    }
445
442
446
    if ($syspref) {
443
    $self->dbh()->do("INSERT INTO systempreferencesi (variable, value, explanation, type, options) values ($variable, $value, $explanation, $type, $options) ON DUPLICATE KEY UPDATE value = $value");
447
        $syspref->set(
448
            {   ( defined $value ? ( value       => $value )       : () ),
449
                ( $explanation   ? ( explanation => $explanation ) : () ),
450
                ( $type          ? ( type        => $type )        : () ),
451
                ( $options       ? ( options     => $options )     : () ),
452
            }
453
        )->store;
454
    } else {
455
        $syspref = Koha::Config::SysPref->new(
456
            {   variable    => $variable_case,
457
                value       => $value,
458
                explanation => $explanation || undef,
459
                type        => $type,
460
                options     => $options || undef,
461
            }
462
        )->store();
463
    }
464
444
465
    if ( $use_syspref_cache ) {
445
    if ( $use_syspref_cache ) {
466
        my $syspref_cache = Koha::Caches->get_instance('syspref');
446
        my $syspref_cache = Koha::Caches->get_instance('syspref');
467
        $syspref_cache->set_in_cache( "syspref_$variable", $value );
447
        $syspref_cache->set_in_cache( "syspref_$variable", $value );
468
    }
448
    }
469
449
470
    return $syspref;
471
}
450
}
472
451
473
=head2 delete_preference
452
=head2 delete_preference
Lines 483-497 was no syspref of the name. Link Here
483
sub delete_preference {
462
sub delete_preference {
484
    my ( $self, $var ) = @_;
463
    my ( $self, $var ) = @_;
485
464
486
    if ( Koha::Config::SysPrefs->find( $var )->delete ) {
465
    my $rc = $self->dbh()->do("DELETE FROM systempreferences WHERE variable like '$var'");
487
        if ( $use_syspref_cache ) {
466
    if ( $use_syspref_cache ) {
488
            my $syspref_cache = Koha::Caches->get_instance('syspref');
467
        my $syspref_cache = Koha::Caches->get_instance('syspref');
489
            $syspref_cache->clear_from_cache("syspref_$var");
468
        $syspref_cache->clear_from_cache("syspref_$var");
490
        }
491
492
        return 1;
493
    }
469
    }
494
    return 0;
495
}
470
}
496
471
497
=head2 csv_delimiter
472
=head2 csv_delimiter
498
- 

Return to bug 28410