You are here

function _minify_process_minify in Minify 7

Helper function to process minify call

4 calls to _minify_process_minify()
minify_batch_process in ./minify.admin.inc
Function to execute minify batch process
minify_update_7102 in ./minify.install
This update will clear all previously generated minify files and re-generate it. After update user must visit Performance -> Minify JavaScript files to confirm.
minify_update_7104 in ./minify.install
Update module weight, minify cache info and re-generate minified files if require
_minify_js_refresh_callback in ./minify.admin.inc
Helper function to regenerate minified js

File

./minify.admin.inc, line 225

Code

function _minify_process_minify($script, &$cache_data) {
  $js_code = urlencode(trim(file_get_contents(drupal_realpath($script))));
  $post_data = _minify_get_post_fields($js_code);
  $response = _minify_send_request($post_data);
  if (isset($response['response'])) {
    $response_obj = $response['response'];
    if (!isset($response_obj->warnings) && !isset($response_obj->serverErrors)) {
      $min_js_path = _minify_construct_min_js_path($script, $cache_data);
      if (file_put_contents($min_js_path, $response_obj->compiledCode)) {
        watchdog('minify', '%old_path minified successfully as %new_path.', array(
          '%old_path' => $script,
          '%new_path' => $min_js_path,
        ), WATCHDOG_NOTICE);
        drupal_set_message(t('%file_name minified successfully.', array(
          '%file_name' => $cache_data[$script]['file_name'],
        )));
        $cache_data[$script]['minified_file_path'] = $min_js_path;
        $cache_data[$script]['minified_size'] = $response_obj->statistics->compressedSize;
        $cache_data[$script]['status'] = true;
        $cache_data[$script]['last_minify_at'] = time();
        $cache_data[$script]['error'] = false;
        $cache_data[$script]['error_msg'] = null;
        $cache_data[$script]['md5'] = md5_file(drupal_realpath($script));
      }

      //File save if end
    }
    else {
      if (isset($response_obj->warnings)) {
        $warning = $response_obj->warnings[0]->warning;
        $cache_data[$script]['error'] = true;
        $cache_data[$script]['error_msg'] = $warning;
        watchdog('minify', 'Failed to generate minified JS. Error: %warning', array(
          '%warning' => $warning,
        ), WATCHDOG_ERROR);
        form_set_error('null', t('Failed to generate minified JS. Error: %warning', array(
          '%warning' => $warning,
        )));
      }
      else {
        if (isset($response_obj->serverErrors)) {
          watchdog('minify', 'Server error, Too many compiles performed recently. Try again later.', array(), WATCHDOG_ERROR);
          form_set_error('null', t('Server error, Too many compiles performed recently. Try again later.'));
        }
      }
    }

    /* Update the cache */
    variable_set('minify_captured_js', $cache_data);
  }

  // Response isset if end
}