You are here

function advagg_update_6109 in Advanced CSS/JS Aggregation 6

Update 6109 - Add filesize field to advagg_files table.

File

./advagg.install, line 951
Handles Advanced Aggregation installation and upgrade tasks.

Code

function advagg_update_6109() {
  $ret = array();

  // Make sure the advagg_get_root_files_dir function is available.
  drupal_load('module', 'advagg');

  // Add in timestamp column.
  db_add_field($ret, 'advagg_files', 'filesize', array(
    'description' => 'The filesize of the file in bytes.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Add in an index.
  db_add_index($ret, 'advagg_files', 'filesize', array(
    'filesize',
  ));

  // Populate the filesize column.
  list($css_path, $js_path) = advagg_get_root_files_dir();
  $results = db_query("SELECT filename, filename_md5 FROM {advagg_files} AS advagg_files");
  while ($row = db_fetch_array($results)) {
    $updated = FALSE;
    if (@is_readable($row['filename'])) {
      $size = filesize($row['filename']);
      if (!empty($size)) {
        db_query("UPDATE {advagg_files} SET filesize = %d WHERE filename_md5 = '%s'", $size, $row['filename_md5']);
        $updated = TRUE;
        $ret[] = array(
          'success' => TRUE,
          'query' => 'Filesize added for: ' . $row['filename'] . '.',
        );
      }
    }
    if (!$updated) {
      $ret[] = array(
        'success' => FALSE,
        'query' => 'Could not get the filesize for for: ' . $row['filename'] . '.',
      );
    }
  }
  return $ret;
}