Пример #1
0
 /**
  * Rollback transaction
  * @throws TipyDaoException if there is no transaction in progress
  * @return mysqli_result
  */
 private static function rollbackTransaction($kind = 'soft')
 {
     $app = TipyApp::getInstance();
     if (self::$openTransactionsCount == 0) {
         throw new TipyDaoException('No transaction in progress');
     } elseif ($kind == 'hard') {
         // rollback parent transaction with all nested savepoints
         $app->logger->debug('ROLLBACK');
         $result = $app->db->query('ROLLBACK');
         if ($result) {
             self::$openTransactionsCount = 0;
         }
     } elseif (self::$openTransactionsCount == 1) {
         $app->logger->debug('ROLLBACK');
         $result = $app->db->query('ROLLBACK');
         if ($result) {
             self::$openTransactionsCount = 0;
         }
     } elseif (self::$openTransactionsCount > 1) {
         $app->logger->debug('ROLLBACK TO SAVEPOINT ' . self::currentSavepointName());
         $result = $app->db->query('ROLLBACK TO SAVEPOINT ' . self::currentSavepointName());
         if ($result) {
             self::$openTransactionsCount--;
         }
     } else {
         // Just to be sure
         throw new TipyDaoException('Negative open transactions counter. Please contact tipy maintainers');
     }
     return $result;
 }