You are here

function _cdn_requirements_check_patch_applied in CDN 6.2

Check if a patch has been applied, given a set of patterns.

2 calls to _cdn_requirements_check_patch_applied()
_cdn_requirements_detect_fallback in ./cdn.requirements.inc
Detect whether the fallback mechanism (to alter file URLs, the best mechanism is the core patch, but a fallback to the theme layer is included) should be enabled or disabled, and actually enable/disable it, too.
_cdn_requirements_generate_requirement_for_patch in ./cdn.requirements.inc
Generates a requirement for the given patch.

File

./cdn.requirements.inc, line 51
Functionality to automatically detect if a patch has been applied.

Code

function _cdn_requirements_check_patch_applied($patterns) {
  $drupal_root = realpath('.');
  $patched = TRUE;
  $unpatched_files = array();
  foreach ($patterns as $kind => $details) {
    foreach ($details as $file_info => $patterns) {
      foreach ($patterns as $pattern) {
        if ($kind == 'core') {
          $filename = $file_info;
          $full_path = $drupal_root . '/' . $filename;
        }
        else {
          list($name, $filename) = explode('|', $file_info);
          $full_path = $drupal_root . '/' . drupal_get_path($kind, $name) . '/' . $filename;
        }
        if ($full_path) {
          $match = preg_match('|' . preg_quote($pattern) . '|m', file_get_contents($full_path));

          // If it didn't match, try allowing \r\n line endings and see if it
          // it then matches. This is of course also qualifies as a correctly
          // applied patch.
          if (!$match) {
            $match = preg_match('|' . preg_quote($pattern) . '|m', str_replace("\n", "\r\n", file_get_contents($full_path)));
          }
          $patched = $patched && $match;

          // Remember unpatched files.
          if (!$match && !in_array($full_path, $unpatched_files)) {
            $unpatched_files[] = $full_path;
          }
        }
      }
    }
  }
  return $unpatched_files;
}