root/branches/release-31/lib/MT/FileInfo.pm @ 1495

Revision 1495, 3.9 kB (checked in by takayama, 21 months ago)

indexe optimized

  • Property svn:keywords set to Author Date Id Revision
Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::FileInfo;
8use strict;
9
10use base qw(MT::Object);
11
12__PACKAGE__->install_properties({
13    column_defs => {
14        'id' => 'integer not null auto_increment',
15        'blog_id' => 'integer not null',
16        'entry_id' => 'integer',
17        'url' => 'string(255)',
18        'file_path' => 'text',
19        'templatemap_id' => 'integer',
20        'template_id' => 'integer',
21        'archive_type' => 'string(255)',
22        'category_id' => 'integer',
23        'author_id' => 'integer',
24        'startdate' => 'string(80)',
25        'virtual' => 'boolean',
26    },
27    indexes => {
28        blog_id => 1,
29        entry_id => 1,
30        template_id => 1,
31        templatemap_id => 1,
32        archive_type => 1,
33        url => 1,
34        startdate => 1,
35        category_id => 1,
36        author_id => 1,
37    },
38    datasource => 'fileinfo',
39    primary_key => 'id',
40});
41
42=pod
43
44=head1 NAME
45
46MT::FileInfo
47
48=head1 SYNOPSIS
49
50A FileInfo gives you information about a certain file or
51server-relative URL (it assumes a one-to-one mapping between files and
52URLs).
53
54More precisely A FileInfo maps a file path to a "Specifier" which
55tells what kind of file it is and how to rebuild it; also included is
56the URL where it is expected to be served.
57
58A Specifier is a variant record with the following types and fields:
59
60            Index of template_id
61          | Entry of templatemap_id * entry_id
62          | DateBased of templatemap_id * date_spec * archive_type
63          | Category of templatemap_id * category_id
64
65A FileInfo is tagged with an archive_type field (from the set
66{Individual, Daily, Monthly, Weekly, Category, Index}), which
67determines which of those variants is held in the record.
68
69=head1 METHODS
70
71=over 4
72
73=item set_info_for_url($url, $file_path, $archive_type, $spec)
74
75Creates a FileInfo record in the database to indicate that the URL
76C<$url> serves the file at C<$file_path> and can be rebuilt from the
77parameters in C<$spec>.
78
79The C<$spec> argument is a hash ref with at least one of {TemplateMap,
80Template} defined, and at least one of the following: {Entry,
81StartDate, Category}.
82
83If $archive_type is 'index' then Template should be given; otherwise
84TemplateMap should be given.
85
86=back
87
88=cut
89
90# think: We need a set({a => v, ...}, {b => u, ...}) routine which
91#    guarantees that subsequently load({a => v, ...}) will return a
92#    record that matches {b => u}
93
94sub set_info_for_url {
95    my $class = shift;
96    my ($url, $file_path, $archive_type, $args) = @_;
97    my $url_map = MT::FileInfo->new();
98    $url_map->blog_id($args->{Blog});
99    if ($archive_type eq 'index') {
100        $url_map->template_id($args->{Template});
101    } else {
102        $url_map->templatemap_id($args->{TemplateMap}) if $args->{TemplateMap};
103        $url_map->template_id($args->{Template}) if $args->{Template};
104        $args->{Entry} = $args->{Entry}->id if ref $args->{Entry};
105        $url_map->entry_id($args->{Entry}) if $args->{Entry};
106        $url_map->startdate($args->{StartDate}) if $args->{StartDate};
107        $args->{Category} = $args->{Category}->id if ref $args->{Category};
108        $url_map->category_id($args->{Category}) if $args->{Category};
109        $args->{Author} = $args->{Author}->id if ref $args->{Author};
110        $url_map->author_id($args->{Author}) if $args->{Author};
111    }
112    $url_map->archive_type($archive_type);
113    $url_map->url($url);
114    $url_map->file_path($file_path);
115    $url_map->save() || return $class->error($url_map->errstr());
116    return $url_map;
117}
118
119sub parent_names {
120    my $obj = shift;
121    my $parents = {
122        blog => 'MT::Blog',
123        template => 'MT::Template',
124        templatemap => 'MT::TemplateMap',
125        category => 'MT::Category',
126        entry => 'MT::Entry',
127        author => 'MT::Author',
128    };
129    $parents;
130}
131
1321;
Note: See TracBrowser for help on using the browser.