line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Read; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
684
|
use utf8; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
20
|
|
4
|
3
|
|
|
3
|
|
149
|
use 5.016; |
|
3
|
|
|
|
|
11
|
|
5
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
79
|
|
6
|
3
|
|
|
3
|
|
16
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
165
|
|
7
|
3
|
|
|
3
|
|
1388
|
use Geoffrey::Template; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
94
|
|
8
|
3
|
|
|
3
|
|
864
|
use Geoffrey::Changeset; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
116
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$Geoffrey::Read::VERSION = '0.000204'; |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
18
|
use parent 'Geoffrey::Role::Core'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
13
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _obj_entries { |
15
|
8
|
|
|
8
|
|
4296
|
my ($self) = @_; |
16
|
8
|
|
|
|
|
796
|
require Geoffrey::Action::Entry; |
17
|
8
|
|
66
|
|
|
48
|
$self->{entries} //= Geoffrey::Action::Entry->new(dbh => $self->dbh, converter => $self->converter,); |
18
|
8
|
|
|
|
|
110
|
return $self->{entries}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _parse_changelogs { |
22
|
1
|
|
|
1
|
|
3
|
my ($self, $ar_changelogs, $s_changelog_root) = @_; |
23
|
1
|
|
|
|
|
2
|
for my $i_changelog (@{$ar_changelogs}) { |
|
1
|
|
|
|
|
3
|
|
24
|
3
|
50
|
|
|
|
94
|
my $s_changelog |
25
|
|
|
|
|
|
|
= $s_changelog_root |
26
|
|
|
|
|
|
|
? File::Spec->catfile($s_changelog_root, "changelog-$i_changelog") |
27
|
|
|
|
|
|
|
: "changelog-$i_changelog"; |
28
|
3
|
50
|
|
|
|
18
|
return 0 if !$self->_parse_log($s_changelog); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
0
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _parse_log { |
34
|
3
|
|
|
3
|
|
13
|
my ($self, $s_changelog) = @_; |
35
|
3
|
|
|
|
|
7
|
for (@{$self->changelog_io->load($s_changelog)}) { |
|
3
|
|
|
|
|
20
|
|
36
|
6
|
|
|
|
|
237
|
my $changeset_result = $self->run_changeset($_, $s_changelog); |
37
|
5
|
50
|
|
|
|
110
|
return 0 if $changeset_result->{exit}; |
38
|
|
|
|
|
|
|
} |
39
|
2
|
|
|
|
|
89
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _get_sql_abstract { |
43
|
16
|
|
|
16
|
|
42
|
my ($self) = @_; |
44
|
16
|
|
|
|
|
1685
|
require SQL::Abstract; |
45
|
16
|
|
66
|
|
|
23411
|
$self->{sql_abstract} //= SQL::Abstract->new; |
46
|
16
|
|
|
|
|
333
|
return $self->{sql_abstract}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _get_changset_by_id { |
50
|
16
|
|
|
16
|
|
48
|
my ($self, $s_changeset_id) = @_; |
51
|
16
|
50
|
|
|
|
50
|
my $s_changelog_name = ($self->schema ? $self->schema . q/./ : q//) . $self->converter->changelog_table; |
52
|
16
|
|
|
|
|
68
|
my $s_changeset_sql = $self->_get_sql_abstract->select($s_changelog_name, qw/*/, {id => $s_changeset_id}); |
53
|
16
|
|
|
|
|
5011
|
my $hr_result = $self->dbh->selectrow_hashref($s_changeset_sql, {Slice => {}}, ($s_changeset_id)); |
54
|
16
|
100
|
|
|
|
4853
|
return unless $hr_result; |
55
|
1
|
|
|
|
|
9
|
require Geoffrey::Utils; |
56
|
1
|
|
|
|
|
7
|
return Geoffrey::Utils::to_lowercase($hr_result); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _check_key { |
60
|
10
|
|
|
10
|
|
36
|
my ($self, $s_changeset_id, $s_md5sum) = @_; |
61
|
10
|
|
|
|
|
44
|
my $hr_db_changeset = $self->_get_changset_by_id($s_changeset_id); |
62
|
10
|
100
|
|
|
|
26
|
return 0 unless scalar keys %{$hr_db_changeset}; |
|
10
|
|
|
|
|
73
|
|
63
|
1
|
50
|
|
|
|
4
|
return 0 unless $hr_db_changeset->{md5sum}; |
64
|
|
|
|
|
|
|
|
65
|
1
|
50
|
|
|
|
4
|
if ($hr_db_changeset->{md5sum} ne $s_md5sum) { |
66
|
1
|
|
|
|
|
5
|
require Geoffrey::Exception::Database; |
67
|
1
|
|
|
|
|
7
|
Geoffrey::Exception::Database::throw_changeset_corrupt($s_changeset_id, $s_md5sum, $hr_db_changeset->{md5sum}); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
0
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub run_changeset { |
73
|
11
|
|
|
11
|
1
|
5835
|
my ($self, $hr_changeset, $s_file) = @_; |
74
|
11
|
50
|
|
|
|
48
|
return {exit => 1} if $hr_changeset->{stop}; |
75
|
11
|
100
|
|
|
|
39
|
if (!$hr_changeset->{id}) { |
76
|
1
|
|
|
|
|
7
|
require Geoffrey::Exception::RequiredValue; |
77
|
1
|
|
|
|
|
6
|
Geoffrey::Exception::RequiredValue::throw_id($s_file); |
78
|
|
|
|
|
|
|
} |
79
|
10
|
|
|
|
|
1081
|
require Hash::MD5; |
80
|
10
|
|
|
|
|
8681
|
my $s_changeset_checksum = Hash::MD5::sum($hr_changeset); |
81
|
10
|
50
|
|
|
|
2243
|
return {key => 1} if $self->_check_key($hr_changeset->{id}, $s_changeset_checksum); |
82
|
9
|
|
|
|
|
41
|
$self->changeset->handle_entries($hr_changeset->{entries}); |
83
|
6
|
50
|
|
|
|
41
|
my $s_table_name = ($self->schema ? $self->schema . q/./ : q//) . $self->converter->changelog_table; |
84
|
6
|
|
|
|
|
27
|
require Geoffrey::Utils; |
85
|
6
|
|
|
|
|
36
|
my $hr_db_changeset = Geoffrey::Utils::to_lowercase($self->_get_changset_by_id($hr_changeset->{id})); |
86
|
|
|
|
|
|
|
|
87
|
6
|
50
|
|
|
|
22
|
if ($hr_db_changeset) { |
88
|
|
|
|
|
|
|
return { |
89
|
|
|
|
|
|
|
changeset => $self->_obj_entries->alter( |
90
|
|
|
|
|
|
|
$s_table_name, |
91
|
|
|
|
|
|
|
{id => $hr_changeset->{id}}, |
92
|
0
|
|
|
|
|
0
|
[{md5sum => $s_changeset_checksum}], |
93
|
|
|
|
|
|
|
)}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return { |
97
|
|
|
|
|
|
|
changeset => $self->_obj_entries->add({ |
98
|
|
|
|
|
|
|
table => $s_table_name, |
99
|
|
|
|
|
|
|
values => [{ |
100
|
|
|
|
|
|
|
created_by => $hr_changeset->{author}, |
101
|
|
|
|
|
|
|
geoffrey_version => $Geoffrey::Read::VERSION, |
102
|
|
|
|
|
|
|
comment => 'Imported by current db.', |
103
|
|
|
|
|
|
|
id => $hr_changeset->{id}, |
104
|
6
|
|
|
|
|
33
|
filename => $s_file, |
105
|
|
|
|
|
|
|
md5sum => $s_changeset_checksum, |
106
|
|
|
|
|
|
|
}]})}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
30
|
|
|
30
|
1
|
207
|
sub schema { return shift->{schema}; } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub changeset { |
112
|
12
|
|
|
12
|
1
|
36
|
my ($self, $obj_changeset) = @_; |
113
|
12
|
50
|
|
|
|
35
|
$self->{changeset} = $obj_changeset if $obj_changeset; |
114
|
|
|
|
|
|
|
$self->{changeset} |
115
|
12
|
|
66
|
|
|
64
|
//= Geoffrey::Changeset->new(converter => $self->converter, dbh => $self->dbh, schema => $self->schema,); |
116
|
12
|
|
|
|
|
87
|
return $self->{changeset}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub run { |
120
|
1
|
|
|
1
|
1
|
3
|
my ($self, $s_changelog_root) = @_; |
121
|
1
|
50
|
|
|
|
6
|
$self->changelog_io->converter($self->converter) if $self->changelog_io->needs_converter; |
122
|
1
|
50
|
|
|
|
7
|
$self->changelog_io->dbh($self->dbh) if $self->changelog_io->needs_dbh; |
123
|
1
|
|
|
|
|
4
|
my $hr_main_changeset = $self->changelog_io->load(File::Spec->catfile($s_changelog_root, 'changelog')); |
124
|
1
|
|
|
|
|
50
|
$self->changeset->template(Geoffrey::Template->new->load_templates($hr_main_changeset->{templates})); |
125
|
1
|
50
|
|
|
|
3
|
$self->changeset->prefix($hr_main_changeset->{prefix} ? $hr_main_changeset->{prefix} . '_' : q~~); |
126
|
1
|
50
|
|
|
|
3
|
$self->changeset->postfix($hr_main_changeset->{postfix} ? '_' . $hr_main_changeset->{postfix} : q~~); |
127
|
1
|
|
|
|
|
5
|
return $self->_parse_changelogs($hr_main_changeset->{changelogs}, $s_changelog_root); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; # End of Geoffrey::Read |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |