예제 #1
0
 /**
  * @todo copy all versions, transaction, exceptions
  * @see FileInterface::copy()
  * @param integer $folder_id
  * @return bool
  */
 public function copy($folder_id, $all_versions = false)
 {
     global $transaction, $user;
     if (is_numeric($folder_id) and $this->file and $this->file_version and $this->file_id) {
         $old_data_entity_id = $this->data_entity_id;
         $old_file_name = $this->get_name();
         $source_folder = Folder::get_instance($this->get_parent_folder_id());
         $folder = Folder::get_instance($folder_id);
         // Create File
         $file_id = $this->create_shape($folder_id, $user->get_user_id());
         $data_entity_id = $this->get_data_entity_id();
         // Alle Versionen kopieren
         $current_file_version_id = FileVersion_Access::get_current_entry_by_toid($this->file_id);
         $current_file_version = new FileVersion_Access($current_file_version_id);
         $extension_array = explode(".", $current_file_version->get_name());
         $extension_array_length = substr_count($current_file_version->get_name(), ".");
         if ($extension_array_length == 0) {
             $extension = "";
         } else {
             $extension = "." . $extension_array[$extension_array_length];
         }
         $current_file_path = constant("BASE_DIR") . "/" . $source_folder->get_path() . "/" . $old_data_entity_id . "-" . $current_file_version->get_internal_revision() . "" . $extension;
         $size = filesize($current_file_path);
         $checksum = md5_file($current_file_path);
         if ($file_id != null) {
             $file_version_access = new FileVersion_access(null);
             $file_version_id = $file_version_access->create($file_id, $old_file_name, 1, $size, $checksum, null, null, 1, true, $user->get_user_id());
             if ($file_version_id == null) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
         $new_file_path = constant("BASE_DIR") . "/" . $folder->get_path() . "/" . $data_entity_id . "-1" . $extension;
         // Rename file with the object id
         if (copy($current_file_path, $new_file_path) == true) {
             if ($transaction_id != null) {
                 $transaction->commit($transaction_id);
             }
             self::__construct($file_id);
             return true;
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }