From 2999e4ac599f7d2b1f50ca9f03efc6056ee9f30b Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 6 Aug 2015 15:34:57 +0200 Subject: [PATCH] Bug 14321: Add public column to uploaded_files Content-Type: text/plain; charset=utf-8 This patch adds uploaded_files.public. This column will be used to mark uploaded files as available via opac-retrieve. The db rev sets this flag for current records having a category (as uploaded via the BZ 6874 plugin: so public). A followup patch will adjust the plugin to use Koha::Upload. Test plan: [1] Run the dbrev. [2] Add a record (upload a file) via stage-marc-import. [3] Check that public is null in the new record. (This is a temporary file without category.) --- Koha/Upload.pm | 5 ++++- installer/data/mysql/atomicupdate/14321a_public.sql | 2 ++ installer/data/mysql/kohastructure.sql | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/14321a_public.sql diff --git a/Koha/Upload.pm b/Koha/Upload.pm index f1dd5c5..8501218 100644 --- a/Koha/Upload.pm +++ b/Koha/Upload.pm @@ -169,6 +169,7 @@ sub _init { } $self->{files} = {}; $self->{uid} = C4::Context->userenv->{number} if C4::Context->userenv; + $self->{public} = $params->{public}? 1: undef; } sub _fh { @@ -251,13 +252,14 @@ sub _register { my ( $self, $filename, $size ) = @_; my $dbh= C4::Context->dbh; my $sql= "INSERT INTO uploaded_files (hashvalue, filename, dir, filesize, - owner, categorycode) VALUES (?,?,?,?,?,?)"; + owner, categorycode, public) VALUES (?,?,?,?,?,?,?)"; my @pars= ( $self->{files}->{$filename}->{hash}, $filename, $self->{temporary}? KOHA_UPLOAD: $self->{category}, $size, $self->{uid}, $self->{category}, + $self->{public}, ); $dbh->do( $sql, undef, @pars ); my $i = $dbh->last_insert_id(undef, undef, 'uploaded_files', undef); @@ -274,6 +276,7 @@ sub _lookup { } else { $sql.= "WHERE hashvalue=?"; } + $sql.= $self->{public}? " AND public=1": ''; my $temp= $dbh->selectall_arrayref( $sql, { Slice => {} }, ( $params->{id} // $params->{hashvalue} // 0 ) ); return $temp; diff --git a/installer/data/mysql/atomicupdate/14321a_public.sql b/installer/data/mysql/atomicupdate/14321a_public.sql new file mode 100644 index 0000000..ba3e816 --- /dev/null +++ b/installer/data/mysql/atomicupdate/14321a_public.sql @@ -0,0 +1,2 @@ +ALTER TABLE uploaded_files ADD COLUMN public tinyint; +UPDATE uploaded_files SET public=1 WHERE categorycode IS NOT NULL; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 13b6a6a..aca8aec 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3374,6 +3374,7 @@ CREATE TABLE uploaded_files ( dtcreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, categorycode tinytext, owner int(11), + public tinyint, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- 1.7.10.4