You are here

function flashnode_update in Flash Node 5.6

Same name and namespace in other branches
  1. 5.2 flashnode.module \flashnode_update()
  2. 5.3 flashnode.module \flashnode_update()
  3. 6.3 flashnode.module \flashnode_update()
  4. 6.2 flashnode.module \flashnode_update()

Implementation of hook_update

File

./flashnode.module, line 447

Code

function flashnode_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", '_flashnode', $node->nid));

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

    // ...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", '_flashnode', $node->nid);
    db_query("DELETE FROM {flashnode} WHERE nid=%d", $node->nid);

    // Call flashnode_insert to create the new entry
    flashnode_insert($node);
  }
  else {

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

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