/** * */ public static function update($files, $wpid = null) { // LAST_INSERT_ID(id) is magic to make last insert id available whether we inserted OR updated. http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html static $sql_path = "INSERT INTO http_resources (path, version) VALUES (?, 1) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), version = version + 1"; static $sql_id = "UPDATE http_resources SET version = version + 1 WHERE id = ?"; static $sql_revs = "INSERT INTO http_resources_revs (res_id, wpid, version) VALUES (?, ?, ?)"; static $sql_version = "SELECT path, version FROM http_resources WHERE id = ?"; foreach ((array) $files as $file) { if (is_numeric($file) || is_int($file)) { // updating PSU::db('myplymouth')->Execute($sql_id, array($file)); $id = (int) $file; } else { // inserting, with a possible update PSU::db('myplymouth')->Execute($sql_path, array($file)); $id = PSU::db('myplymouth')->Insert_ID(); } // pull most recent version number $resource = PSU::db('myplymouth')->GetRow($sql_version, array($id)); PSU::cdn_expire($resource['path']); PSU::db('myplymouth')->Execute($sql_revs, array($id, $wpid, $resource['version'])); } }