You are here

function _boost_change_extension in Boost 6

Change a file extension in the database.

Parameters

$old: string of the old extension: .js

$new: string of the new extension: .json

1 call to _boost_change_extension()
boost_update_6109 in ./boost.install
Update 6109 - Change .js to .json

File

./boost.module, line 4861
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function _boost_change_extension($old, $new) {

  // make sure we are in the webroot
  chdir(dirname($_SERVER['SCRIPT_FILENAME']));
  $result = db_query("SELECT base_dir, filename, hash FROM {boost_cache} WHERE extension = '%s'", $old);
  while ($filename = db_fetch_array($result)) {

    // change extension
    $new_filename = _boost_kill_file_extension($filename['filename']) . $new;
    $hash = md5($new_filename);

    // update database
    db_query("UPDATE {boost_cache} SET filename = '%s', extension = '%s', hash = '%s' WHERE hash = '%s'", $new_filename, $new, $hash, $filename['hash']);

    // update files, normal & gzip
    $filenames = boost_get_all_filenames($filename['filename'], $filename['base_dir']);
    $new_filenames = boost_get_all_filenames($new_filename, $filename['base_dir']);
    foreach ($filenames as $key => $values) {
      foreach ($values as $num => $filename) {
        if (file_exists($filename)) {
          rename($filename, $new_filenames[$key][$num]);
        }
      }
    }
  }
}