Insert info into the advagg_files and advagg_bundles database.

Parameters

$files: List of files in the proposed bundle.

$filetype: css or js.

$bundle_md5: Bundle's machine name.

$root: Is this a root bundle.

1 call to advagg_insert_bundle_db()
advagg_get_filename in ./advagg.module
Given a list of files; return back the aggregated filename.

File

./advagg.module, line 1104

Code

function advagg_insert_bundle_db($files, $filetype, $bundle_md5, $root) {
    $lock_name = 'advagg_insert_bundle_db' . $bundle_md5;
    if (!lock_acquire($lock_name)) {
        // If using async, wait before returning to give the other request time
        // to complete.
        if (variable_get('advagg_aggregate_mode', ADVAGG_AGGREGATE_MODE) < 2) {
            lock_wait($lock_name);
        }
        return;
    }
    // Double check that the bundle doesn't exist now that we are in a lock.
    $bundle_exists = db_query("SELECT 1 FROM {advagg_bundles} WHERE bundle_md5 = :bundle_md5", array(
        ':bundle_md5' => $bundle_md5,
    ))->fetchField();
    if ($bundle_exists) {
        lock_release($lock_name);
        return;
    }
    foreach ($files as $order => $filename) {
        $filename_md5 = md5($filename);
        // Insert file into the advagg_files table if it doesn't exist.
        $checksum = db_query("SELECT checksum FROM {advagg_files} WHERE filename_md5 = :filename_md5", array(
            ':filename_md5' => $filename_md5,
        ))->fetchField();
        if (empty($checksum)) {
            $checksum = advagg_checksum($filename);
            // TODO Please review the conversion of this statement to the D7 database API syntax.
            
            /* db_query("INSERT INTO {advagg_files} (filename, filename_md5, checksum, filetype, filesize) VALUES ('%s', '%s', '%s', '%s', %d)", $filename, $filename_md5, $checksum, $filetype, @filesize($filename)) */
            $id = db_insert('advagg_files')->fields(array(
                'filename' => $filename,
                'filename_md5' => $filename_md5,
                'checksum' => $checksum,
                'filetype' => $filetype,
                'filesize' => filesize($filename),
            ))
                ->execute();
        }
        // Create the entries in the advagg_bundles table.
        // TODO Please review the conversion of this statement to the D7 database API syntax.
        
        /* db_query("INSERT INTO {advagg_bundles} (bundle_md5, filename_md5, counter, porder, root, timestamp) VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", $bundle_md5, $filename_md5, 0, $order, $root, REQUEST_TIME) */
        $id = db_insert('advagg_bundles')->fields(array(
            'bundle_md5' => $bundle_md5,
            'filename_md5' => $filename_md5,
            'counter' => 0,
            'porder' => $order,
            'root' => $root,
            'timestamp' => REQUEST_TIME,
        ))
            ->execute();
    }
    lock_release($lock_name);
}