Exemplo n.º 1
0
 public function delete()
 {
     if ($this->file_id && module_file::can_i('delete', 'Files')) {
         $file_data = $this->get_data();
         if ($this->can_i_access()) {
             // delete any sub files of buckets first.
             // todo: recurisive testing.
             if ($file_data['bucket']) {
                 $sub_files = module_file::get_files(array('bucket_parent_file_id' => $file_data['file_id']));
                 foreach ($sub_files as $sub_file) {
                     if ($sub_file['file_id'] && $sub_file['bucket_parent_file_id'] == $this->file_id) {
                         $sub_file_ucm = new ucm_file($sub_file['file_id']);
                         $sub_file_ucm->delete();
                     }
                 }
             }
             // delete the physical file.
             if ($file_data['file_path'] && is_file($file_data['file_path'])) {
                 unlink($file_data['file_path']);
             }
             // delete the db entry.
             delete_from_db('file', 'file_id', $this->file_id);
             // delete any comments.
             delete_from_db('file_comment', 'file_id', $this->file_id);
             // delete any staff rel.
             delete_from_db('file_user_rel', 'file_id', $this->file_id);
             // delete any notifications
             delete_from_db('file_notification', 'file_id', $this->file_id);
         }
     }
 }