You are here

function tmgmt_file_tmgmt_job_delete in Translation Management Tool 7

Same name and namespace in other branches
  1. 8 translators/tmgmt_file/tmgmt_file.module \tmgmt_file_tmgmt_job_delete()

Implements hook_tmgmt_job_delete().

File

translators/file/tmgmt_file.module, line 134
Module file of the translation management test module.

Code

function tmgmt_file_tmgmt_job_delete(TMGMTJob $job) {
  $translator = $job
    ->getTranslator();

  // Ignore jobs that don't have a file translator.
  if (!$translator || $translator->plugin != 'file') {
    return;
  }

  // Check if there are any files that need to be deleted.
  // @todo There doesn't seem to be an API function for this...
  $args = array(
    ':module' => 'tmgmt_file',
    ':type' => 'tmgmt_job',
    ':id' => $job->tjid,
  );
  $result = db_query('SELECT fid FROM {file_usage} WHERE module = :module and type = :type and id = :id', $args);
  $fids = $result
    ->fetchCol();
  if (!empty($fids)) {
    foreach (file_load_multiple($fids) as $file) {
      file_usage_delete($file, 'tmgmt_file', 'tmgmt_job', $job->tjid);

      // It is very unlikely that these files are used anywhere else. Delete it.
      file_delete($file);
    }
  }
}