Skip to content

Commit

Permalink
remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vpeil committed Oct 11, 2018
1 parent 7c820ed commit 5513e90
Showing 1 changed file with 0 additions and 160 deletions.
160 changes: 0 additions & 160 deletions lib/LibreCat/App/Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -261,166 +261,6 @@ sub get_statistics {
};
}

sub new_record {
my ($self, $bag) = @_;
$self->log->warn(
'DEPRECATION NOTICE: new_record is deprecated. Use librecat->model($model)->generate_id instead'
);
Catmandu->store('main')->bag($bag)->generate_id;
}

sub update_record {
my ($self, $bag, $rec) = @_;
$self->log->warn(
'DEPRECATION NOTICE: update_record is deprecated. Use librecat->model($model)->add instead'
);

my $saved_record = $self->store_record($bag, $rec);

$self->index_record($bag, $saved_record);

sleep 1; # bad hack!

$rec;
}

sub store_record {
my ($self, $bag, $rec, %opts) = @_;
$self->log->warn(
'DEPRECATION NOTICE: store_record is deprecated. Use librecat->model($model)->add instead'
);

# don't know where to put it, should find better place to handle this
# especially the async stuff
if ($bag eq 'publication') {
require LibreCat::App::Catalogue::Controller::File;
require LibreCat::App::Catalogue::Controller::Material;

LibreCat::App::Catalogue::Controller::File::handle_file($rec);

if ($rec->{related_material}) {
LibreCat::App::Catalogue::Controller::Material::update_related_material(
$rec);
}

# Set for every update the user-id of the last editor
unless ($rec->{user_id}) {

# Edit by a user via the command line?
my $super_id = $self->config->{store}->{builtin_users}->{options}
->{init_data}->[0]->{_id} // 'undef';
$rec->{user_id} = $super_id;
}
}

# memoize fixes
state $fixes = {};
my $fix = $fixes->{$bag} //= $self->create_fixer("update_$bag.fix");
$fix->fix($rec);

state $cite_fix = Catmandu::Fix->new(fixes => ["add_citation()"]);
if ($bag eq 'publication') {
$cite_fix->fix($rec) unless $opts{skip_citation};
}

my $can_store = 1;

if (librecat->has_model($bag)) {
my $model = librecat->model($bag);

unless ($model->is_valid($rec)) {
$can_store = 0;
$opts{validation_error}->($model->validator, $rec)
if $opts{validation_error}
&& ref($opts{validation_error}) eq 'CODE';
}
}

if ($can_store) {
my $bagname = "main_$bag";
$self->log->debug("storing record in $bagname...");
$self->log->debug(Dancer::to_json($rec));
my $saved_record = $self->$bagname->add($rec);
$self->$bagname->commit;
return $saved_record;
}
else {
return undef;
}
}

sub index_record {
my ($self, $bag, $rec) = @_;
$self->log->warn(
'DEPRECATION NOTICE: index_record is deprecated. Use librecat->model($model)->add instead'
);

#compare version! through _version or through date_updated
$self->log->debug("indexing record in $bag...");

# memoize fixes
state $fixes = {};
my $fix = $fixes->{$bag} //= $self->create_fixer("index_$bag.fix");
$fix->fix($rec);

$self->log->debug(Dancer::to_json($rec));
$self->$bag->add($rec);
$self->$bag->commit;
$rec;
}

sub delete_record {
my ($self, $bag, $id) = @_;
$self->log->warn(
'DEPRECATION NOTICE: delete_record is deprecated. Use librecat->model($model)->delete instead'
);

if ($bag eq 'publication') {
my $del_record = $self->publication->get($id);

return undef unless $del_record;

if ($del_record->{oai_deleted} || $del_record->{status} eq 'public') {
$del_record->{oai_deleted} = 1;
$del_record->{locked} = 1;
}

$del_record->{date_deleted} = $self->now;
$del_record->{status} = 'deleted';

my $saved = $self->main_publication->add($del_record);
$self->main_publication->commit;
$self->publication->add($saved);
$self->publication->commit;

sleep 1;

return $saved;
}
else {
$self->purge_record($bag, $id);
return +{};
}
}

sub purge_record {
my ($self, $bag, $id) = @_;
$self->log->warn(
'DEPRECATION NOTICE: delete_record is deprecated. Use librecat->model($model)->purge instead'
);

# Delete from the index store
$self->$bag->delete($id);
$self->$bag->commit;

# Delete from the main store
my $bagname = "main_$bag";
$self->$bagname->delete($id);
$self->$bagname->commit;

return 1;
}

sub uri_base {

#config option 'host' is deprecated
Expand Down

0 comments on commit 5513e90

Please sign in to comment.