DB/Schema/Result/ItemAttachment.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 98.1% 54 / 55 CC 3 SCAR 4.4
CC
3
Cov
100%
uri
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« DB/Role/CopyDB.pm ↑ Summary DB/Schema/ResultSet/Item.pm »
1 13 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Biblio::Zotero::DB::Schema::Result::ItemAttachment;
3 13 $Biblio::Zotero::DB::Schema::Result::ItemAttachment::VERSION = '0.004';
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
6  
7  
8 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 ▶use base 'DBIx::Class::Core';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 13 __PACKAGE__->table("itemAttachments");
15  
16  
17 13 __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 13 __PACKAGE__->set_primary_key("itemid");
47  
48  
49 13 __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 13 __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 13 __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 13 __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 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 13 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 13 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 13 ▶use Path::Class::URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 # TODO: document
97 3 ▶sub uri {
Subroutine uri: called CC=3 SCAR=11.0
Pod undocumented
98 3 my ($self) = @_;
99 # TODO handle case where the item in not an attachment
100 3 ▶ if(not defined $self->path) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->path) { } 1 2 3
elsif ($self->path =~ /^storage:/) { } 1 1 2
101 # get URI from ItemDataValue table
102 1 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 my $key = $self->itemid->key;
110 1 my $subdir = $self->result_source->schema->zotero_storage_directory()->subdir($key);
111  
112 1 my $subdir_uri = $subdir->uri->as_string;
113  
114 1 URI->new_abs( uri_escape( $self->path =~ s/^storage://r ),
115 # escaping URI because it may not be actually escaped properly in the DB
116 $subdir_uri
117 );
118 } else {
119 # link to file
120 1 file($self->path)->uri; # NOTE this needs to be check for Zotero on non-Unix systems
121 }
122 }
123  
124 13 1;
125  
126 __END__
« DB/Role/CopyDB.pm ↑ Summary DB/Schema/ResultSet/Item.pm »