You are here

function backup_migrate_format_size in Backup and Migrate 8.3

Same name and namespace in other branches
  1. 7.3 backup_migrate.module \backup_migrate_format_size()

A custom version of format size which treats 1GB as 1000 MB rather than 1024 MB This is a more standard and expected version for storage (as opposed to memory).

1 call to backup_migrate_format_size()
backup_migrate_nodesquirrel_status_form in includes/destinations.nodesquirrel.inc
Display the NodeSquirrel status on the configuration form.

File

./backup_migrate.module, line 1847
Create (manually or scheduled) and restore backups of your Drupal MySQL database with an option to exclude table data (e.g. cache_*)

Code

function backup_migrate_format_size($size, $langcode = LANGUAGE_NONE) {
  $precision = 2;
  $multiply = pow(10, $precision);
  if ($size == 0) {
    return t('0 bytes', array(), array(
      'langcode' => $langcode,
    ));
  }
  if ($size < 1024) {
    return format_plural($size, '1 byte', '@count bytes', array(), array(
      'langcode' => $langcode,
    ));
  }
  else {
    $size = ceil($size * $multiply / 1024);
    $string = '@size KB';
    if ($size >= 1024 * $multiply) {
      $size = ceil($size / 1024);
      $string = '@size MB';
    }
    if ($size >= 1000 * $multiply) {
      $size = ceil($size / 1000);
      $string = '@size GB';
    }
    if ($size >= 1000 * $multiply) {
      $size = ceil($size / 1000);
      $string = '@size TB';
    }
    return t($string, array(
      '@size' => round($size / $multiply, $precision),
    ), array(
      'langcode' => $langcode,
    ));
  }
}