Uses the database to scan CSS/JS files for changes.

Return value

array Array of files that have changed.

1 call to advagg_scan_for_changes()
advagg_push_new_changes dans ./advagg.cache.inc
Flush the correct caches so CSS/JS changes go live.
1 string reference to 'advagg_scan_for_changes'
advagg_hook_info dans ./advagg.module
Implements hook_hook_info().

Fichier

./advagg.cache.inc, line 16

Code

function advagg_scan_for_changes() {
    // Get all files stored in the database and filesystem.
    $files_that_have_changed = array();
    $result = db_select('advagg_files', 'af')->fields('af')
        ->execute();
    if (!empty($result)) {
        module_load_include('inc', 'advagg', 'advagg');
        $filenames = array();
        $data = array();
        foreach ($result as $row) {
            $filenames[] = $row->filename;
            $data[$row->filename] = (array) $row;
        }
        // Get filesystem data.
        $files_info = advagg_get_info_on_files($filenames, TRUE);
        foreach ($files_info as $info) {
            if (!isset($data[$info['data']])) {
                continue;
            }
            $row = $data[$info['data']];
            // Select the keys to compare.
            $keys_to_compare = array(
                'filesize',
                'content_hash',
                'linecount',
            );
            $changed = array();
            foreach ($keys_to_compare as $key) {
                if ($row[$key] != $info[$key]) {
                    $changed[] = $key . ' db:' . $row[$key] . ' file:' . $info[$key];
                    break;
                }
            }
            // Compare mtime if it is not zero.
            if (empty($info['split']) && !empty($info['mtime'])) {
                if (variable_get('advagg_strict_mtime_check', ADVAGG_STRICT_MTIME_CHECK) && $row['mtime'] != $info['mtime']) {
                    $changed[] = 'mtime db:' . $row['mtime'] . ' file:' . $info['mtime'];
                }
                elseif ($row['mtime'] < $info['mtime']) {
                    $changed[] = 'mtime db:' . $row['mtime'] . ' file:' . $info['mtime'];
                }
            }
            if (empty($changed)) {
                // Call hook_advagg_scan_for_changes().
                $changes_array = module_invoke_all('advagg_scan_for_changes', $row['filename']);
                if (is_array($changes_array)) {
                    foreach ($changes_array as $value) {
                        if (!empty($value)) {
                            $changed[] = $value;
                            break;
                        }
                    }
                }
            }
            // If file has changed, add it to the array.
            if (!empty($changed)) {
                $info['changes'] = $changed;
                $files_that_have_changed[$row['filename']] = $info;
            }
        }
    }
    return $files_that_have_changed;
}