You are here

function webfm_dbupdate_file in Web File Manager 5.2

Same name and namespace in other branches
  1. 5 webfm.module \webfm_dbupdate_file()

webfm_dbupdate_file - updates information about a file

Parameters

int $fid - file id of the file to record to be altered:

string $path string containing the destination path relative to drupal root:

array $metadata - an array of key => value pairs, where key matches a field in the webfm_file table:

Return value

bool - TRUE if success - else FALSE

3 calls to webfm_dbupdate_file()
webfm_move_file in ./webfm_file.inc
webfm_putmeta in ./webfm.module
webfm_rename_db_file in ./webfm_file.inc

File

./webfm.module, line 1890

Code

function webfm_dbupdate_file($fid, $path = FALSE, $metadata = array()) {
  if ($path) {

    //add additional values to $metadata
    $metadata['fpath'] = $path;
  }

  //create a string of field value items in printf format
  foreach ($metadata as $key => $value) {
    if (is_numeric($value)) {
      $printfvalues[] = $key . '=%d';
    }
    else {
      $printfvalues[] = $key . "='%s'";
    }
  }
  $printfvalues = implode(', ', $printfvalues);
  $values = array_values($metadata);
  $values[] = $fid;

  //tack on the fid at the end for the last param for the update query - i.e. WHERE fid = %d

  //make a db_query friendly query with prinf stuff
  $query = "UPDATE {webfm_file} SET {$printfvalues} WHERE fid = %d";
  $result = db_query($query, $values);
  if ($result === FALSE) {
    drupal_set_message(t('webfm_dbupdate_file() err: fid=%fid', array(
      '%fid' => $fid,
    )), error);
    return FALSE;
  }
  return TRUE;
}