1 package SL::File::Object;
4 use parent qw(Rose::Object);
7 use Rose::Object::MakeMethods::Generic (
9 'scalar --get_set_init' => [ qw(db_file loaded id version newest) ],
12 #use SL::DB::Helper::Attr;
13 #__PACKAGE__->_as_timestamp('mtime');
14 # wie wird das mit dem Attr Helper gemacht damit er bei nicht DB Objekten auch geht?
16 sub mtime_as_timestamp_s {
17 $::locale->format_date_object($_[0]->mtime, precision => 'second');
23 $_[0]->loaded_db_file->itime;
27 $_[0]->loaded_db_file->file_name;
31 $_[0]->loaded_db_file->file_type;
35 $_[0]->loaded_db_file->object_type;
39 $_[0]->loaded_db_file->object_id;
43 $_[0]->loaded_db_file->mime_type;
47 $_[0]->loaded_db_file->title;
50 sub file_description {
51 $_[0]->loaded_db_file->description;
55 $_[0]->loaded_db_file->backend;
59 $_[0]->loaded_db_file->source;
62 # methods to go directly into the backends
65 $_[0]->backend_class->get_filepath(dbfile => $_[0]->loaded_db_file, version => $_[0]->version)
69 $_[0]->backend_class->get_content(dbfile => $_[0]->loaded_db_file, version => $_[0]->version)
73 $_[0]->backend_class->get_mtime(dbfile => $_[0]->loaded_db_file, version => $_[0]->version)
77 $_[0]->backend_class->get_version_count(dbfile => $_[0]->loaded_db_file)
81 SL::File->get_all_versions(dbfile => $_[0]->loaded_db_file)
85 SL::File->save(dbfile => $_[0]->loaded_db_file, file_contents => $_[1] )
89 SL::File->save(dbfile => $_[0]->loaded_db_file, file_path => $_[1] )
93 SL::File->delete(dbfile => $_[0]->loaded_db_file)
96 sub delete_last_version {
97 SL::File->delete(dbfile => $_[0]->loaded_db_file, last => 1 )
101 SL::File->delete(dbfile => $_[0]->loaded_db_file, version => $_[0]->version )
105 SL::File->delete(dbfile => $_[0]->loaded_db_file, all_but_notlast => 1 )
109 SL::File->rename(dbfile => $_[0]->loaded_db_file, to => $_[1])
115 SL::File->get_backend_class($_[0]->backend)
119 sub loaded_db_file { # so, dass wir die nur einmal laden.
120 if (!$_[0]->loaded) {
121 $_[0]->db_file->load;
128 sub init_db_file { die 'must always have a db file'; }
129 sub init_loaded { 0 }
131 sub init_version { 0 }
132 sub init_newest { 1 }
142 SL::File::Object - a filemangement object wrapper
148 my ($object) = SL::File->get_all(object_id => $object_id,
149 object_type => $object_type,
150 file_type => 'images', # may be optional
151 source => 'uploaded' # may be optional
155 my $object_id = $object->object_id,
156 my $object_type = $object->object_type,
157 my $file_type = $object->file_type;
158 my $file_name = $object->file_name;
159 my $mime_type = $object->mime_type;
161 my $mtime = $object->mtime;
162 my $itime = $object->itime;
163 my $id = $object->id;
164 my $newest = $object->newest;
166 my $versions = $object->version_count;
168 my @versionobjs = $object->versions;
169 foreach ( @versionobjs ) {
170 my $mtime = $_->mtime;
171 my $contents = $_->get_content;
176 $object->rename("image1.png");
177 $object->save_contents("new text");
178 $object->save_file("/tmp/empty.png");
180 $object->delete_last_version;
185 This is a wrapper around a single object in the filemangement.
189 Following methods are wrapper to read the attributes of L<SL::DB::File> :
205 =item C<file_description>
217 Additional are there special methods. If the Object is created by SL::File::get_all_versions()
218 or by "$object->versions"
219 it has a version number. So the different mtime, filepath or content can be retrieved:
225 get the modification time of a (versioned) object
229 get the full qualified file path of the (versioned) object
233 get the content of the (versioned) object
235 =item C<version_count>
237 Get the available versions of the file
241 Returns an array of SL::File::Object objects with the available versions of the file, starting with the newest version.
245 If set this is the newest version of the file.
247 =item C<save_contents $contents>
249 Store a new contents to the file (as a new version).
251 =item C<save_file $filepath>
253 Store the content of an (absolute)file path to the file
257 Delete the file with all of his versions
259 =item C<delete_last_version>
261 Delete only the last version of the file with implicit decrement of the version_count.
265 Delete all old versions of the file. Only one version exist after purge. The version count is reset to 1.
267 =item C<rename $newfilename>
279 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>