Project

General

Profile

Revision 1f142f4f

Added by Florent Torregrosa over 8 years ago

Issue #592: Update file_entity to version 7.x-2.0-beta2.

View differences:

drupal7/sites/all/modules/file_entity/file_entity.pages.inc
165 165

  
166 166
  // Remove any schemes not found in the instance settings.
167 167
  if (!empty($options['schemes'])) {
168
    $schemes = array_intersect_key($schemes, $options['schemes']);
168
    $schemes = array_intersect_key($schemes, array_flip($options['schemes']));
169 169
  }
170 170

  
171 171
  // Determine which scheme to use as the default value.
......
245 245
  $rows = array();
246 246
  $occured_entities = array();
247 247

  
248
  foreach (file_usage_list($file) as $module => $usage) {
249
    $info = system_get_info('module', $module);
250

  
251
    // There are cases where the actual entity doesn't exist.
252
    // We have to handle this.
253
    foreach ($usage as $entity_type => $entity_ids) {
248
  // Determine all of the locations where a file is used, then loop through the
249
  // occurrences and filter out any duplicates.
250
  foreach (file_usage_list($file) as $module => $type) {
251
    foreach ($type as $entity_type => $entity_ids) {
252
      // There are cases where the actual entity doesn't exist.
253
      // We have to handle this.
254 254
      $entity_info = entity_get_info($entity_type);
255 255
      $entities = empty($entity_info) ? NULL : entity_load($entity_type, array_keys($entity_ids));
256 256

  
257 257
      foreach ($entity_ids as $entity_id => $count) {
258
        // If some other module already added this entity just sum all counts.
258
        // If this entity has already been listed in the table, just add any
259
        // additional usage to the total count column in the table row and
260
        // continue on to the next iteration of the loop.
259 261
        if (isset($occured_entities[$entity_type][$entity_id])) {
260 262
          $rows[$occured_entities[$entity_type][$entity_id]][2] += $count;
261 263
          continue;
262 264
        }
263 265

  
266
        // Retrieve the label and the URI of the entity.
264 267
        $label = empty($entities[$entity_id]) ? $module : entity_label($entity_type, $entities[$entity_id]);
265 268
        $entity_uri = empty($entities[$entity_id]) ? NULL : entity_uri($entity_type, $entities[$entity_id]);
266 269

  
267
        // Some entities do not have URL.
270
        // Link the label to the URI when possible.
268 271
        if (empty($entity_uri)) {
269
          $rows[] = array(check_plain($label), $entity_type, $module, $count);
272
          $entity = check_plain($label);
270 273
        }
271 274
        else {
272
          $uri = $entity_uri['path'];
273
          $rows[] = array(l($label, $uri), $entity_type, $module, $count);
275
          $entity = l($label, $entity_uri['path']);
274 276
        }
275 277

  
278
        $rows[] = array($entity, $entity_type, $count);
279

  
280
        // Record the occurrence of the entity to ensure that it isn't listed in
281
        // the table again.
276 282
        $occured_entities[$entity_type][$entity_id] = count($rows) - 1;
277 283
      }
278 284
    }
279 285
  }
280
  $header[] = array(
281
    'data' => t('Entity'),
282
  );
283
  $header[] = array(
284
    'data' => t('Entity type'),
285
  );
286
  $header[] = array(
287
    'data' => t('Registering module'),
288
  );
289
  $header[] = array(
290
    'data' => t('Use count'),
291
  );
286

  
287
  $header = array(t('Entity'), t('Entity type'), t('Use count'));
292 288
  $build['usage_table'] = array(
293 289
    '#theme' => 'table',
294 290
    '#header' => $header,
295 291
    '#rows' => $rows,
296
    '#caption' => t('This table lists all of the places where @filename is used.',
297
    array('@filename' => $file->filename)),
292
    '#caption' => t('This table lists all of the places where @filename is used.', array('@filename' => $file->filename)),
298 293
    '#empty' => t('This file is not currently used.'),
299 294
  );
295

  
300 296
  return $build;
301 297
}
302 298

  
......
428 424
    $file = file_load($form_state['storage']['upload']);
429 425
    if ($file) {
430 426
      if (file_uri_scheme($file->uri) != $form_state['storage']['scheme']) {
431
        if ($moved_file = file_move($file, $form_state['storage']['scheme'] . '://' . file_uri_target($file->uri), FILE_EXISTS_RENAME)) {
427
        $file_destination = $form_state['storage']['scheme'] . '://' . file_uri_target($file->uri);
428
        $file_destination = file_stream_wrapper_uri_normalize($file_destination);
429
        if ($moved_file = file_move($file, $file_destination, FILE_EXISTS_RENAME)) {
432 430
          // Only re-assign the file object if file_move() did not fail.
433 431
          $file = $moved_file;
434 432
        }
......
455 453
    }
456 454

  
457 455
    // Figure out destination.
458
    if (isset($_GET['destination'])) {
459
      $destination = drupal_get_destination();
460
      unset($_GET['destination']);
461
    }
462
    elseif (user_access('administer files')) {
463
      $destination = array('destination' => 'admin/content/file');
456
    if (user_access('administer files')) {
457
      $path = 'admin/content/file';
464 458
    }
465 459
    else {
466
      $destination = array('destination' => 'file/' . $file->fid);
460
      $path = 'file/' . $file->fid;
467 461
    }
468
    $form_state['redirect'] = $destination['destination'];
462
    $form_state['redirect'] = $path;
469 463
  }
470 464
  else {
471 465
    $form_state['rebuild'] = TRUE;
......
558 552
      $file->status = FILE_STATUS_PERMANENT;
559 553
      file_save($file);
560 554

  
561
      $saved_files[] = $file;
562 555
      $form_state['files'][$file->fid] = $file;
563 556
    }
564 557
    else {
......
568 561
  }
569 562

  
570 563
  // Redirect to the file edit page.
571
  if (file_entity_access('update', $file) && module_exists('multiform') && module_exists('media')) {
564
  if (file_entity_access('update', $file) && module_exists('media_bulk_upload')) {
572 565
    $destination = array();
573 566
    if (isset($_GET['destination'])) {
574 567
      $destination = drupal_get_destination();
......
807 800
  if (!empty($form_state['values']['replace_upload'])) {
808 801
    $replacement = $form_state['values']['replace_upload'];
809 802
    // Move file from temp to permanent home.
810
    $destination_uri = file_uri_scheme($file->uri) . '://' . file_uri_target($replacement->uri);
803
    $destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($replacement->uri);
811 804
    $replace_mode = $destination_uri == $file->uri ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME;
812 805
    if ($new_file_uri = file_unmanaged_copy($replacement->uri, $destination_uri, $replace_mode)) {
813 806
      // @todo Add watchdog() about replaced file here?
......
848 841
  }
849 842

  
850 843
  if (file_uri_scheme($file->uri) != $form_state['values']['scheme']) {
851
    if ($moved_file = file_move($file, $form_state['values']['scheme'] . '://' . file_uri_target($file->uri), FILE_EXISTS_RENAME)) {
844
    $file_destination = $form_state['storage']['scheme'] . '://' . file_uri_target($file->uri);
845
    $file_destination = file_stream_wrapper_uri_normalize($file_destination);
846
    if ($moved_file = file_move($file, $file_destination, FILE_EXISTS_RENAME)) {
852 847
      // Only re-assign the file object if file_move() did not fail.
853 848
      $file = $moved_file;
854 849
    }

Also available in: Unified diff