Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
vikin91 committed May 31, 2016
2 parents 124a69b + 3f5656e commit a4ce344
Show file tree
Hide file tree
Showing 27 changed files with 376 additions and 279 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
### Changelog ###

#### v0.4.1 31.05.2016 ####
* Add function to change download urls from direct file paths to file serving function
* Add function to remove attachments
* Fixing multiple minor bugs

#### v0.4 22.05.2016 ####
* Fixing multiple minor bugs
* Improving code quality with perlcritic
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# README #

BibSpace is an Online Bibtex Publications Management Software for Authors and Research Groups. Read about its features on the [BibSpace @ the Error Blog](https://blog.hex64.com/bibspace-online-bibtex-publications-management-software-for-authors-and-research-groups/).

## Build status ##

Branch | Status | Test coverage
Expand All @@ -26,4 +28,4 @@ Visit [hex64.com](http://www.hex64.com/) and click backend/frontend demo to have
- [] Describe nginx and apache2 configuration
- [] Describe cron setup
- [] ``perlcritic -4 `find ./lib -iname *.pm```
- [] Upload local list of known bugs
- [] Upload local list of known bugs
2 changes: 1 addition & 1 deletion install-bibtex2html.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -e
wget http://www.lri.fr/~filliatr/ftp/bibtex2html/bibtex2html-1.98.tar.gz
wget --no-check-certificate http://www.lri.fr/~filliatr/ftp/bibtex2html/bibtex2html-1.98.tar.gz
tar -xzvf bibtex2html-1.98.tar.gz
cd bibtex2html-1.98 && ./configure --prefix=$HOME/bibtex2html && make && make install
32 changes: 23 additions & 9 deletions lib/BibSpace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use Try::Tiny;
use Path::Tiny; # for creating directories

# for Makemake. Needs to be removed for Dist::Zilla
# our $VERSION = '0.4';
# our $VERSION = '0.4.1';

# 0 4,12,20 * * * curl http://localhost:8081/cron/day
# 0 2 * * * curl http://localhost:8081/cron/night
Expand Down Expand Up @@ -57,7 +57,7 @@ has db => sub {

has version => sub {
my $self = shift;
return $BibSpace::VERSION // "0.4";
return $BibSpace::VERSION // "0.4.1";
};


Expand All @@ -72,18 +72,28 @@ sub startup {
push @{$self->app->static->paths}, $self->app->home->rel_dir('public');
# push @{$self->app->static->paths}, $self->config->{backups_dir};

say "Using config: ".$self->app->config_file;
say "App version: ".$self->app->version;
$config = $self->plugin('Config' => {file => $self->app->config_file});

$self->hook(before_dispatch => sub {
my $c = shift;
$c->req->url->base->scheme('https') if $c->req->headers->header('X-Forwarded-HTTPS');

# TODO!!
# only for directory deployment!!
# push @{$c->req->url->base->path->trailing_slash(1)}, shift @{$c->req->url->path->leading_slash(0)};

# dirty fix for production deployment in a directory
my $proxy_prefix = $self->config->{proxy_prefix};
if($proxy_prefix ne ""){
# we remove the leading slash
$proxy_prefix =~ s|^/||;
push @{$c->req->url->base->path->trailing_slash(1)}, $proxy_prefix;
}
});

say "Using config: ".$self->app->config_file;
say "App version: ".$self->app->version;
$config = $self->plugin('Config' => {file => $self->app->config_file});


say "Creating directories.";

Expand Down Expand Up @@ -313,8 +323,9 @@ sub startup {
# EXPERIMENTAL
$logged_user->get('/publications-set')->to('publications#all_defined_by_set');
# description of this function is included with the code
# $anyone->get('/publications/special/:id')->to('publications#special_map_pdf_to_local_file'); # use with extreeme caution!
$superadmin->get('/publications/fix_urls')->to('publications#replace_urls_to_file_serving_function');
# $anyone->get('/publications/special/:id')->to('publications#special_map_pdf_to_local_file'); # use with extreme caution!
$logged_user->get('/publications/sdqpdf')->to('publications#all_with_pdf_on_sdq');
$superadmin->get('/publications/fix_urls')->to('publications#replace_urls_to_file_serving_function')->name('fix_attachment_urls');
# EXPERIMENTAL END

$logged_user->get('/publications')->to('publications#all'); # logged_user icons!
Expand All @@ -327,9 +338,12 @@ sub startup {
$logged_user->get('/publications/candidates_to_delete')->to('publications#all_candidates_to_delete');
$logged_user->get('/publications/missing_month')->to('publications#all_without_missing_month');

$logged_user->get('/publications/sdqpdf')->to('publications#all_with_pdf_on_sdq');
$logged_user->get('/publications/get/:id')->to('publications#single');
$logged_user->get('/publications/download/:filetype/:id')->to('publications#download')->name('download_publication');
#
$anyone->get('/publications/download/:filetype/:id')->to('publications#download')->name('download_publication');
$anyone->get('/publications/download/:filetype/(:id).pdf')->to('publications#download')->name('download_publication_pdf');
#
$logged_user->get('/publications/remove_attachment/:filetype/:id')->to('publications#remove_attachment')->name('publications_remove_attachment');

$logged_user->get('/publications/hide/:id')->to('publications#hide');
$logged_user->get('/publications/unhide/:id')->to('publications#unhide');
Expand Down
13 changes: 9 additions & 4 deletions lib/BibSpace/Controller/BackupFunctions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,24 @@ sub do_delete_backup{ # added 22.08.14

say "call BackupFunctions::do_delete_backup";


my $backup_dir_absolute = $self->config->{backups_dir};
$backup_dir_absolute =~ s!/*$!/!;


my $sth = $dbh->prepare("SELECT filename FROM Backup WHERE id = ?");
$sth->execute($id);
my $row = $sth->fetchrow_hashref();
my $fname = $row->{filename};

my $sth2 = $dbh->prepare("DELETE FROM Backup WHERE id=?");
$sth2->execute($id);
my $file_path = $backup_dir_absolute.$fname;
my $exists = 1 if -e $file_path;
say "do_delete_backup deletes file: $file_path exists $exists";

$self->write_log("destroying backup id $id");

unlink $fname;
my $sth2 = $dbh->prepare("DELETE FROM Backup WHERE id=?");
$sth2->execute($id);
unlink $file_path;
}
####################################################################################
sub do_delete_broken_or_old_backup { # added 22.08.14
Expand Down
38 changes: 19 additions & 19 deletions lib/BibSpace/Controller/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ our @EXPORT = qw(
get_html_for_entry_id
get_exceptions_for_entry_id
get_year_for_entry_id
clean_ugly_bibtex_fileds
clean_ugly_bibtex_fileds_for_all_entries
clean_ugly_bibtex_fields
clean_ugly_bibtex_fields_for_all_entries
prepare_backup_table
get_month_numeric
get_current_year
Expand Down Expand Up @@ -149,7 +149,6 @@ sub get_publications_core_from_set{
####################################################################################

sub get_publications_core{
# say "CALL: get_publications_core";
my $self = shift;
my $author = shift;
my $year = shift;
Expand All @@ -161,9 +160,13 @@ sub get_publications_core{
my $permalink = shift;
my $hidden = shift;

# say "CALL: get_publications_core author $author tag $tag";

my $dbh = $self->app->db;

my $teamid = get_team_id($dbh, $team) || undef;
my $teamid = get_team_id($dbh, $team) || undef; # gives -1 if $team contains id
$teamid = $team if defined $teamid and $teamid eq -1; # so team = teamid

my $master_id = get_master_id_for_master($dbh, $author) || undef;
if($master_id == -1){
$master_id = $author; # it means that author was given as master_id and not as master name
Expand All @@ -177,8 +180,7 @@ sub get_publications_core{

$teamid = undef unless defined $team;
$master_id = undef unless defined $author;
$tagid = undef unless defined $tag;

$tagid = undef unless defined $tag;

my @objs = BibSpace::Functions::EntryObj->getByFilter($dbh, $master_id, $year, $bibtex_type, $entry_type, $tagid, $teamid, $visible, $permalink, $hidden);
return @objs;
Expand Down Expand Up @@ -276,7 +278,7 @@ sub nohtml{
sub postprocess_all_entries_after_author_uids_change{ # assigns papers to their authors ONLY. No tags, no regeneration.
my $self = shift;

$self->write_log("reassing papers to authors started");
$self->write_log("reassign papers to authors started");

my $qry = "SELECT DISTINCT bibtex_key, id, bib FROM Entry";
my $sth = $self->app->db->prepare( $qry );
Expand All @@ -299,7 +301,7 @@ sub postprocess_all_entries_after_author_uids_change{ # assigns papers to their
assign_entry_to_existing_authors_no_add($self, $entry_obj);
}

$self->write_log("reassing papers to authors finished");
$self->write_log("reassign papers to authors finished");
};

##################################################################
Expand Down Expand Up @@ -338,25 +340,24 @@ sub postprocess_all_entries_after_author_uids_change_w_creating_authors{ # assi
};

####################################################################################
sub clean_ugly_bibtex_fileds_for_all_entries {
# clean_ugly_bibtex_fileds_for_all_entries
sub clean_ugly_bibtex_fields_for_all_entries {
my $self = shift;
my $dbh = $self->app->db;
$self->write_log("clean_ugly_bibtex_fileds_for_all_entries started");
$self->write_log("clean_ugly_bibtex_fields_for_all_entries started");


my @ids = get_all_entry_ids($dbh);
for my $id (@ids){
clean_ugly_bibtex_fileds($dbh, $id);
clean_ugly_bibtex_fields($dbh, $id);
}
$self->write_log("clean_ugly_bibtex_fileds_for_all_entries finished");
$self->write_log("clean_ugly_bibtex_fields_for_all_entries finished");
};
####################################################################################
sub clean_ugly_bibtex_fileds {
sub clean_ugly_bibtex_fields {
my $dbh = shift;
my $eid = shift;

# TODO: move this into config
our @bib_fields_to_delete = qw(bdsk-url-1 bdsk-url-2 bdsk-url-3 date-added date-modified owner tags);
my @bib_fields_to_delete = shift || qw(bdsk-url-1 bdsk-url-2 bdsk-url-3 date-added date-modified owner tags);

my @ary = $dbh->selectrow_array("SELECT bib FROM Entry WHERE id = ?", undef, $eid);
my $entry_str = $ary[0];
Expand All @@ -377,7 +378,7 @@ sub clean_ugly_bibtex_fileds {
my $new_bib = $entry->print_s;


# celaning errors caused by sqlite - mysql import
# cleaning errors caused by sqlite - mysql import

$new_bib =~ s/''\{(.)\}/"\{$1\}/g;
$new_bib =~ s/"\{(.)\}/\\"\{$1\}/g;
Expand All @@ -394,6 +395,7 @@ sub clean_ugly_bibtex_fileds {
}
};


##################################################################

sub assign_entry_to_existing_authors_no_add{
Expand Down Expand Up @@ -562,8 +564,6 @@ sub delete_entry_by_id{

my $sth3 = $dbh->prepare( "DELETE FROM Entry_to_Author WHERE entry_id = ?" );
$sth3->execute($id);

warn "FIXME: delete_entry_by_id. Pdf file should be deleted from file system as well";
};
################################################################################
sub get_all_non_hidden_entry_ids{
Expand Down
2 changes: 1 addition & 1 deletion lib/BibSpace/Controller/Cron.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ sub cron_week {

############ Cron ACTIONS
# $self->helper_reassign_papers_to_authors(); #can be anbled later
# $self->helper_clean_ugly_bibtex_fileds_for_all_entries(); #can be enabled later
# $self->helper_$self->helper_clean_ugly_bibtex_fields_for_all_entries(); #can be enabled later
$self->helper_do_delete_broken_or_old_backup();
############ Cron ACTIONS STOP

Expand Down
4 changes: 2 additions & 2 deletions lib/BibSpace/Controller/CronHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ sub register {



$app->helper(helper_clean_ugly_bibtex_fileds_for_all_entries => sub {
$app->helper(helper_clean_ugly_bibtex_fields_for_all_entries => sub {
my $self = shift;
clean_ugly_bibtex_fileds_for_all_entries($self);
clean_ugly_bibtex_fields_for_all_entries($self);
});


Expand Down
Loading

0 comments on commit a4ce344

Please sign in to comment.