Esempio n. 1
0
 /**
  * Transfers a file into this source from a file.
  *
  * @param string           $source_location
  * @param string           $folder_id
  * @param Assets_base_file $file
  * @param                  $action
  * @throws Exception
  * @return array
  */
 public function transfer_file_into_source($source_location, $folder_id, $file, $action)
 {
     $folder_row = $this->EE->assets_lib->get_folder_row_by_id($folder_id);
     $file_name = $file->filename();
     // swap whitespace with underscores
     $file_name = preg_replace('/\\s+/', '_', $file_name);
     // if this is not empty, we have a revisited conflict with some plan of action
     if (!empty($action)) {
         switch ($action) {
             case Assets_helper::ACTIONS_REPLACE:
                 $server_path = $this->_get_file_server_path($folder_row, $file_name);
                 if (!$this->EE->assets_lib->get_file_id_by_folder_id_and_name($folder_id, $file->filename())) {
                     $this->_delete_source_file($server_path);
                 } else {
                     $this->delete_file($this->EE->assets_lib->get_file_id_by_folder_id_and_name($folder_id, $file_name), TRUE);
                 }
                 break;
             case Assets_helper::ACTIONS_KEEP_BOTH:
                 $file_name = $this->get_name_replacement($folder_row, $file_name);
                 break;
         }
     }
     $result = $this->_do_upload_in_folder($folder_row, $source_location, $file_name, $action);
     if (isset($result['success'])) {
         $file_row = $file->row();
         $file_row['source_type'] = $this->get_source_type();
         $file_row['source_id'] = $folder_row->source_id;
         $file_row['filedir_id'] = $folder_row->filedir_id;
         $file_row['folder_id'] = $folder_id;
         $file_row['file_name'] = $file_name;
         $this->EE->db->update('assets_files', $file_row, array('file_id' => $file->file_id()));
         return $result;
     }
     return $result;
 }