line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
13
|
|
|
13
|
|
12147
|
use utf8; |
|
13
|
|
|
|
|
80
|
|
|
13
|
|
|
|
|
137
|
|
2
|
|
|
|
|
|
|
package Biblio::Zotero::DB::Schema::Result::ItemAttachment; |
3
|
|
|
|
|
|
|
$Biblio::Zotero::DB::Schema::Result::ItemAttachment::VERSION = '0.003'; |
4
|
|
|
|
|
|
|
# Created by DBIx::Class::Schema::Loader |
5
|
|
|
|
|
|
|
# DO NOT MODIFY THE FIRST PART OF THIS FILE |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
686
|
use strict; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
367
|
|
9
|
13
|
|
|
13
|
|
80
|
use warnings; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
331
|
|
10
|
|
|
|
|
|
|
|
11
|
13
|
|
|
13
|
|
63
|
use base 'DBIx::Class::Core'; |
|
13
|
|
|
|
|
35
|
|
|
13
|
|
|
|
|
4212
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->table("itemAttachments"); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
18
|
|
|
|
|
|
|
"itemid", |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
data_type => "integer", |
21
|
|
|
|
|
|
|
is_auto_increment => 1, |
22
|
|
|
|
|
|
|
is_foreign_key => 1, |
23
|
|
|
|
|
|
|
is_nullable => 0, |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
"sourceitemid", |
26
|
|
|
|
|
|
|
{ data_type => "int", is_foreign_key => 1, is_nullable => 1 }, |
27
|
|
|
|
|
|
|
"linkmode", |
28
|
|
|
|
|
|
|
{ data_type => "int", is_nullable => 1 }, |
29
|
|
|
|
|
|
|
"mimetype", |
30
|
|
|
|
|
|
|
{ data_type => "text", is_nullable => 1 }, |
31
|
|
|
|
|
|
|
"charsetid", |
32
|
|
|
|
|
|
|
{ data_type => "int", is_nullable => 1 }, |
33
|
|
|
|
|
|
|
"path", |
34
|
|
|
|
|
|
|
{ data_type => "text", is_nullable => 1 }, |
35
|
|
|
|
|
|
|
"originalpath", |
36
|
|
|
|
|
|
|
{ data_type => "text", is_nullable => 1 }, |
37
|
|
|
|
|
|
|
"syncstate", |
38
|
|
|
|
|
|
|
{ data_type => "int", default_value => 0, is_nullable => 1 }, |
39
|
|
|
|
|
|
|
"storagemodtime", |
40
|
|
|
|
|
|
|
{ data_type => "int", is_nullable => 1 }, |
41
|
|
|
|
|
|
|
"storagehash", |
42
|
|
|
|
|
|
|
{ data_type => "text", is_nullable => 1 }, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__PACKAGE__->set_primary_key("itemid"); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
50
|
|
|
|
|
|
|
"annotations", |
51
|
|
|
|
|
|
|
"Biblio::Zotero::DB::Schema::Result::Annotation", |
52
|
|
|
|
|
|
|
{ "foreign.itemid" => "self.itemid" }, |
53
|
|
|
|
|
|
|
{ cascade_copy => 0, cascade_delete => 0 }, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__PACKAGE__->has_many( |
58
|
|
|
|
|
|
|
"highlights", |
59
|
|
|
|
|
|
|
"Biblio::Zotero::DB::Schema::Result::Highlight", |
60
|
|
|
|
|
|
|
{ "foreign.itemid" => "self.itemid" }, |
61
|
|
|
|
|
|
|
{ cascade_copy => 0, cascade_delete => 0 }, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__PACKAGE__->belongs_to( |
66
|
|
|
|
|
|
|
"itemid", |
67
|
|
|
|
|
|
|
"Biblio::Zotero::DB::Schema::Result::Item", |
68
|
|
|
|
|
|
|
{ itemid => "itemid" }, |
69
|
|
|
|
|
|
|
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->belongs_to( |
74
|
|
|
|
|
|
|
"sourceitemid", |
75
|
|
|
|
|
|
|
"Biblio::Zotero::DB::Schema::Result::Item", |
76
|
|
|
|
|
|
|
{ itemid => "sourceitemid" }, |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
is_deferrable => 0, |
79
|
|
|
|
|
|
|
join_type => "LEFT", |
80
|
|
|
|
|
|
|
on_delete => "NO ACTION", |
81
|
|
|
|
|
|
|
on_update => "NO ACTION", |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-07-02 23:02:38 |
87
|
|
|
|
|
|
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:u4JJM71EtePId8XMpq4WOQ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# NOTE: extended DBIC schema below |
90
|
|
|
|
|
|
|
|
91
|
13
|
|
|
13
|
|
88
|
use URI; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
349
|
|
92
|
13
|
|
|
13
|
|
72
|
use URI::Escape; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
1044
|
|
93
|
13
|
|
|
13
|
|
79
|
use Path::Class; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
688
|
|
94
|
13
|
|
|
13
|
|
71
|
use Path::Class::URI; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
162
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# TODO: document |
97
|
|
|
|
|
|
|
sub uri { |
98
|
3
|
|
|
3
|
0
|
13405
|
my ($self) = @_; |
99
|
|
|
|
|
|
|
# TODO handle case where the item in not an attachment |
100
|
3
|
100
|
|
|
|
81
|
if(not defined $self->path) { |
|
|
100
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# get URI from ItemDataValue table |
102
|
1
|
|
|
|
|
41
|
URI->new( $self->itemid->item_datas_rs->find( |
103
|
|
|
|
|
|
|
{ 'fieldid.fieldname' => 'url', }, |
104
|
|
|
|
|
|
|
{ prefetch => [ 'fieldid', 'valueid' ] } |
105
|
|
|
|
|
|
|
)->valueid->value ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
elsif($self->path =~ /^storage:/) { |
108
|
|
|
|
|
|
|
# link to file in storage |
109
|
1
|
|
|
|
|
67
|
my $key = $self->itemid->key; |
110
|
1
|
|
|
|
|
107
|
my $subdir = $self->result_source->schema->zotero_storage_directory()->subdir($key); |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
130
|
my $subdir_uri = $subdir->uri->as_string; |
113
|
|
|
|
|
|
|
# TODO the regex below is a fix for Path::Class::URI. Remove later when new version is released. |
114
|
1
|
50
|
|
|
|
129
|
$subdir_uri .= "/" if $subdir_uri !~ m,/$,,; # force to be directory |
115
|
|
|
|
|
|
|
# NOTE: see bug report for Path::Class::URI: |
116
|
|
|
|
|
|
|
# , |
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
23
|
URI->new_abs( uri_escape( $self->path =~ s/^storage://r ), |
120
|
|
|
|
|
|
|
# escaping URI because it may not be actually escaped properly in the DB |
121
|
|
|
|
|
|
|
$subdir_uri |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} else { |
124
|
|
|
|
|
|
|
# link to file |
125
|
1
|
|
|
|
|
73
|
file($self->path)->uri; # NOTE this needs to be check for Zotero on non-Unix systems |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |