You are here

function ocupload_change_files_status in One Click Upload 7

Same name and namespace in other branches
  1. 7.2 ocupload.module \ocupload_change_files_status()

Custom form submit. Change status uploaded files to "permanent".

1 string reference to 'ocupload_change_files_status'
ocupload_form_alter in ./ocupload.module
Implements hook_form_alter().

File

./ocupload.module, line 153
Hooks and general functions

Code

function ocupload_change_files_status($form, &$form_state) {
  $cid = 'ocupload:' . $form['#form_id'] . ':' . $GLOBALS['user']->uid;
  if ($cache = cache_get($cid)) {
    $permanent_files = array();
    foreach ($cache->data as $field_name => $files) {
      $field_value = _ocupload_field_value_by_html_name($form_state, $field_name);
      foreach ($files as $fid => $file_name) {
        if (strpos($field_value, $file_name) !== FALSE) {
          $file = file_load($fid);
          $file->status = FILE_STATUS_PERMANENT;
          file_save($file);
          unset($cache->data[$field_name][$fid]);
          $permanent_files[] = $file;
        }
      }
      if (count($cache->data[$field_name]) == 0) {
        unset($cache->data[$field_name]);
      }
    }
    if ($permanent_files) {
      drupal_alter('ocupload_saved_data', $permanent_files, $form, $form_state);
    }
    cache_set($cid, $cache->data, 'cache', count($cache->data) > 0 ? $cache->expire : CACHE_TEMPORARY);
  }
}