Daizu

 view release on metacpan or  search on metacpan

lib/Daizu/Publish.pm  view on Meta::CPAN

    close $fh or die "Error closing redirect map file '$filename': $!\n";
}

=item publish_gone_map($cms, $wc_id, $config)

TODO

=cut

sub publish_gone_map
{
    my ($cms, $wc_id, $config) = @_;

    my $filename = $config->{gone_map};
    assert(defined $filename) if DEBUG;
    open my $fh, '>', $filename
        or die "Error opening gone map '$filename': $!\n";

    my $url = $config->{url};
    my $sth = $cms->db->prepare(q{
        select url
        from url
        where status = 'G'
          and wc_id = ?
          -- URL is exact match or is more precise
          and (url = ? or (? like '%/' and url like ?))
        order by url
    });
    $sth->execute($wc_id, $url, $url, like_escape($url) . '%');

    while (my ($url) = $sth->fetchrow_array) {
        my $path = _map_path($url, $config);
        print $fh "$path\t1\n"
            if defined $path;
    }

    close $fh or die "Error closing gone map file '$filename': $!\n";
}

sub _map_path
{
    my ($url, $config) = @_;

    $url = URI->new($url);
    my $path = $url->rel($config->{url});
    $path = '/' if $path eq './';
    return if $path eq $url || $path =~ m!^\.\.?/!;

    assert(defined $path && $path ne '') if DEBUG;
    $path = "/$path" unless $path =~ m!^/!;

    return $path;
}

=item update_live_sites($cms, $start_rev)

TODO

=cut

sub update_live_sites
{
    my ($cms, $start_rev) = @_;
    return transactionally($cms->{db}, \&_update_live_sites_txn,
                           $cms, $start_rev);
}

sub _update_live_sites_txn
{
    my ($cms, $start_rev) = @_;
    my $end_rev = $cms->live_wc->current_revision;

    my ($cur_rev) = db_select($cms->{db}, live_revision => {}, 'revnum');
    $start_rev = $cur_rev unless defined $start_rev;

    if (!defined $start_rev) {
        db_insert($cms->{db}, 'live_revision', revnum => $end_rev);
        die "No live sites tracked yet.  I've initialized the database\n" .
            "to use the latest revision as a starting point, but you\n" .
            "need to publish all the content to start with before it\n" .
            "makes sense to use this feature.\n";
    }

    return if $start_rev == $end_rev;   # nothing to do

    # These calls do all the actual work.
    my $changes = file_changes_between_revisions($cms, $start_rev, $end_rev);
    my $work = do_publishing_url_updates($cms, $changes);
    my ($publish_url, $delete_url) = urls_which_need_publishing(
        $cms, $start_rev, $changes, $work->{url_activated},
        $work->{url_deactivated}, $work->{url_changed});
    do_publication_work(
        $cms, $publish_url, $delete_url,
        $work->{update_redirect_maps}, $work->{update_gone_maps});

    # Keep track of the new revision we've published up to.
    if (defined $cur_rev) {
        db_update($cms->{db}, 'live_revision', { revnum => $cur_rev },
                  revnum => $end_rev);
    }
    else {
        db_insert($cms->{db}, 'live_revision', revnum => $end_rev);
    }
}

=back

=head1 COPYRIGHT

This software is copyright 2006 Geoff Richards E<lt>geoff@laxan.comE<gt>.
For licensing information see this page:

L<http://www.daizucms.org/license/>

=cut

1;
# vi:ts=4 sw=4 expandtab



( run in 0.505 second using v1.01-cache-2.11-cpan-5a3173703d6 )