line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Changeset::HistoryRecord; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
4767
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
165
|
|
4
|
4
|
|
|
4
|
|
29
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
159
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
21
|
use base qw/DBIx::Changeset/; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
3309
|
|
7
|
4
|
|
|
4
|
|
79447
|
use DBI; |
|
4
|
|
|
|
|
74783
|
|
|
4
|
|
|
|
|
263
|
|
8
|
4
|
|
|
4
|
|
977
|
use Exception::Class::DBI; |
|
4
|
|
|
|
|
3599
|
|
|
4
|
|
|
|
|
149
|
|
9
|
4
|
|
|
4
|
|
16888
|
use DateTime; |
|
4
|
|
|
|
|
811127
|
|
|
4
|
|
|
|
|
168
|
|
10
|
4
|
|
|
4
|
|
4543
|
use DateTime::Format::ISO8601; |
|
4
|
|
|
|
|
229987
|
|
|
4
|
|
|
|
|
358
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
58
|
use vars qw{$VERSION}; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
292
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
4
|
|
|
4
|
|
2781
|
$VERSION = '1.11'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
DBIx::Changeset::HistoryRecord - Object to query a changeset record log entry |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Object to query a changeset record log entry |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use DBIx::Changeset::HistoryRecord; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $foo = DBIx::Changeset::HistoryRecord->new(); |
28
|
|
|
|
|
|
|
... |
29
|
|
|
|
|
|
|
$foo->find_all(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
sub new { |
37
|
0
|
|
|
0
|
1
|
|
my($proto, $fields) = @_; |
38
|
0
|
|
0
|
|
|
|
my($class) = ref $proto || $proto; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
DBIx::Changeset::Exception::ObjectCreateException->throw(error => 'Missing required db connection fields') unless defined $fields; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $self = bless {%$fields}, $class; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 read |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
sub read { |
51
|
0
|
|
|
0
|
1
|
|
my ($self, $uid) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## check for a uid |
54
|
0
|
0
|
|
|
|
|
DBIx::Changeset::Exception::ReadHistoryRecordException->throw(error => 'Need a uid to read') unless defined $uid; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
$self->_connect_to_db() unless defined $self->dbh(); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
## right we got a uid so do a search |
59
|
0
|
|
|
|
|
|
my $q = $self->pb()->query('get_changeset_record', { id => $uid }); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $hrecord = $q->fetchrow_hashref; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
DBIx::Changeset::Exception::ReadHistoryRecordException->throw(error => "No record found with uid of $uid") unless defined $hrecord; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# set the accessors |
66
|
0
|
|
|
|
|
|
foreach my $key (qw(id filename md5 version skipped_b forced_b modify_ts create_ts)) { |
67
|
0
|
|
|
|
|
|
$self->$key($hrecord->{$key}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$q->finish(); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 write |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
sub write { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $record) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
DBIx::Changeset::Exception::WriteHistoryRecordException->throw(error => 'No DBIx::Changeset::Record object provided') unless defined $record; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
$self->_connect_to_db() unless defined $self->dbh(); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
### does a record exist already |
86
|
0
|
|
|
|
|
|
my $q = $self->pb()->query('get_changeset_record', { id => $record->id }); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
### work out filename |
89
|
0
|
|
|
|
|
|
my $filename = File::Spec->catfile($record->changeset_location, $record->uri); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
### md5 |
92
|
0
|
|
|
|
|
|
my $md5 = $record->md5(); |
93
|
|
|
|
|
|
|
### timestamp |
94
|
0
|
|
|
|
|
|
my $dt = DateTime->now(); |
95
|
0
|
|
|
|
|
|
my $ts = $dt->ymd . ' ' . $dt->hms; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $hrecord = $q->fetchrow_hashref; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ( defined($hrecord) ) { |
100
|
|
|
|
|
|
|
### update |
101
|
0
|
|
|
|
|
|
my $q_ = $self->pb()->query('update_changeset_record', { |
102
|
|
|
|
|
|
|
filename => $filename, |
103
|
|
|
|
|
|
|
md5 => $md5, |
104
|
|
|
|
|
|
|
modify_ts => $ts, |
105
|
|
|
|
|
|
|
id => $hrecord->{'id'}, |
106
|
|
|
|
|
|
|
}); |
107
|
0
|
|
|
|
|
|
$q_->execute(); |
108
|
0
|
|
|
|
|
|
$q_->finish(); |
109
|
|
|
|
|
|
|
} else { |
110
|
|
|
|
|
|
|
### create |
111
|
0
|
|
|
|
|
|
my $q_ = $self->pb()->query('create_changeset_record', { |
112
|
|
|
|
|
|
|
id => $record->id, |
113
|
|
|
|
|
|
|
filename => $filename, |
114
|
|
|
|
|
|
|
md5 => $md5, |
115
|
|
|
|
|
|
|
modify_ts => $ts, |
116
|
|
|
|
|
|
|
create_ts => $ts, |
117
|
|
|
|
|
|
|
version => 1, |
118
|
|
|
|
|
|
|
}); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$q_->execute(); |
121
|
0
|
|
|
|
|
|
$q_->finish(); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$q->finish(); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 ACCESSORS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 id |
132
|
|
|
|
|
|
|
The id of this record (matches the DBIx::Changeset::Record uid) |
133
|
|
|
|
|
|
|
args: |
134
|
|
|
|
|
|
|
string |
135
|
|
|
|
|
|
|
returns: |
136
|
|
|
|
|
|
|
string |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 dbh |
139
|
|
|
|
|
|
|
The dbh connection to the historyrecord database |
140
|
|
|
|
|
|
|
args: |
141
|
|
|
|
|
|
|
DBD::H |
142
|
|
|
|
|
|
|
returns: |
143
|
|
|
|
|
|
|
DBD::H |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 filename |
146
|
|
|
|
|
|
|
The uri of the matching changeset record |
147
|
|
|
|
|
|
|
args: |
148
|
|
|
|
|
|
|
string |
149
|
|
|
|
|
|
|
returns: |
150
|
|
|
|
|
|
|
string |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 md5 |
153
|
|
|
|
|
|
|
The md5 hash of the Record content when it was updated |
154
|
|
|
|
|
|
|
args: |
155
|
|
|
|
|
|
|
string |
156
|
|
|
|
|
|
|
returns: |
157
|
|
|
|
|
|
|
string |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 forced_b |
160
|
|
|
|
|
|
|
records wether this was a forced update |
161
|
|
|
|
|
|
|
args: |
162
|
|
|
|
|
|
|
bool |
163
|
|
|
|
|
|
|
returns: |
164
|
|
|
|
|
|
|
bool |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 skipped_b |
167
|
|
|
|
|
|
|
records wether this update was skipped |
168
|
|
|
|
|
|
|
args: |
169
|
|
|
|
|
|
|
bool |
170
|
|
|
|
|
|
|
returns: |
171
|
|
|
|
|
|
|
bool |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 modify_ts |
174
|
|
|
|
|
|
|
records the timestamp of when this record was last modified |
175
|
|
|
|
|
|
|
args: |
176
|
|
|
|
|
|
|
timestamp |
177
|
|
|
|
|
|
|
returns: |
178
|
|
|
|
|
|
|
timestamp |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 modify_ts |
181
|
|
|
|
|
|
|
records the timestamp of when this record was created |
182
|
|
|
|
|
|
|
args: |
183
|
|
|
|
|
|
|
timestamp |
184
|
|
|
|
|
|
|
returns: |
185
|
|
|
|
|
|
|
timestamp |
186
|
|
|
|
|
|
|
=head2 pb |
187
|
|
|
|
|
|
|
the data phrasebook used for loading the correct sql |
188
|
|
|
|
|
|
|
args: |
189
|
|
|
|
|
|
|
phrasebook object |
190
|
|
|
|
|
|
|
returns: |
191
|
|
|
|
|
|
|
phreasebook object |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my @ACCESSORS = qw/dbh id filename md5 forced_b skipped_b version modify_ts create_ts pb/; |
196
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(@ACCESSORS); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub DESTROY { |
199
|
0
|
|
|
0
|
|
|
my $self = shift; |
200
|
|
|
|
|
|
|
|
201
|
0
|
0
|
|
|
|
|
if ( defined $self->dbh ) { |
202
|
0
|
|
|
|
|
|
$self->dbh->disconnect(); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
return; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Copyright 2004-2008 Grox Pty Ltd. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
213
|
|
|
|
|
|
|
under the same terms as Perl itself. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The full text of the license can be found in the LICENSE file included with this module. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; # End of DBIx::Changeset |