/
bust_cache.pl
85 lines (63 loc) · 2.24 KB
/
bust_cache.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env perl
=head1 NAME
bust_cache.pl - Delete the precompiled content of a page. MojoMojo
will recompile the page next time it is requested.
=head1 SYNOPSIS
script/util/bust_cache.pl /path/to/page
=head1 AUTHORS
Dan Dascalescu (dandv), http://dandascalescu.com
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
=head1 COPYRIGHT
Copyright (C) 2010, Dan Dascalescu.
=cut
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../lib";
use MojoMojo::Schema;
my ($page_path, $filename_content, $dsn, $user, $pass) = @ARGV;
if (!$page_path) {
die "USAGE: $0 /path/to/page [dsn user pass]
Delete the precompiled content of a page. MojoMojo
will recompile the page next time it is requested.
\n";
}
if (!$dsn) {
# no DSN passed via the command line; attempting to read one from the config file
require Config::JFDI;
my $config = Config::JFDI->new(name => "MojoMojo")->get;
die "Couldn't read config file" if not keys %{$config};
eval {
if (ref $config->{'Model::DBIC'}->{'connect_info'} eq 'HASH') {
$dsn = $config->{'Model::DBIC'}->{'connect_info'}->{dsn};
$user = $config->{'Model::DBIC'}->{'connect_info'}->{user};
$pass = $config->{'Model::DBIC'}->{'connect_info'}->{password};
} else {
($dsn, $user, $pass) = @{$config->{'Model::DBIC'}->{connect_info}};
}
};
die "Your DSN settings in mojomojo.conf seem invalid: $@\n" if $@;
}
die "Couldn't find a valid Data Source Name (DSN).\n" if !$dsn;
$dsn =~ s/__HOME__/$FindBin::Bin\/\.\./g;
my $schema = MojoMojo::Schema->connect($dsn, $user, $pass) or
die "Failed to connect to database";
my ( $path_pages, $proto_pages ) = $schema->resultset('Page')->path_pages( $page_path )
or die "Can't find page $page_path\n";
if (scalar @$proto_pages) {
die "One or more pages at the end do(es) not exist: ",
(join ", ", map { $_->{name_orig} } @$proto_pages),
"\n";
}
# Get the lastest content version of the page
my $page = $path_pages->[-1];
my $page_content = $schema->resultset('Content')->single(
{
page => $page->id,
version => $page->content_version,
}
);
$page_content->update({
precompiled => ''
});