# Copyright (c) 2009 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: RealmFileMD5List.pm,v 1.4 2009/03/08 12:50:13 nagler Exp $ package Bivio::Biz::Model::RealmFileMD5List; use strict; use Bivio::Base 'Biz.ListModel'; use Digest::MD5 (); our($VERSION) = sprintf('%d.%02d', q$Revision: 1.4 $ =~ /\d+/g); my($_RF) = b_use('Model.RealmFile'); my($_FP) = b_use('Type.FilePath'); my($_IDI) = __PACKAGE__->instance_data_index; sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { version => 1, can_iterate => 1, auth_id => 'RealmFile.realm_id', primary_key => ['RealmFile.realm_file_id'], order_by => [qw( RealmFile.path )], $self->field_decl(other => [[qw(md5 Name)]]), other_query_keys => [qw(path_info)], }); } sub internal_post_load_row { my($self, $row) = @_; return 0 unless shift->SUPER::internal_post_load_row(@_); my($md5) = Digest::MD5->new; $md5->addfile($_RF->get_handle($self, 'RealmFile.', $row)); $row->{md5} = $md5->b64digest; return 1; } sub internal_prepare_statement { my($self, $stmt, $query) = @_; my($p) = $_RF->parse_path($query->unsafe_get('path_info'), $self); $p = $_FP->join(lc($p), '%'); $stmt->where( ['RealmFile.is_folder', [0]], $stmt->NOT_LIKE( 'RealmFile.path_lc', $_FP->join(lc($_FP->VERSIONS_FOLDER), '%')), $stmt->LIKE('RealmFile.path_lc', $p), ); return shift->SUPER::internal_prepare_statement(@_); } 1;