Skip to content

Commit

Permalink
Utility scripts to import/export raw pages. Dump a page's markup cont…
Browse files Browse the repository at this point in the history
…ent to STDOUT, or load it from a file.
  • Loading branch information
dandv committed May 19, 2010
1 parent edd6474 commit d85cc76
Show file tree
Hide file tree
Showing 3 changed files with 255 additions and 25 deletions.
50 changes: 25 additions & 25 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
New features:
- Google search formatter (bayashi)
- Utility scripts to import/export raw page markup from file/to STDOUT (dandv)

Bug fixes:
Bug fixes:
- Minor CSS fix (tcaine)

Improvements:
- All Methods/subs now documented
- POD Coverage test on by default
- All method must be documented from now on - POD coverage test is on by default

1.00 2010-05-09 00:04:20

New Features:
- Create a default page for new users.
- Replaced shrunken-head image with a sane "Stop" sign (dandv)

Bug fixes:
- Fix WantedLink to use normalize_page to match links
- Removed File::Slurp dependency after removing it from Text::(Multi)Markdown
because it fails installation under Strawberry Perl (dandv)
- IRC Formatter auto-color nicknames (GitHub issue #27) (linio)
- IRC Formatter auto-color nicknames (GitHub issue #27) (linio)
- Attachments size in Page info is now correctly displayed (GitHub issue #53) (linio)
- Remove 'Alerts' from Syntax Highlight list - it's Kate's hidden module (Github issue #52) (linio)
- Fixed formatter_all_textile tests to work without Syntax plugin

Improvements:
- Refine POD so lintian is happy (debian build tool)
- Add unicode code option to DB connect string. This allows us to remove
the use of UTF8Columns which is deprecated. Hook in CHARTSET=utf8 for MySQL deploy
- Forced SQLite, MySQL and PostgreSQL database connections to use Unicode,
eliminating dependency on DBIx::Class::UTF8Columns, which is now strongly deprecated. (mateu)

Misc:
- Test::Notabs is now optional
- HTML::Toc is now required


0.999042 2009-12-01 21:42:00

Expand All @@ -47,16 +47,16 @@

Bug fixes:
- fixed inserting images via the toolbar after markdown="1" support (dandv)


0.999041 2009-10-26 11:55:00

New features:
- add markdown="1" to block-level HTML elements to interpret Markdown (dandv)

Translation:
- Italian. MojoMojo ora parla italiano (enrico)

Bug fixes:
- Exports now export the entire subtree (dandv)
- Sub pages do not show pages without view permission (linio)
Expand All @@ -69,30 +69,30 @@
Documentation:
- improved and centralized installation docs into lib/MojoMojo/Installation.pod



0.999040 2009-09-04 19:53:00

- Format content body and store in content.precompile
Use this precompiled body when available for page delivery (see page/view.tt).
/.precompile_pages action for precompiling all page versions.
This action can take a few minutes for the Catalyst wiki (~2000 page versions).

- Fixed [[child]] and [[../sibling]] display bug when first creating a page.
Adjust tests to reflect that [[../sibling]] formats to parent/sibling
instead of ../sibling. (mateu)

- Simplified and improved sub-pages. Speed and layout enhanced. (mateu)
- Made subtree KinoSearch work (mateu)
- Added paging for .list (dandv)

- Catapulse theme (dab)
- Madrid.pm theme (diegok)
- More español (diegok)

- Updated jQuery inplace editor and related code; fixed '&'-encoding bug
which caused any text after the '&' to be lost when editing in-place (dandv)

- Simplified 404 page handling in suggest.tt (mateu)
- No cookie for anonymous user requests, and cookie test (mateu)
- Removed PageCache (mateu)
Expand All @@ -101,7 +101,7 @@
- Main formatter now guaranteed to end the content with *one* newline (dandv)
- Remove some obsolete crud (dandv/marcus)



0.999033 2009-08-14 12:40:00 UTC

Expand Down Expand Up @@ -418,9 +418,9 @@


0.999013 2008-02-06 00:08:00
- renovated skin (arne)
- syntax fixes, registration/login (jshirley)
- fix email validation template (jshirley)
- Renovated skin (arne)
- Syntax fixes, registration/login (jshirley)
- Fix email validation template (jshirley)


0.999012 2008-02-06 00:08:00
Expand Down
81 changes: 81 additions & 0 deletions script/util/dump_content.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env perl
=head1 NAME
dump_content.pl - Dump the raw (markup) content of a page.
=head1 SYNOPSIS
script/util/dump_content.pl /path/to/page > page.markdown
=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
Dump the raw (markup) contents of the last version of a page.
\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'}) {
$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,
}
);

print $page_content->body;
149 changes: 149 additions & 0 deletions script/util/import_content.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/env perl
=head1 NAME
import_content.pl - import content from a file into a MojoMojo page
=head1 SYNOPSIS
script/util/import_content.pl /path/to/page page.markdown
Since this operation is undoable, the script will prompt you to confirm that
you really want to replace the contents of the last version of /path/to/page
with what's in F<page.markdown>.
=head1 DESCRIPTION
Replace the contents of the last version of a page with the content from a
file. Useful if you want to fix a typo in a page without bumping the version
and creating yet another revision in the database. Of course, can be used for
evil, but then so could be a series of SQL commands.
=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;

=head2 preview
Return the middle of a string. Examples:
preview('abcdefghijk', 10)
'ab [...] k'
preview('abcdefghijkl', 10), "\n";
'ab [...] l'
preview('abcdefghijkl', 11), "\n";
'ab [...] kl'
preview('abcdefghijklm', 10), "\n";
'ab [...] m'
preview('abcdef0000000000ghijklm', 10), "\n";
'ab [...] m'
=cut

sub preview {
my ($string, $limit) = @_;
my $length = length $string;
return $string if $length <= $limit;
my $middle = ' [...] ';
return
substr( $string, 0, ($limit+1 - length $middle)/2 )
. $middle
. substr( $string, $length - ($limit-1 - length $middle)/2 )
;
}


my ($page_path, $filename_content, $dsn, $user, $pass) = @ARGV;

if (!$page_path) {
die "USAGE: $0 /path/to/page filename [dsn user pass]
Replace the contents of the last version of a page with the content from a file
\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'}) {
$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_rs = $schema->resultset('Content')->search(
{
page => $page->id,
version => $page->content_version,
}
);
die "More than one 'last version' for page <$page_path>. The database may be corrupt.\n"
if $page_content_rs->count > 1;
my $page_content = $page_content_rs->first;

open my $file_content, '<:utf8', $filename_content or die $!;
my $content; {local $/; $content = <$file_content>};

print "Are you sure you want to replace\n",
preview($page_content->body, 300),
"\nwith\n",
preview($content, 300),
"\n? ('yes'/anything else): ";
my $answer = <STDIN>; chomp $answer;
if ($answer eq 'yes') {
$page_content->update(
{
body => $content,
precompiled => '', # this needs to be blanked so that MojoMojo will re-compile it
}
);
print "Done.\n";
} else {
print "Aborted.\n";
exit 1;
}

0 comments on commit d85cc76

Please sign in to comment.