line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::bif::drop::project; |
2
|
1
|
|
|
1
|
|
4560
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use Bif::Mo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
765
|
use DBIx::ThinSQL qw/sq/; |
|
1
|
|
|
|
|
27529
|
|
|
1
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.1.5_7'; |
8
|
|
|
|
|
|
|
extends 'App::bif'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub run { |
11
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
12
|
1
|
|
|
|
|
5
|
my $opts = $self->opts; |
13
|
1
|
|
|
|
|
7
|
my $dbw = $self->dbw; |
14
|
0
|
|
|
|
|
|
my $info = $self->get_project( $opts->{path} ); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
if ( !$opts->{force} ) { |
17
|
0
|
|
|
|
|
|
print "Nothing dropped (missing --force, -f)\n"; |
18
|
0
|
|
|
|
|
|
return $self->ok('DropNoForce'); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$dbw->txn( |
22
|
|
|
|
|
|
|
sub { |
23
|
0
|
0
|
|
0
|
|
|
if ( $info->{default_hub_id} ) { |
24
|
0
|
|
|
|
|
|
$self->drop_shallow($info); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
print "Project dropped: $info->{path} (shallow)\n"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
|
|
|
|
|
|
$dbw->xdo( |
30
|
|
|
|
|
|
|
delete_from => 'projects', |
31
|
|
|
|
|
|
|
where => { id => $info->{id} }, |
32
|
0
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
print "Project dropped: $info->{path})\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
return $self->ok('DropProjectShallow') if $info->{default_hub_id}; |
40
|
0
|
|
|
|
|
|
return $self->ok('DropProject'); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub drop_shallow { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my $info = shift; |
46
|
0
|
|
|
|
|
|
my $dbw = $self->dbw; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Drop topics that are not part of any other project |
49
|
|
|
|
|
|
|
my $res = $dbw->xdo( |
50
|
|
|
|
|
|
|
with => 'x', |
51
|
|
|
|
|
|
|
as => sq( |
52
|
|
|
|
|
|
|
select => [ 't.link_topic_id', 'COUNT(t.link_topic_id) AS total' ], |
53
|
|
|
|
|
|
|
from => 'topics t', |
54
|
|
|
|
|
|
|
where => { 't.project_id' => $info->{id} }, |
55
|
0
|
|
|
|
|
|
group_by => 't.id', |
56
|
|
|
|
|
|
|
having => 'total = 1', |
57
|
|
|
|
|
|
|
), |
58
|
|
|
|
|
|
|
delete_from => 'link_topics', |
59
|
|
|
|
|
|
|
where => [ |
60
|
|
|
|
|
|
|
'id IN ', |
61
|
|
|
|
|
|
|
sq( |
62
|
|
|
|
|
|
|
select => 'x.id', |
63
|
|
|
|
|
|
|
from => 'x', |
64
|
|
|
|
|
|
|
) |
65
|
|
|
|
|
|
|
], |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Delete project node entities, except those which are |
69
|
|
|
|
|
|
|
# our own identities, project entities, or are also |
70
|
|
|
|
|
|
|
# other project node entities. |
71
|
|
|
|
|
|
|
# $res += $dbw->xdo( |
72
|
|
|
|
|
|
|
# delete_from => 'entities', |
73
|
|
|
|
|
|
|
# where => [ |
74
|
|
|
|
|
|
|
# 'id IN ', |
75
|
|
|
|
|
|
|
# sq( |
76
|
|
|
|
|
|
|
# select => 'pte.entity_id', |
77
|
|
|
|
|
|
|
# from => 'project_node_entities pte', |
78
|
|
|
|
|
|
|
# where => { 'pte.project_id' => $info->{id} }, |
79
|
|
|
|
|
|
|
# except_select => 'x.entity_id', |
80
|
|
|
|
|
|
|
# from => sq( |
81
|
|
|
|
|
|
|
# select => 'bif.identity_id AS entity_id', |
82
|
|
|
|
|
|
|
# from => 'bifkv bif', |
83
|
|
|
|
|
|
|
# where => { 'bif.key' => 'self' }, |
84
|
|
|
|
|
|
|
# union_all_select => 'pe.entity_id', |
85
|
|
|
|
|
|
|
# from => 'project_entities pe', |
86
|
|
|
|
|
|
|
# where => { 'pe.project_id' => $info->{id} }, |
87
|
|
|
|
|
|
|
# union_all_select => 'pte.entity_id', |
88
|
|
|
|
|
|
|
# from => 'project_node_entities pte', |
89
|
|
|
|
|
|
|
# where => { 'pte.project_id !' => $info->{id} }, |
90
|
|
|
|
|
|
|
# )->as('x'), |
91
|
|
|
|
|
|
|
# ), |
92
|
|
|
|
|
|
|
# ], |
93
|
|
|
|
|
|
|
# ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$res += $dbw->xdo( |
96
|
|
|
|
|
|
|
update => 'projects', |
97
|
|
|
|
|
|
|
set => { local => 0 }, |
98
|
|
|
|
|
|
|
where => { id => $info->{id} }, |
99
|
0
|
|
|
|
|
|
); |
100
|
0
|
|
|
|
|
|
return $res; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
__END__ |