App-Chronicle
view release on metacpan or search on metacpan
bin/chronicle view on Meta::CPAN
#
# Call on_initiate for all plugins which have not been excluded.
#
foreach my $plugin ( get_plugins_for_method("on_initiate") )
{
$CONFIG{ 'verbose' } && print "Calling $plugin on_initiate()\n";
$plugin->on_initiate( config => \%CONFIG, dbh => $dbh );
}
#
# Call on_generate for all plugins which have not been excluded.
#
# `on_generate` is logically identical to `on_initiate`, except
# the former plugins are guaranteed to have been invoked first.
#
foreach my $plugin ( get_plugins_for_method("on_generate") )
{
$CONFIG{ 'verbose' } && print "Calling $plugin on_generate()\n";
$plugin->on_generate( config => \%CONFIG, dbh => $dbh );
}
#
# Copy any static content from the theme-directory.
#
my $ts = $CONFIG{ 'theme-dir' } . "/" . $CONFIG{ 'theme' } . "/static";
if ( -d $ts )
{
#
# This could be improved, but it will cope with subdirectories, etc,
# so for the moment it will remain.
#
system("/bin/tar -C $ts -cpf - . | /bin/tar -C $CONFIG{'output'} -xf -");
}
#
# Now we're done.
#
$dbh->disconnect();
exit(0);
=begin doc
Read each blog-post from beneath ./data/ - and if it is missing from the
database then insert it.
We also handle the case where the file on disk is newer than the database
version - in that case we remove the database version and update it to
contain the newer content.
=end doc
=cut
sub updateDatabase
{
my ($dbh) = (@_);
#
# Assume each entry is already present in the database.
#
my $sql =
$dbh->prepare("SELECT id FROM blog WHERE ( file=? AND mtime=? )") or
die "Failed to select post";
#
# Look for posts.
#
foreach
my $file ( get_post_files( $CONFIG{ 'input' }, $CONFIG{ 'pattern' } ) )
{
#
# We want to find the mtime to see if it is newer than the DB-version.
#
my ( $dev, $ino, $mode, $nlink, $uid,
$gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks
)
= stat($file);
#
# Lookup the existing entry
#
$sql->execute( $file, $mtime ) or
die "Failed to execute: " . $dbh->errstr();
my $result = $sql->fetchrow_hashref();
if ( !$result )
{
#
# The file is not in the database, or it is present with a
# different modification time.
#
# Parse the file and insert it.
#
insertPost( $dbh, $file, $mtime );
}
}
$sql->finish();
}
=begin doc
Given a filename containing a blog post then insert that post into
the database.
We also update the tags.
( run in 1.482 second using v1.01-cache-2.11-cpan-9581c071862 )