0byt3m1n1
Path:
/
data
/
0
/
0
/
6
/
46
/
6861
/
user
/
7034
/
cgi-bin
/
lib
/
MT
/
[
Home
]
File: FileInfo.pm
# Copyright 2003-2004 Six Apart. This code cannot be redistributed # without permission from www.sixapart.com. # # $Id: FileInfo.pm,v 1.8 2004/08/28 21:34:09 ezra Exp $ package MT::FileInfo; use strict; use base qw(MT::Object); __PACKAGE__->install_properties({ columns => [ 'id', 'blog_id', 'entry_id', 'url', 'file_path', 'templatemap_id', 'template_id', 'archive_type', 'category_id', 'startdate', 'virtual' ], indexes => { blog_id => 1, entry_id => 1, template_id => 1, url => 1, }, datasource => 'fileinfo', primary_key => 'id', }); =pod =head1 NAME MT::FileInfo =head1 SYNOPSIS A FileInfo gives you information about a certain file or server-relative URL (it assumes a one-to-one mapping between files and URLs). More precisely A FileInfo maps a file path to a "Specifier" which tells what kind of file it is and how to rebuild it; also included is the URL where it is expected to be served. A Specifier is a variant record with the following types and fields: Index of template_id | Entry of templatemap_id * entry_id | DateBased of templatemap_id * date_spec * archive_type | Category of templatemap_id * category_id A FileInfo is tagged with an archive_type field (from the set {Individual, Daily, Monthly, Weekly, Category, Index}), which determines which of those variants is held in the record. =head1 METHODS =over 4 =item set_info_for_url($url, $file_path, $archive_type, $spec) Creates a FileInfo record in the database to indicate that the URL C<$url> serves the file at C<$file_path> and can be rebuilt from the parameters in C<$spec>. The C<$spec> argument is a hash ref with at least one of {TemplateMap, Template} defined, and at least one of the following: {Entry, StartDate, Category}. If $archive_type is 'index' then Template should be given; otherwise TemplateMap should be given. =back =cut # think: We need a set({a => v, ...}, {b => u, ...}) routine which # guarantees that subsequently load({a => v, ...}) will return a # record that matches {b => u} sub set_info_for_url { my $class = shift; my ($url, $file_path, $archive_type, $args) = @_; my $url_map = MT::FileInfo->new(); $url_map->blog_id($args->{Blog}); if ($archive_type eq 'index') { $url_map->template_id($args->{Template}); } else { $url_map->templatemap_id($args->{TemplateMap}) if $args->{TemplateMap}; $url_map->template_id($args->{Template}) if $args->{Template}; $url_map->entry_id($args->{Entry}) if $args->{Entry}; $url_map->startdate($args->{StartDate}) if $args->{StartDate}; $url_map->category_id($args->{Category}) if $args->{Category}; } $url_map->archive_type($archive_type); $url_map->url($url); $url_map->file_path($file_path); $url_map->save() || return $class->error($url_map->errstr()); return $url_map; } 1;