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 bless +{ %{ $_[0] } }, __PACKAGE__;
132 sub init_db_file { die 'must always have a db file'; }
133 sub init_loaded { 0 }
135 sub init_version { 0 }
136 sub init_newest { 1 }
146 SL::File::Object - a filemangement object wrapper
152 my ($object) = SL::File->get_all(object_id => $object_id,
153 object_type => $object_type,
154 file_type => 'images', # may be optional
155 source => 'uploaded' # may be optional
159 my $object_id = $object->object_id,
160 my $object_type = $object->object_type,
161 my $file_type = $object->file_type;
162 my $file_name = $object->file_name;
163 my $mime_type = $object->mime_type;
165 my $mtime = $object->mtime;
166 my $itime = $object->itime;
167 my $id = $object->id;
168 my $newest = $object->newest;
170 my $versions = $object->version_count;
172 my @versionobjs = $object->versions;
173 foreach ( @versionobjs ) {
174 my $mtime = $_->mtime;
175 my $contents = $_->get_content;
180 $object->rename("image1.png");
181 $object->save_contents("new text");
182 $object->save_file("/tmp/empty.png");
184 $object->delete_last_version;
189 This is a wrapper around a single object in the filemangement.
193 Following methods are wrapper to read the attributes of L<SL::DB::File> :
209 =item C<file_description>
221 Additional are there special methods. If the Object is created by SL::File::get_all_versions()
222 or by "$object->versions"
223 it has a version number. So the different mtime, filepath or content can be retrieved:
229 get the modification time of a (versioned) object
233 get the full qualified file path of the (versioned) object
237 get the content of the (versioned) object
239 =item C<version_count>
241 Get the available versions of the file
245 Returns an array of SL::File::Object objects with the available versions of the file, starting with the newest version.
249 If set this is the newest version of the file.
251 =item C<save_contents $contents>
253 Store a new contents to the file (as a new version).
255 =item C<save_file $filepath>
257 Store the content of an (absolute)file path to the file
261 Delete the file with all of his versions
263 =item C<delete_last_version>
265 Delete only the last version of the file with implicit decrement of the version_count.
269 Delete all old versions of the file. Only one version exist after purge. The version count is reset to 1.
271 =item C<rename $newfilename>
283 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>