You are here

function _textimage_preset_flush in Textimage 7.2

Same name and namespace in other branches
  1. 5.2 textimage_admin.inc \_textimage_preset_flush()
  2. 5 textimage.module \_textimage_preset_flush()
  3. 6.2 textimage_admin.inc \_textimage_preset_flush()

Flush cached media for a preset.

Parameters

string $pid: A preset id.

bool $delete_data: Boolean whether to delete textimage data or not

3 calls to _textimage_preset_flush()
textimage_preset_flush_confirm_submit in ./textimage.admin.inc
Todo.
_textimage_preset_delete in ./textimage.admin.inc
Todo.
_textimage_preset_update in ./textimage.admin.inc
Update a preset.

File

./textimage.admin.inc, line 659
Textimage admin page callback

Code

function _textimage_preset_flush($pid, $delete_data = FALSE) {
  if ($pid !== 0) {
    drupal_set_message(t('Flushed Preset Images (ID: @pid)', array(
      '@pid' => $pid,
    )));
  }
  file_unmanaged_delete_recursive(variable_get('file_default_scheme', 'public') . '://textimage/' . $pid);
  if ($delete_data) {
    db_delete('textimage_image')
      ->condition('pid', $pid)
      ->execute();
  }
  else {
    $query = db_query('SELECT file FROM {textimage_image} WHERE pid LIKE :pid', array(
      ':pid' => $pid,
    ))
      ->fetchAll();
    foreach ($query as $file_obj) {

      // Clear cached versions of this image file in all styles.
      image_path_flush($file_obj->file);
      $filename = explode('/', $file_obj->file);
      $filename = $filename[count($filename) - 1];

      // Restore images in reference with images stored at {textimage_image}
      textimage_deliver($pid, $filename, FALSE);
    }
  }
}