You are here

function flash_update in Flash Node 5

Implementation of hook_update

File

./flash.module, line 447

Code

function flash_update($node) {

  // get the path of the old file
  $old_path = db_result(db_query("SELECT filepath FROM {files} WHERE filename='%s' AND nid=%d", '_flash', $node->nid));

  // This is a new file if the old path and the current path differ...
  if ($old_path != $node->flash['_flash']) {

    // ...so delete the old path
    file_delete(file_create_path($old_path));

    // delete the entries for the old file from the database
    db_query("DELETE FROM {files} WHERE filename='%s' AND nid=%d", '_flash', $node->nid);
    db_query("DELETE FROM {flash} WHERE nid=%d", $node->nid);

    // call flash_insert to create the new entry
    flash_insert($node);
  }
  else {

    // we still have the same file, but we have some new settings to update in the database
    db_query("UPDATE {flash} SET height=%d, width=%d, version=%d, build=%d, display=%d WHERE nid=%d", $node->flash['height'], $node->flash['width'], $node->flash['version'], $node->flash['build'], $node->flash['display'], $node->nid);
  }

  // reset the cache to ensure any pages using filters are updated
  cache_clear_all('*', 'cache_filter', true);
}