App-Chronicle
view release on metacpan or search on metacpan
bin/chronicle view on Meta::CPAN
# 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.
=end doc
=cut
sub insertPost
{
my ( $dbh, $filename, $mtime ) = (@_);
$CONFIG{ 'verbose' } && print "Adding post to DB: $filename\n";
#
# Is the entry present, but with a different mtime?
#
# If so we need to delete the post, and the tags which are pointing
# at it, otherwise we'll have orphaned tags.
#
my $sql = $dbh->prepare("SELECT id FROM blog WHERE file=?");
$sql->execute($filename) or die "Failed to execute :" . $dbh->errstr();
my $id;
$sql->bind_columns( undef, \$id );
while ( $sql->fetch() )
{
( run in 1.567 second using v1.01-cache-2.11-cpan-ceb78f64989 )