You are here

function filefield_paths_node_update in File (Field) Paths 6

Same name and namespace in other branches
  1. 6.2 filefield_paths.module \filefield_paths_node_update()

Implements hook_node_update().

1 call to filefield_paths_node_update()
filefield_paths_node_insert in ./filefield_paths.module
Implements hook_node_insert().

File

./filefield_paths.module, line 383
Contains core functions for the FileField Paths module.

Code

function filefield_paths_node_update(&$node) {
  if (($ffp = filefield_paths_get_fields($node)) !== FALSE) {
    $update = new stdClass();
    $update->node = FALSE;

    // Process files.
    foreach ($ffp['#files'] as &$file) {

      // Invoke hook_filefield_paths_process_file().
      foreach (module_implements('filefield_paths_process_file') as $module) {
        $function = "{$module}_filefield_paths_process_file";
        $function($file['new'] || variable_get("ffp_{$node->type}_{$file['name']}", 0), $file, $ffp['#settings'][$file['name']], $node, $update);
      }
    }

    // Re-write node entry if required.
    if ($update->node == TRUE) {
      global $user;
      drupal_write_record('node', $node, 'nid');
      _node_save_revision($node, $user->uid, 'vid');
    }

    // Re-write cck fields.
    if (module_exists('content')) {
      if (module_exists('filefield')) {
        _field_file_cache(NULL, TRUE);
      }
      _content_field_invoke_default('update', $node);
      cache_clear_all("content:{$node->nid}:{$node->vid}", content_cache_tablename());
    }

    // Cleanup temporary paths.
    if ($ffp['#settings']) {
      foreach ($ffp['#settings'] as $name => $field) {
        $paths = explode('/', $field['filepath']['value']);
        filefield_paths_cleanup_temp($paths);

        // Invoke hook_filefield_paths_cleanup().
        foreach (module_implements('filefield_paths_cleanup') as $module) {
          $function = "{$module}_filefield_paths_cleanup";
          $function($ffp, $paths, $name);
        }
      }
    }
  }
}