Insert/Update data in the advagg_aggregates table.

Paramètres

array $files: List of files in the aggregate including files meta data.

string $aggregate_filenames_hash: Hash of the groupings of files.

Return value

bool Return TRUE if anything was written to the database.

1 call to advagg_insert_aggregate()
advagg_insert_update_db dans ./advagg.inc
Insert/Update data in advagg tables.

Fichier

./advagg.inc, line 94

Code

function advagg_insert_aggregate(array $files, $aggregate_filenames_hash) {
    // Record if a database write was done.
    $write_done = FALSE;
    // Check if the aggregate is in the database.
    $files_in_db = array();
    $query = db_select('advagg_aggregates', 'aa')->fields('aa', array(
        'filename_hash',
    ))
        ->condition('aggregate_filenames_hash', $aggregate_filenames_hash)
        ->orderBy('aa.porder', 'ASC')
        ->execute();
    foreach ($query as $row) {
        $files_in_db[$row->filename_hash] = (array) $row;
    }
    $count = 0;
    foreach ($files as $file_meta_data) {
        ++$count;
        // Skip if the file already exists in the aggregate.
        if (!empty($files_in_db[$file_meta_data['filename_hash']])) {
            continue;
        }
        // Store settings for this file that depend on how it was added.
        $settings = array();
        if (isset($file_meta_data['media_query'])) {
            $settings['media'] = $file_meta_data['media_query'];
        }
        // Write record into the database.
        $record = array(
            'aggregate_filenames_hash' => $aggregate_filenames_hash,
            'filename_hash' => $file_meta_data['filename_hash'],
            'porder' => $count,
            'settings' => serialize($settings),
        );
        $return = db_merge('advagg_aggregates')->key(array(
            'aggregate_filenames_hash' => $record['aggregate_filenames_hash'],
            'filename_hash' => $record['filename_hash'],
        ))
            ->insertFields($record)
            ->execute();
        if ($return) {
            $write_done = TRUE;
        }
    }
    return $write_done;
}