CVS update: /cowiki/includes/cowiki/class/dao/
[email protected] 12 May 2005 21:42:38 -0000
| Newsgroups | gmane.comp.php.cowiki.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: dgorski Date: 2005/05/12 14:42:38 Modified: cowiki/includes/cowiki/class/dao/class.UserDAOMySQL.php cowiki/includes/cowiki/class/dao/class.DocumentDAO.php cowiki/includes/cowiki/class/dao/class.CommentDAO.php Log: Added transaction demarcation (begin/commit/rollback) File Changes: Directory: /cowiki/includes/cowiki/class/dao/ ============================================= File [changed]: class.UserDAOMySQL.php Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/dao/class.UserDAOMySQL.php?r1=1.23&r2=1.24 Delta lines: +69 -33 --------------------- --- class.UserDAOMySQL.php 1 May 2005 04:34:28 -0000 1.23 +++ class.UserDAOMySQL.php 12 May 2005 21:42:36 -0000 1.24 @@ -2,7 +2,7 @@ /** * - * $Id: class.UserDAOMySQL.php,v 1.23 2005/05/01 04:34:28 dgorski Exp $ + * $Id: class.UserDAOMySQL.php,v 1.24 2005/05/12 21:42:36 dgorski Exp $ * * This file is part of coWiki. coWiki is free software under the terms of * the GNU General Public License (GPL). Read the LICENSE file. If you did @@ -17,7 +17,7 @@ * @author Daniel T. Gorski, <[email protected]> * @copyright (C) Daniel T. Gorski, {@link http://www.develnet.org} * @license http://www.gnu.org/licenses/gpl.html - * @version $Revision: 1.23 $ + * @version $Revision: 1.24 $ * */ @@ -333,6 +333,9 @@ // ---------------------------------------------------------------- + // Begin transaction + $this->Storage->begin(); + // Check if login already exists $sQuery = " SELECT COUNT(login) AS rec_count FROM ".$this->sUserTable." @@ -345,6 +348,10 @@ // Oops, doublette or previous errors if ($aData['rec_count'] > 0) { + + // Rollback transaction + $this->Storage->rollback(); + $Context->addError(454); return false; } @@ -361,6 +368,10 @@ $this->Storage->freeResult($rResult); if ($aData['rec_tan'] != $User->get('recTan')) { + + // Rollback transaction + $this->Storage->rollback(); + // Warn only once! $User->set('recTan', $aData['rec_tan']); $Context->addError(440); @@ -406,16 +417,14 @@ // --- if ($Context->hasErrors()) { + + // Rollback transaction + $this->Storage->rollback(); return false; } // ---------------------------------------------------------------- - // Begin transaction -# $this->Storage->beginTransaction(); - - // ---------------------------------------------------------------- - // Gather data for insert/update $aFields = array( 'rec_tan' => $this->Storage->generateTan(), @@ -504,8 +513,8 @@ $User->get('userId') ); - // End transaction -# $this->Storage->endTransaction(); + // Commit transaction + $this->Storage->commit(); // Tell the observers that something has changed $this->notifyObservers(); @@ -532,7 +541,7 @@ $bSuccess = true; // Begin transaction -# $this->Storage->beginTransaction(); + $this->Storage->begin(); $It = $Users->iterator(); @@ -542,6 +551,9 @@ $Obj->set('password', null); if (!$this->storeUser($Obj)) { + // Rollback transaction + $this->Storage->rollback(); + // FIX the error RuntimeContext::getInstance()->addError(0); $bSuccess = false; @@ -549,8 +561,10 @@ } } - // End transaction -# $this->Storage->endTransaction(); + if ($bSuccess) { + // Commit transaction + $this->Storage->commit(); + } return $bSuccess; } @@ -594,14 +608,14 @@ ); // Begin transaction -# $this->Storage->beginTransaction(); + $this->Storage->begin(); // Execute delete (remove) $this->Storage->remove($aDeleteAssign); $this->Storage->remove($aDeleteUser); - // End transaction -# $this->Storage->endTransaction(); + // Commit transaction + $this->Storage->commit(); return $Context->hasNoErrors(); } @@ -651,6 +665,9 @@ return $this->Groups; } + // Begin transaction + $this->Storage->begin(); + $sQuery = "SELECT rec_tan, rec_mod_id, rec_mod_ip, @@ -659,7 +676,7 @@ group_id, name, description - FROM cowiki_group + FROM ".$this->sGroupTable." ORDER BY group_id"; $rResult = $this->Storage->query($sQuery); @@ -686,7 +703,8 @@ $this->Groups->add($Group); } - $this->Storage->freeResult($rResult); + // Commit transaction + $this->Storage->commit(); // Groups has been already read $this->bGotAllGroups = true; @@ -734,6 +752,9 @@ // ---------------------------------------------------------------- + // Begin transaction + $this->Storage->begin(); + // Check if group already exists $sQuery = " SELECT COUNT(name) AS rec_count FROM ".$this->sGroupTable." @@ -746,6 +767,10 @@ // Oops, doublette or previous errors if ($aData['rec_count'] > 0) { + + // Rollback transaction + $this->Storage->rollback(); + $Context->addError(457); return false; } @@ -762,6 +787,10 @@ $this->Storage->freeResult($rResult); if ($aData['rec_tan'] != $Group->get('recTan')) { + + // Rollback transaction + $this->Storage->rollback(); + // Warn only once! $Group->set('recTan', $aData['rec_tan']); $Context->addError(440); @@ -792,9 +821,6 @@ // ---------------------------------------------------------------- - // Begin transaction -# $this->Storage->beginTransaction(); - // If this is an update if ($Group->get('groupId') != 0) { @@ -825,8 +851,8 @@ ); } - // End transaction -# $this->Storage->endTransaction(); + // Commit transaction + $this->Storage->commit(); return true; } @@ -850,12 +876,16 @@ $bSuccess = true; // Begin transaction -# $this->Storage->beginTransaction(); + $this->Storage->begin(); $It = $Groups->iterator(); while ($Obj = $It->next()) { if (!$this->storeGroup($Obj)) { + + // Rollback transaction + $this->Storage->rollback(); + // FIX the error RuntimeContext::getInstance()->addError(0); $bSuccess = false; @@ -863,8 +893,10 @@ } } - // End transaction -# $this->Storage->endTransaction(); + if ($bSuccess) { + // Commit transaction + $this->Storage->commit(); + } return $bSuccess; } @@ -908,14 +940,14 @@ ); // Begin transaction -# $this->Storage->beginTransaction(); + $this->Storage->begin(); // Execute delete (remove) $this->Storage->remove($aDeleteAssign); $this->Storage->remove($aDeleteGroup); - // End transaction -# $this->Storage->endTransaction(); + // Commit transaction + $this->Storage->commit(); return $Context->hasNoErrors(); } @@ -940,11 +972,14 @@ $this->getAllGroups(); + // Begin transaction + $this->Storage->begin(); + // Container for users member groups $MemberGroups = new Vector(); $sQuery = " SELECT group_id - FROM cowiki_user_group + FROM ".$this->sAssignTable." WHERE user_id = '".$nId."' ORDER BY group_id"; @@ -961,7 +996,8 @@ } } - $this->Storage->freeResult($rResult); + // Commit transaction + $this->Storage->commit(); return $MemberGroups; } @@ -986,7 +1022,7 @@ protected function storeMemberGroupsOfUid($Groups, $nId) { // Begin transaction -# $this->Storage->beginTransaction(); + $this->Storage->begin(); // Clean up and delete memeber groups frist $aDelete = array( @@ -1018,8 +1054,8 @@ $this->Storage->insert($aInsert); } - // End transaction -# $this->Storage->endTransaction(); + // Commit transaction + $this->Storage->commit(); } } // of class File [changed]: class.DocumentDAO.php Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/dao/class.DocumentDAO.php?r1=1.70&r2=1.71 Delta lines: +81 -11 --------------------- --- class.DocumentDAO.php 1 May 2005 04:34:28 -0000 1.70 +++ class.DocumentDAO.php 12 May 2005 21:42:36 -0000 1.71 @@ -2,7 +2,7 @@ /** * - * $Id: class.DocumentDAO.php,v 1.70 2005/05/01 04:34:28 dgorski Exp $ + * $Id: class.DocumentDAO.php,v 1.71 2005/05/12 21:42:36 dgorski Exp $ * * This file is part of coWiki. coWiki is free software under the terms of * the GNU General Public License (GPL). Read the LICENSE file. If you did @@ -17,7 +17,7 @@ * @author Daniel T. Gorski, <[email protected]> * @copyright (C) Daniel T. Gorski, {@link http://www.develnet.org} * @license http://www.gnu.org/licenses/gpl.html - * @version $Revision: 1.70 $ + * @version $Revision: 1.71 $ * */ @@ -1162,7 +1162,7 @@ AND sort_order < '".$Node->get('sortOrder')."' ORDER BY sort_order DESC"; - // We need on result + // We need one result $sQuery = $this->Storage->addLimitToQuery($sQuery, 0, 1); // {{{ DEBUG }}} @@ -1206,7 +1206,7 @@ AND sort_order > '".$Node->get('sortOrder')."' ORDER BY sort_order ASC"; - // We need on result + // We need one result $sQuery = $this->Storage->addLimitToQuery($sQuery, 0, 1); // {{{ DEBUG }}} @@ -1236,17 +1236,31 @@ */ public function incrementViews($Node) { + // Begin transaction + $this->Storage->begin(); + // {{{ DEBUG }}} Logger::info('Incrementing view counter of node #'.$Node->get('id')); + try { $aUpdate = array( 'table' => $this->sNodeTable, 'fields' => array('views' => $Node->get('views') + 1), 'where' => "node_id = '".$Node->get('id')."'" ); - // Execute update (terminates on error) + // Execute update $this->Storage->update($aUpdate); + + } catch (StorageException $se) { + + // Rollback transaction + $this->Storage->rollback(); + throw $se; + } + + // Commit transaction + $this->Storage->commit(); } // -------------------------------------------------------------------- @@ -1340,8 +1354,15 @@ // ---------------------------------------------------------------- + // Begin transaction + $this->Storage->begin(); + // Check for a duplicate names if ($this->getNameDupesCount($Node) > 0) { + + // Rollback transaction + $this->Storage->rollback(); + $this->Context->addError($Node->get('isWeb') ? 411 : 422); // {{{ DEBUG }}} @@ -1368,6 +1389,10 @@ $this->Storage->freeResult($rResult); if ($aData !== false && $aData['rec_tan'] != $Node->get('recTan')) { + + // Rollback transaction + $this->Storage->rollback(); + // Warn only once! $Node->set('recTan', $aData['rec_tan']); $this->Context->addError(440); @@ -1583,6 +1608,11 @@ // Store node ids this node is referencing to $this->storeNodeReferences($Node); + // --- + + // Commit transaction + $this->Storage->commit(); + // Tell the observers that something has changed $this->notifyObservers(); @@ -1605,6 +1635,9 @@ */ protected function updateParentOf($Node) { + // Begin transaction + $this->Storage->begin(); + // {{{ DEBUG }}} Logger::info('Updating the parent of node id #'.$Node->get('id')); @@ -1622,6 +1655,9 @@ // Execute update $this->Storage->update($aUpdate); + + // Commit transaction + $this->Storage->commit(); } // -------------------------------------------------------------------- @@ -1771,6 +1807,9 @@ return false; } + // Begin transaction + $this->Storage->begin(); + $aInsert = array( 'table' => $this->sNodeHistTable, 'fields' => $this->aBackup @@ -1778,6 +1817,9 @@ // Store backup $this->Storage->insert($aInsert); + + // Commit transaction + $this->Storage->commit(); } // -------------------------------------------------------------------- @@ -1799,6 +1841,9 @@ return true; // FIX: TEMPORARILY DISABLED + // Begin transaction + $this->Storage->begin(); + // Delete all references to this node $aDelete = array( 'table' => $this->sNodeRefTable, @@ -1827,6 +1872,9 @@ // Execute insert $this->Storage->insert($aInsert); } + + // Commit transaction + $this->Storage->commit(); } // -------------------------------------------------------------------- @@ -1846,6 +1894,9 @@ */ public function storeContentOnly($Node) { + // Begin transaction + $this->Storage->begin(); + // {{{ DEBUG }}} Logger::info( 'Storing content only for id #'.$Node->get('id').'. Other @@ -1866,6 +1917,9 @@ // Execute update $this->Storage->update($aUpdate); + + // Commit transaction + $this->Storage->commit(); } // -------------------------------------------------------------------- @@ -1886,10 +1940,17 @@ */ public function storeWithLazyChildren($Node, $bSaveParent = true) { + // Begin transaction + $this->Storage->begin(); + // If no real parent "root" is given, it can not be saved if ($bSaveParent) { // Save the parent node first if (!$this->store($Node)) { + + // Rollback transaction + $this->Storage->rollback(); + return false; } } @@ -1918,6 +1979,9 @@ $this->Storage->update($aUpdate); } + // Commit transaction + $this->Storage->commit(); + // Tell the observers that something has changed $this->notifyObservers(); @@ -1994,6 +2058,9 @@ // ---------------------------------------------------------------- + // Begin transaction + $this->Storage->begin(); + // Backup preparation $this->prepareBackup($Node); @@ -2011,6 +2078,9 @@ // Store prepared backup data (if any) to history $this->executeBackup($Node); + + // Commit transaction + $this->Storage->commit(); // Tell the observers that something has changed $this->notifyObservers(); File [changed]: class.CommentDAO.php Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/dao/class.CommentDAO.php?r1=1.12&r2=1.13 Delta lines: +27 -29 --------------------- --- class.CommentDAO.php 12 May 2005 19:43:04 -0000 1.12 +++ class.CommentDAO.php 12 May 2005 21:42:36 -0000 1.13 @@ -2,7 +2,7 @@ /** * - * $Id: class.CommentDAO.php,v 1.12 2005/05/12 19:43:04 dgorski Exp $ + * $Id: class.CommentDAO.php,v 1.13 2005/05/12 21:42:36 dgorski Exp $ * * This file is part of coWiki. coWiki is free software under the terms of * the GNU General Public License (GPL). Read the LICENSE file. If you did @@ -17,7 +17,7 @@ * @author Daniel T. Gorski, <[email protected]> * @copyright (C) Daniel T. Gorski, {@link http://www.develnet.org} * @license http://www.gnu.org/licenses/gpl.html - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * */ @@ -196,8 +196,7 @@ WHERE node_id = ".$Node->get('id'); $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); return (int)$aData['rec_count']; } @@ -224,8 +223,7 @@ AND lft = 1"; $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); return (int)$aData['rec_count']; } @@ -251,8 +249,7 @@ WHERE tree_id = ".$nId; $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); return (int)$aData['rec_count']; } @@ -295,8 +292,6 @@ $Coms->add($this->createComment($aData)); } - $this->Storage->freeResult($rResult); - return $Coms; } @@ -332,8 +327,7 @@ // Limit the query to required count $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); if (!$aData) { return null; @@ -396,8 +390,6 @@ $aNodes[$Com->get('level')-1]->addItem($Com); } - $this->Storage->freeResult($rResult); - return $aNodes[0]; } @@ -427,8 +419,7 @@ $sQuery = $this->Storage->addLimitToQuery($sQuery, 0, 1); $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); if ($aData) { return (int)$aData['comment_id']; @@ -463,8 +454,7 @@ $sQuery = $this->Storage->addLimitToQuery($sQuery, 0, 1); $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); if ($aData) { return (int)$aData['comment_id']; @@ -498,8 +488,7 @@ ORDER BY lft DESC"; $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); if ($aData) { return (int)$aData['comment_id']; @@ -532,8 +521,7 @@ ORDER BY lft ASC"; $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); if ($aData) { return (int)$aData['comment_id']; @@ -558,6 +546,10 @@ * @todo [D11N] Check the parameter type of "$Com" */ public function incrementViews($Com) { + + // Begin transaction + $this->Storage->begin(); + $Com->set('views', $Com->get('views') + 1); $aUpdate = array( @@ -568,6 +560,9 @@ // Execute update (terminates on error) $this->Storage->update($aUpdate); + + // Commit transaction + $this->Storage->commit(); } // -------------------------------------------------------------------- @@ -622,7 +617,7 @@ // ---------------------------------------------------------------- - // Check qoutation + // Check quotation $nCite = 1; $nNew = 1; @@ -690,7 +685,10 @@ $aFields['rec_mod_host'] = $this->Request->getRemoteHost(); } - #$this->Storage->beginTransaction($this->sComTable); + // --- + + // Begin transaction + $this->Storage->begin(); // Is this is an update or an initial insert? if ($ComItem->get('commentId')) { @@ -728,8 +726,7 @@ WHERE comment_id = ".(int)$nReplyToId; $rResult = $this->Storage->query($sQuery); - $aData = $this->Storage->fetchArray($rResult); - $this->Storage->freeResult($rResult); + $aData = $this->Storage->fetchArrayAndFreeResult($rResult); // First node in branch? if (!$aData) { @@ -786,12 +783,13 @@ 'where' => "comment_id = ".$aData['tree_id'] ); - // Execute update pn the root node + // Execute update on the root node $this->Storage->update($aUpdate); - // ---------------------------------------------------------------- + // Commit transaction + $this->Storage->commit(); -# $this->Storage->endTransaction($this->sComTable); + // ---------------------------------------------------------------- // Tell the observers that something has changed $this->notifyObservers();