Exemple #1
0
 /**
  * Replace physical file
  * @param Assets_base_file $old_file
  * @param Assets_base_file $replace_with
  */
 public function replace_file(Assets_base_file $old_file, Assets_base_file $replace_with)
 {
     if ($old_file->kind() == 'image') {
         // we'll need this if replacing images
         $local_copy = $replace_with->get_local_copy();
     }
     $this->_delete_source_file($old_file->server_path());
     $this->_purge_cached_source_file($old_file->server_path());
     $this->_delete_generated_thumbs($old_file->file_id());
     $this->_move_source_file($replace_with, $replace_with->folder_row(), $old_file->folder_row(), $old_file->filename());
     if ($old_file->kind() == 'image') {
         $this->post_upload_image_actions($old_file->file_id(), $local_copy);
     }
     $data = array('width' => (int) $replace_with->width(), 'height' => (int) $replace_with->height(), 'size' => $replace_with->size(), 'date_modified' => $replace_with->date_modified());
     $this->EE->db->update('assets_files', $data, array('file_id' => $old_file->file_id()));
 }
Exemple #2
0
 /**
  * @param Assets_base_file $file
  * @param                  $previous_folder_row
  * @param                  $folder_row
  * @param string           $new_file_name
  * @param bool             $overwrite
  * @return array|mixed
  */
 protected function _move_source_file(Assets_base_file $file, $previous_folder_row, $folder_row, $new_file_name = '', $overwrite = FALSE)
 {
     if (empty($new_file_name)) {
         $new_file_name = $file->filename();
     }
     $new_server_path = $this->get_folder_server_path($folder_row->full_path, $folder_row) . $new_file_name;
     if (!$overwrite && (file_exists($new_server_path) or empty($this->cache['merge_in_progress']) && $this->EE->assets_lib->get_file_id_by_folder_id_and_name($folder_row->folder_id, $new_file_name))) {
         return $this->_prompt_result_array($new_file_name);
     }
     if (!$overwrite) {
         // make sure the filename is clean and unique
         $this->_prep_filename($new_server_path, $file->server_path());
     }
     // attempt to rename the file
     if (!@rename($file->server_path(), $new_server_path)) {
         return array('error' => lang('couldnt_save'));
     }
     $new_filename = pathinfo($new_server_path, PATHINFO_BASENAME);
     $is_image = $file->kind() == 'image';
     // moved from top level
     if ($previous_folder_row->parent_id == 0) {
         // to a different one - UPDATE
         if ($folder_row->parent_id == 0) {
             $filedir = $this->get_filedir($folder_row->filedir_id);
             $this->EE->db->where('upload_location_id', $previous_folder_row->filedir_id)->where('file_name', $file->filename())->update('files', array('site_id' => $filedir->site_id, 'upload_location_id' => $filedir->id, 'rel_path' => $new_server_path, 'file_name' => $new_filename));
         } else {
             $this->EE->db->where('upload_location_id', $previous_folder_row->filedir_id)->where('file_name', $file->filename())->delete('files');
         }
     } else {
         $source_server_path = $this->get_filedir($folder_row->filedir_id)->server_path;
         // to a top level one - INSERT
         // if we can do this without EE complaining
         if ($folder_row->parent_id == 0 && substr($source_server_path, 0, 3) != '../' && strpos($source_server_path, SYSDIR) === FALSE) {
             $this->_store_file_data($new_server_path, $folder_row->filedir_id);
         }
     }
     if ($is_image) {
         $this->_delete_thumbnails($file->server_path(), $previous_folder_row->filedir_id);
         $this->_create_thumbnails($new_server_path, $folder_row->filedir_id);
     }
     return array('success' => TRUE, 'file_id' => $file->file_id(), 'new_file_name' => $new_filename);
 }