Daizu
view release on metacpan or search on metacpan
lib/Daizu/Util.pm view on Meta::CPAN
}
}
}
=item instantiate_generator($cms, $class, $root_file)
Create a generator object from the Perl class C<$class>, passing in the
information generator classes expect for their constructors.
C<$root_file>, which should be a L<Daizu::File> object, is passed to the
generator and as also used to find the configuration information, if
any, for this generator instance. Typically C<$root_file> will be the
on which the C<daizu:generator> property was set to enable this generator
class.
If C<$class> is undef then the default generator is used (L<Daizu::Gen>).
=cut
sub instantiate_generator
{
my ($cms, $class, $root_file) = @_;
$class = 'Daizu::Gen'
unless defined $class;
load_class($class);
my $path = $root_file->{path};
my $config = $cms->{generator_config}{$class}{$path};
$config = $cms->{generator_config}{$class}{''}
unless defined $config;
return $class->new(
cms => $cms,
root_file => $root_file,
config_elem => $config,
);
}
=item update_all_file_urls($cms, $wc_id)
Updates the C<url> table in the same way as the L<Daizu::File> method
L<update_urls_in_db()|Daizu::File/$file-E<gt>update_urls_in_db([$dup_urls])>,
except that
it does so for all files in working copy C<$wc_id>, and the return
values are each true if I<any> of the changes include new or updated
redirects or 'gone' files.
Any active URLs for files which no longer exist in the working copy are marked
as 'gone'. This function also takes care of handling temporary duplicate
URLs which occur during the update, when one file adds a new URL which is
already active for another file, but will be inactive by the end of the
transaction.
All of this is done in a single database transaction.
TODO - update docs about new return value
=cut
sub update_all_file_urls
{
my ($cms, $wc_id) = @_;
my $db = $cms->{db};
return transactionally($db, sub {
my $sth = $db->prepare(q{
select id
from wc_file
where wc_id = ?
});
$sth->execute($wc_id);
# These are aggregate versions of the same variables as in the
# update_urls_in_db() function in Daizu::File. Look there for
# details of what they mean.
my (%redirects_changed, %gone_changed);
my %dup_urls;
while (my ($file_id) = $sth->fetchrow_array) {
my $file = Daizu::File->new($cms, $file_id);
my $changes = $file->update_urls_in_db(\%dup_urls);
aggregate_map_changes($changes, \%redirects_changed,
\%gone_changed);
}
resolve_url_update_duplicates($db, $wc_id, \%dup_urls);
# Any other active URLs which belong to files that no longer exist
# should be deactivated.
$db->do(q{
update url
set status = 'G'
where wc_id = ?
and guid_id in (
select u.guid_id
from url u
left outer join wc_file f on f.wc_id = u.wc_id and
f.guid_id = u.guid_id
where u.wc_id = ?
and u.status = 'A'
and f.id is null
)
}, undef, $wc_id, $wc_id);
return {
update_redirect_maps => \%redirects_changed,
update_gone_maps => \%gone_changed,
};
});
}
=item resolve_url_update_duplicates($db, $wc_id, $dup_urls)
TODO
=cut
sub resolve_url_update_duplicates
{
( run in 1.894 second using v1.01-cache-2.11-cpan-39bf76dae61 )