root/branches/release-33/lib/MT/FileInfo.pm @ 1776

Revision 1776, 3.9 kB (checked in by mpaschal, 20 months ago)

Update 'virtual' field of fileinfos directly when dynamicity changes
Don't recreate fileinfos when dynamicity changes, only when publishing path does (but when publishing path changes, recreate fileinfos even if publishing statically, as we always keep fileinfos nowadays)
Don't cache fileinfos, so updating directly is not a problem
BugzID: 67300

  • 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    cacheable => 0,
41});
42
43=pod
44
45=head1 NAME
46
47MT::FileInfo
48
49=head1 SYNOPSIS
50
51A FileInfo gives you information about a certain file or
52server-relative URL (it assumes a one-to-one mapping between files and
53URLs).
54
55More precisely A FileInfo maps a file path to a "Specifier" which
56tells what kind of file it is and how to rebuild it; also included is
57the URL where it is expected to be served.
58
59A Specifier is a variant record with the following types and fields:
60
61            Index of template_id
62          | Entry of templatemap_id * entry_id
63          | DateBased of templatemap_id * date_spec * archive_type
64          | Category of templatemap_id * category_id
65
66A FileInfo is tagged with an archive_type field (from the set
67{Individual, Daily, Monthly, Weekly, Category, Index}), which
68determines which of those variants is held in the record.
69
70=head1 METHODS
71
72=over 4
73
74=item set_info_for_url($url, $file_path, $archive_type, $spec)
75
76Creates a FileInfo record in the database to indicate that the URL
77C<$url> serves the file at C<$file_path> and can be rebuilt from the
78parameters in C<$spec>.
79
80The C<$spec> argument is a hash ref with at least one of {TemplateMap,
81Template} defined, and at least one of the following: {Entry,
82StartDate, Category}.
83
84If $archive_type is 'index' then Template should be given; otherwise
85TemplateMap should be given.
86
87=back
88
89=cut
90
91# think: We need a set({a => v, ...}, {b => u, ...}) routine which
92#    guarantees that subsequently load({a => v, ...}) will return a
93#    record that matches {b => u}
94
95sub set_info_for_url {
96    my $class = shift;
97    my ($url, $file_path, $archive_type, $args) = @_;
98    my $url_map = MT::FileInfo->new();
99    $url_map->blog_id($args->{Blog});
100    if ($archive_type eq 'index') {
101        $url_map->template_id($args->{Template});
102    } else {
103        $url_map->templatemap_id($args->{TemplateMap}) if $args->{TemplateMap};
104        $url_map->template_id($args->{Template}) if $args->{Template};
105        $args->{Entry} = $args->{Entry}->id if ref $args->{Entry};
106        $url_map->entry_id($args->{Entry}) if $args->{Entry};
107        $url_map->startdate($args->{StartDate}) if $args->{StartDate};
108        $args->{Category} = $args->{Category}->id if ref $args->{Category};
109        $url_map->category_id($args->{Category}) if $args->{Category};
110        $args->{Author} = $args->{Author}->id if ref $args->{Author};
111        $url_map->author_id($args->{Author}) if $args->{Author};
112    }
113    $url_map->archive_type($archive_type);
114    $url_map->url($url);
115    $url_map->file_path($file_path);
116    $url_map->save() || return $class->error($url_map->errstr());
117    return $url_map;
118}
119
120sub parent_names {
121    my $obj = shift;
122    my $parents = {
123        blog => 'MT::Blog',
124        template => 'MT::Template',
125        templatemap => 'MT::TemplateMap',
126        category => 'MT::Category',
127        entry => 'MT::Entry',
128        author => 'MT::Author',
129    };
130    $parents;
131}
132
1331;
Note: See TracBrowser for help on using the browser.