Fichier

src/State/Files.php, line 156

Classe

Files
Provides AdvAgg with a file status state system using a key value store.

Namespace

Drupal\advagg\State

Code

public function getMultiple(array $keys, $refresh_data = NULL) {
    $values = [];
    $load = [];
    $cache_level = $this->config
        ->get('cache_level');
    $cache_time = advagg_get_cache_time($cache_level);
    foreach ($keys as $key) {
        // Check if we have a value in the cache.
        $value = $this->get($key);
        if ($value) {
            $values[$key] = $value;
        }
        else {
            $load[] = $key;
        }
    }
    if ($load) {
        $loaded_values = $this->keyValueStore
            ->getMultiple($load);
        foreach ($load as $key) {
            // If we find a value, add it to the temporary cache.
            if (isset($loaded_values[$key])) {
                if ($refresh_data === FALSE) {
                    $values[$key] = $loaded_values[$key];
                    $this->set($key, $loaded_values[$key]);
                    continue;
                }
                $file_contents = (string) @file_get_contents($key);
                if (!$refresh_data && $cache_level != -1 && !empty($loaded_values[$key]['updated'])) {
                    // If data last updated too long ago check for changes.
                    // Ensure the file exists.
                    if (!file_exists($key)) {
                        $this->delete($key);
                        $values[$key] = NULL;
                        continue;
                    }
                    // If cache is Normal, check file for changes.
                    if ($cache_level == 1 || REQUEST_TIME - $loaded_values[$key]['updated'] < $cache_time) {
                        $content_hash = Crypt::hashBase64($file_contents);
                        if ($content_hash == $loaded_values[$key]['content_hash']) {
                            $values[$key] = $loaded_values[$key];
                            $this->set($key, $loaded_values[$key]);
                            continue;
                        }
                    }
                }
                // If file exists but is changed rescan.
                $values[$key] = $this->scanFile($key, $loaded_values[$key], $file_contents);
                continue;
            }
            if (file_exists($key)) {
                // File has never been scanned, scan it.
                $values[$key] = $this->scanFile($key);
            }
        }
    }
    return $values;
}