The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Konstrukt::Plugin::wiki::backend::file - Base class for file backends

SYNOPSIS

        use base 'Konstrukt::Plugin::wiki::backend::file';
        #overwrite the methods
        
        #note that you can use $self->backend_method() in the action methods as
        #only an instance of the backend class will be created and it will inherit your methods.
        

DESCRIPTION

Base class for a backend class that implements the backend functionality (store, retrieve, ...) for files (*.zip, *.pdf, *.*).

Includes the control/display code for managing files as it won't change with different backend types (DBI, file, ...). So the implementing backend class will inherit this code but must overwrite the data retrieval and update code.

Although currently only DBI-backends exist, it should be easy to develop other backends (e.g. file based).

Note that the name of the files will be normalized. All characters but letters, numbers, hyphens, parenthesis, brackets and dots will be replaced by underscores. Internally files are case insensitive. So SomeFile.zip will point to the same page as somefile.zip.

METHODS

init

Initialization for this plugin.

If you overwrite this one in your implementation, make sure to call $self-SUPER::init(@_);> to let the base class (this class) also do its init work.

install

Installs the templates.

Parameters:

none

actions

See "actions" in Konstrukt::Plugin::wiki::backend for a description of this one.

Responsible for the actions to show manage files.

prepare

The served file content will of course be dynamic. Don't do anything here.

execute

This one will be called, when a file's content will be downloaded. It will retrieve the content from the backend and return it to the browser.

Parameters:

  • $tag - Reference to the tag (and its children) that shall be handled.

file_show

Will handle the action to show an information page for a file.

file_edit_show

Will handle the action to show the form to edit/upload a file.

file_edit

Will handle the action to update a file.

file_revision_list

Will handle the action to show the revision history of a file.

file_restore

Will handle the action to restore a file's content and/or description.

exists

This method will return true, if a specified file exists. It will return undef otherwise.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the file

  • $revision - Optional: A specific revision of a file

revision

This method will return the latest revision number/number of revisions of a specified file. It will return undef if the specified file does not exist.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the file

revisions

This method will return all revisions of the specified file as an array of hash references ordered by ascending revision numbers:

        [
                { revision => 1, description => 'foo', description_revision => 3, content_revision => 4, content => 1, author => 'bar', host => '123.123.123.123', year => 2005, month => 1, day => 1, hour => 0, => minute => 0 },
                { revision => 2, ...},
                ...
        ]
        

Will return undef, if the file doesn't exist.

Note that the description_revision and content_revision may also be 0 if no content has been saved yet.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the file

get_info

This method will return the file info as a hashref:

                { title => 'foo', revision => 7, description => 'some text', description_revision => 3, content_revision => 4, author => 'foo', host => '123.123.123.123', year => 2005, month => 1, day => 1, hour => 0, => minute => 0 },

Will return undef, if the requested file doesn't exist.

Note that the description_revision and content_revision may also be 0 if no content has been saved yet.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the file

  • $revision - Optional: A specific revision of a file. When not specified, the latest revision will be returned.

get_content

This method will return the file content as a hashref:

                { content => 'binarydata', mimetype => 'application/foobar', filename => 'somefile.ext' }

Will return undef, if the requested file doesn't exist or there is no content yet.

Must be overwritten by the implementing class.

Parameters:

  • $title - The title of the file

  • $revision - Optional: A specific revision of a file. When not specified, the latest revision will be returned.

store

This method will add a new file (or new revision if the file already exists) to the store.

If the file already exists, you may also just add a new description or a new content for the file. Pass undef for the value, you don't want to change.

Will return -1 if no change has been made (which is the case, when no new content and no new description has been passed and the file already exists in the database). Will return true on successful update and undef on error.

Parameters:

  • $title - The title of the file

  • $store_description - True, if a new description should be stored. False, if the old one should be left.

  • $description - A description of this file. May be undef to reset (delete) the description for the new revision.

  • $store_content - True, if a new content should be stored. False, if the old one should be left.

  • $content - The (binary) content that should be stored. May be undef to reset (delete) the content for the new revision.

  • $mimetype - The MIME type of the file

  • $filename - The filename of the uploaded file. Will be used as the filename for the download

  • $author - User id of the creator

  • $host - Internet address of the creator

restore

This method will restore a description and/or a content from a given file revision.

Will return -1 if no change has been made (which is the case, when the current data and the data, which should be restored, are the same). Will return true on successful update and undef on error.

Parameters:

  • $title - The title of the file

  • $revision - The revision from which the description will be restored.

  • $restore_description - True, when the description should be restored

  • $restore_content - True, when the content should be restored

  • $author - User id of the modifier

  • $host - Internet address of the modifier

AUTHOR

Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.

This document is free software. It is distributed under the same terms as Perl itself.

SEE ALSO

Konstrukt::Plugin, Konstrukt::Plugin, Konstrukt