Populate the filesize_processed field in the advagg_files table.

Fichier

./advagg.install, line 607

Code

function advagg_update_7211(&$sandbox) {
    drupal_load('module', 'advagg');
    module_load_include('inc', 'advagg', 'advagg');
    $types = array(
        'css',
        'js',
    );
    // If first run of this update function then set progress variables.
    if (!isset($sandbox['progress'])) {
        $count = db_select('advagg_files', 'af')->fields('af')
            ->condition('filesize_processed', 0)
            ->countQuery()
            ->execute()
            ->fetchField();
        $sandbox['progress'] = 0;
        $sandbox['max'] = $count;
    }
    // How many items should be processed per pass.
    $limit = 20;
    foreach ($types as $type) {
        $query = db_select('advagg_files', 'af')->fields('af')
            ->condition('filesize_processed', 0)
            ->condition('filetype', $type)
            ->range($sandbox['progress'], $limit)
            ->execute();
        foreach ($query as $row) {
            $row->filesize_processed = (int) advagg_generate_filesize_processed($row->filename, $type);
            if (!empty($row->filesize_processed)) {
                $write = (array) $row;
                db_merge('advagg_files')->key(array(
                    'filename_hash' => $write['filename_hash'],
                ))
                    ->fields($write)
                    ->execute();
            }
        }
    }
    // Update our progress information.
    $sandbox['progress'] += $limit;
    // Set the value for finished.
    $sandbox['#finished'] = $sandbox['progress'] >= $sandbox['max'] ? TRUE : $sandbox['progress'] / $sandbox['max'];
    if ($sandbox['#finished']) {
        return t('The filesize_processed field has been populated inside the advagg_files table.');
    }
}