From 6679a4cb389e621ac0fd907345ee2a01897ea045 Mon Sep 17 00:00:00 2001 From: Max Kremmel Date: Sat, 16 Jun 2007 16:45:57 +0000 Subject: finally fix the friggin image replacement bug --- plugins/storage.bitfile.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/storage.bitfile.php b/plugins/storage.bitfile.php index ac2df07..ee4ac91 100644 --- a/plugins/storage.bitfile.php +++ b/plugins/storage.bitfile.php @@ -1,6 +1,6 @@ mDb->query( $sql, array( $pStoreRow['dest_file_path'], $pStoreRow['type'], $pStoreRow['size'], $pStoreRow['foreign_id'] ) ); + // we have been given an attachment_id but no foreign_id. we will make a last attempt to see if this is an update or an insert + if( @BitBase::verifyId( $pStoreRow['attachment_id'] ) && !@BitBase::verifyId( $pStoreRow['foreign_id'] )) { + $pStoreRow['foreign_id'] = $gBitSystem->mDb->getOne( "SELECT `foreign_id` FROM `".BIT_DB_PREFIX."liberty_attachments` WHERE `attachment_id` = ?", array( $pStoreRow['attachment_id'] )); + } + + if( @BitBase::verifyId( $pStoreRow['foreign_id'] ) ) { + $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `storage_path`=?, `mime_type`=?, `file_size`=? WHERE `file_id` = ?"; + $gBitSystem->mDb->query( $sql, array( $pStoreRow['upload']['dest_path'].$pStoreRow['upload']['name'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $pStoreRow['foreign_id'] ) ); } else { $pStoreRow['foreign_id'] = $gBitSystem->mDb->GenID( 'liberty_files_id_seq' ); $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_files` ( `storage_path`, `file_id`, `mime_type`, `file_size`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )"; -- cgit v1.3