Transactions in PHP

I know that EZPDO supports transactions, but when I try to use them I receive the following error:

 
Exception
Description

Object Company does not contains variable
Source File

/Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObjectUtil.php (227)

0216:             } else {
0217:                 throw new Exception('Unable to get variable details of '.$aVarName.' without variables');
0218:             }
0219:         }
0220:         $lVarNameSearch = strtolower($aVarName);
0221:         foreach ($aVariables as $lVarName => $lDetails) {
0222:             $lVarName = strtolower($lVarName);
0223:             if ($lVarNameSearch == $lVarName) {
0224:                 return $lDetails;
0225:             }
0226:         }
0227: throw new Exception('Object '.get_class($aObject).' does not contains variable '.$aVarName);
0228:     }
0229: 
0230:     protected function &getVariableName(&$aObject, &$aVariables, &$aVarName, &$aAutoCreate = false) {
0231:         $lDetails = $this->getVariableDetails($aObject, $aVariables, $aVarName, $aAutoCreate);
0232:         $lVarName = $lDetails['NAME'];
0233:         if (is_null($lVarName)) {
0234:             return $aVarName;
0235:         }
0236:         return $lVarName;
0237:     }
0238: 
0239:     protected function debugVariable(&$aObject, &$aVariables) {


Stack Trace

#0 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObjectUtil.php(174): epObjectUtil->getVariableDetails(Object(Company), Array, NULL, true)
#1 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php(3036): epObjectUtil->getByGetter(Object(Company), Array, NULL, true)
#2 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php(2998): epObject->_reduceRelationshipVar('user')
#3 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php(2866): epObject->_backupObjectVars()
#4 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epTransaction.php(83): epObject->epStartTransaction()
#5 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epManager.php(2099): epTransaction->addObject(Object(epObject), Object(epDbObject))
#6 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epManager.php(743): epManagerBase->addObject_t(Object(epObject))
#7 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/classes/CompanyFactory.php(5): epManagerBase->create('Company')
#8 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/Controllers/NewAccountController.php(41): CompanyFactory::loadCompanyByORMID('PTS')
#9 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/UI/Pages/CreateNewAccount.php(36): NewAccountController->createAccount(Object(UserRegistrationDTO))
#10 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/TComponent.php(374): CreateNewAccount->onCompleteRegistration(Object(TWizard), Object(TWizardNavigationEventParameter))
#11 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/WebControls/TWizard.php(686): TComponent->raiseEvent('OnCompleteButto...', Object(TWizard), Object(TWizardNavigationEventParameter))
#12 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/WebControls/TWizard.php(1388): TWizard->onCompleteButtonClick(Object(TWizardNavigationEventParameter))
#13 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TControl.php(1430): TWizard->bubbleEvent(Object(TButton), Object(TCommandEventParameter))
#14 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/WebControls/TButton.php(205): TControl->raiseBubbleEvent(Object(TButton), Object(TCommandEventParameter))
#15 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/WebControls/TButton.php(222): TButton->onCommand(Object(TCommandEventParameter))
#16 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TPage.php(909): TButton->raisePostBackEvent('undefined')
#17 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TPage.php(255): TPage->raisePostBackEvent()
#18 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TPage.php(190): TPage->processPostBackRequest(Object(THtmlWriter))
#19 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/Services/TPageService.php(474): TPage->run(Object(THtmlWriter))
#20 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/Services/TPageService.php(420): TPageService->runPage(Object(CreateNewAccount), Array)
#21 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/TApplication.php(1066): TPageService->run()
#22 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/TApplication.php(376): TApplication->runService()
#23 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/index.php(16): TApplication->run()
#24 {main}


 

My application code looks like this:

 
epManager::instance()->start_t();
		$company = CompanyFactory::loadCompanyByORMID($accountDto->companyName);
		
		if ( !is_null($company) )
			throw new DuplicateObjectException("Specified company already exists.");
		
		$company = CompanyFactory::createCompany();
			
		$user = new User();
		$user = UserFactory::createUser();
		$user->setLoginId($accountDto->userName);
		$user->setEmail($accountDto->emailAddress);
		$user->setLanguage($accountDto->language);
		$user->setTimezone($accountDto->timeZone);
		$user->setPassword($accountDto->password);
		
		$company->setName($accountDto->companyName);
		$company->user[] = $user;
		$company->save();
		
		try {
			epManager::instance()->commit_t(false);
		}
		catch (Exception $e)
		{
			throw new PersistenceLayerException("Could not store account details.");
		}
 

If I comment out the transaction parts, everything works fine but with them I get the error above. I tried upgrading the EZPDO library by hand but that introduced new issues. Is there any way to get transaction support? WIthout it I really can’t use DB_VA for anything more important than a small personal project.

Hi rbegga,

Sorry about the problem. It has been fixed. Please download at:
http://files3.visual-paradigm.com/200711/Patch/sp1_20071119f/VP_Suite_Windows_3_1_sp1_20071119f.exe

Please run it and overwrite the existing installation.

Best regards,
Jick

Jick,

Thanks for your quick response, that was awesome!!! The only issue is I forgot to mention that I am using the Mac version of DBVA. Is there any way I can get a patch for the Mac?

Thanks again for your help,

-TJ

Hi rbegga,

Please try this:
http://files3.visual-paradigm.com/200711/Patch/sp1_20071119f/VP_Suite_MacOSX_3_1_sp1_20071119f.dmg

Best regards,
Jick

Jick,

The patch allowed me to call the EZPDO transaction functions, however when I try to rollback a transaction I get the following error:

 TPhpErrorException
Description

[Warning] Invalid argument supplied for foreach() (@line 2977 in file /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php).
Source File

/Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php (2977)

2966:         }
2967:         return $backup;
2968:     }
2969: 
2970:     /**
2971:      * Restore the wrapper vars
2972:      * @param array $backup
2973:      * @return void
2974:      */
2975:     protected function _restoreWrapperVars($backup) {
2976:         // set vars back to wrapper
2977: foreach($backup as $var => $value) {
2978:             $this->$var = $value;
2979:         }
2980:     }
2981: 
2982:     /**
2983:      * Backup the object vars
2984:      * @return array 
2985:      */
2986:     protected function _backupObjectVars() {
2987:         $backup = array();
2988:         foreach($this->ep_cached_vars as $var => $lDetails) {
2989:         // foreach($this->ep_cached_vars as $var) {


Stack Trace

#0 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php(2977): PradoBase::phpErrorHandler(2, 'Invalid argumen...', '/Applications/x...', 2977, Array)
#1 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epObject.php(2886): epObject->_restoreWrapperVars(NULL)
#2 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epTransaction.php(131): epObject->epEndTransaction(true)
#3 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/ORM/lib/phporm/src/runtime/epManager.php(2063): epTransaction->rollbackObjects()
#4 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/Core/Controllers/NewAccountController.php(81): epManagerBase->rollback_t()
#5 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/protected/UI/Pages/CreateNewAccount.php(75): NewAccountController->createAccount(Object(UserRegistrationDTO))
#6 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/TComponent.php(374): CreateNewAccount->onCompleteRegistration(Object(TButton), NULL)
#7 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/WebControls/TButton.php(192): TComponent->raiseEvent('OnClick', Object(TButton), NULL)
#8 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/WebControls/TButton.php(221): TButton->onClick(NULL)
#9 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TPage.php(909): TButton->raisePostBackEvent('undefined')
#10 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TPage.php(255): TPage->raisePostBackEvent()
#11 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/UI/TPage.php(190): TPage->processPostBackRequest(Object(THtmlWriter))
#12 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/Services/TPageService.php(474): TPage->run(Object(THtmlWriter))
#13 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/Web/Services/TPageService.php(420): TPageService->runPage(Object(CreateNewAccount), Array)
#14 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/TApplication.php(1066): TPageService->run()
#15 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/framework/TApplication.php(376): TApplication->runService()
#16 /Applications/xampp/xamppfiles/htdocs/jobinizer/trunk/app/index.php(16): TApplication->run()
#17 {main}

2007-11-15 23:39 Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.8e DAV/2 PHP/5.2.4 PRADO/3.1.1
 

Not sure what the issue might be…

Hi rbegga,

We are unable to repeat your problem. Please provide us with more detail. E.g.:

  • Generated *.php
  • .vpp file
  • Other .php files related to the problem.

Best regards,
Jick

Jick,

I think the error message itself might have been something on my end, however it seems like transactions still aren’t working like they should. I have attached a complete example .VPP file as well as my own CreateData demo php file.

Basically the issue is that if you run the CreateJobinizerData.php file once, the records are created properly for the test data objects. The second time you run it, an exception occurs because you are inserting duplicate data in the database, which is correct. The problem is the state of the database after the exception: records for the objects that had no exception while saving are still being created, which is incorrect because if any part of the transaction fails, then entire thing should be rolled back, and it doesn’t seem to be doing that for me.

Hi rbegga,

Thank you for the files. We’ll check the problems and come back to you as soon as we can.

Best regards,
Jick