本文整理汇总了PHP中Zend_Db_Adapter_Abstract::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Adapter_Abstract::beginTransaction方法的具体用法?PHP Zend_Db_Adapter_Abstract::beginTransaction怎么用?PHP Zend_Db_Adapter_Abstract::beginTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Adapter_Abstract
的用法示例。
在下文中一共展示了Zend_Db_Adapter_Abstract::beginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveRel
public function saveRel(Mage_Admin_Model_Permissions_Rules $rule)
{
$this->_write->beginTransaction();
try {
$roleId = $rule->getRoleId();
$this->_write->delete($this->_ruleTable, "role_id = {$roleId}");
$masterResources = Mage::getModel('admin/permissions_roles')->getResourcesList2D();
$masterAdmin = false;
if ($postedResources = $rule->getResources()) {
foreach ($masterResources as $index => $resName) {
if (!$masterAdmin) {
$permission = in_array($resName, $postedResources) ? 'allow' : 'deny';
$this->_write->insert($this->_ruleTable, array('role_type' => 'G', 'resource_id' => trim($resName, '/'), 'privileges' => '', 'assert_id' => 0, 'role_id' => $roleId, 'permission' => $permission));
}
if ($resName == 'all' && $permission == 'allow') {
$masterAdmin = true;
}
}
}
$this->_write->commit();
} catch (Mage_Core_Exception $e) {
throw $e;
} catch (Exception $e) {
$this->_write->rollBack();
}
}
示例2: setUp
/**
* (non-PHPdoc)
* @see ActiveSync/ActiveSync_TestCase::setUp()
*/
protected function setUp()
{
$this->_db = getTestDatabase();
$this->_db->beginTransaction();
$this->_deviceBackend = new Syncope_Backend_Device($this->_db);
$this->_folderBackend = new Syncope_Backend_Folder($this->_db);
$newDevice = Syncope_Backend_DeviceTests::getTestDevice();
$this->_device = $this->_deviceBackend->create($newDevice);
}
示例3: parseCsv
/**
* Parses csv file
*
* @param string $file
* @return Mage_Core_Model_Resource_Abstract
*/
public function parseCsv($file)
{
$info = pathinfo($file);
$io = new Varien_Io_File();
$io->open(array('path' => $info['dirname']));
$io->streamOpen($info['basename'], 'r');
$headers = $io->streamReadCsv();
if ($headers === false) {
$io->streamClose();
Mage::throwException(Mage::helper('pyro_licenses')->__('You must specify valid headers in the first row'));
}
if (false === ($columns = $this->_prepareColumns($headers))) {
$io->streamClose();
Mage::throwException(Mage::helper('pyro_licenses')->__("Invalid header: 'License' is missed"));
}
$this->_write->beginTransaction();
try {
$rowNumber = 1;
$importData = array();
while (false !== ($csvLine = $io->streamReadCsv())) {
$rowNumber++;
// check for empty lines
$emptyLine = array_unique($csvLine);
if (count($emptyLine) == 1 && $emptyLine[0] == "") {
continue;
}
$row = $this->_getImportRow($csvLine, $columns, $rowNumber);
if ($row !== false) {
$importData[] = $row;
}
if (count($importData) == 5000) {
$this->_saveImportData($importData);
$importData = array();
}
}
$this->_saveImportData($importData);
$io->streamClose();
} catch (Mage_Core_Exception $e) {
$this->_write->rollback();
$io->streamClose();
Mage::throwException($e->getMessage());
} catch (Exception $e) {
$this->_write->rollback();
$io->streamClose();
Mage::logException($e);
Mage::throwException(Mage::helper('adminhtml')->__($e->getMessage()));
}
$this->_write->commit();
if ($this->_importErrors) {
$error = sprintf('ImportSubscribers: "%1$s"', implode('", "', $this->_importErrors));
Mage::log($error, 3, '', true);
}
return $this;
}
示例4: setUp
/**
* (non-PHPdoc)
* @see ActiveSync/ActiveSync_TestCase::setUp()
*/
protected function setUp()
{
$this->_db = getTestDatabase();
$this->_db->beginTransaction();
$this->_contentBackend = new Syncope_Backend_Content($this->_db);
$this->_deviceBackend = new Syncope_Backend_Device($this->_db);
$this->_folderBackend = new Syncope_Backend_Folder($this->_db);
$this->_syncStateBackend = new Syncope_Backend_SyncState($this->_db);
$this->_device = $this->_deviceBackend->create(Syncope_Backend_DeviceTests::getTestDevice());
$this->_folder = $this->_folderBackend->create(Syncope_Backend_FolderTests::getTestFolder($this->_device));
}
示例5: delete
public function delete(Mage_Admin_Model_Permissions_Roles $role)
{
$this->_write->beginTransaction();
try {
$this->_write->delete($this->_roleTable, "role_id={$role->getId()}");
$this->_write->delete($this->_roleTable, "parent_id={$role->getId()}");
$this->_write->delete($this->_ruleTable, "role_id={$role->getId()}");
$this->_write->commit();
} catch (Mage_Core_Exception $e) {
throw $e;
} catch (Exception $e) {
$this->_write->rollBack();
}
}
示例6: aggregate
public function aggregate($object)
{
if (!$object->getEntityPkValue() && $object->getId()) {
$object->load($object->getReviewId());
}
$ratingModel = Mage::getModel('rating/rating');
$ratingSummaries = $ratingModel->getEntitySummary($object->getEntityPkValue(), false);
$nonDelete = array();
foreach ($ratingSummaries as $ratingSummaryObject) {
if ($ratingSummaryObject->getCount()) {
$ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount());
} else {
$ratingSummary = $ratingSummaryObject->getSum();
}
$reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId());
$select = $this->_read->select();
$select->from($this->_aggregateTable)->where("{$this->_aggregateTable}.entity_pk_value = ?", $object->getEntityPkValue())->where("{$this->_aggregateTable}.entity_type = ?", $object->getEntityId())->where("{$this->_aggregateTable}.store_id = ?", $ratingSummaryObject->getStoreId());
$oldData = $this->_read->fetchRow($select);
$data = new Varien_Object();
$data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId());
$this->_write->beginTransaction();
try {
if ($oldData['primary_id'] > 0) {
$condition = $this->_write->quoteInto("{$this->_aggregateTable}.primary_id = ?", $oldData['primary_id']);
$this->_write->update($this->_aggregateTable, $data->getData(), $condition);
} else {
$this->_write->insert($this->_aggregateTable, $data->getData());
}
$this->_write->commit();
} catch (Exception $e) {
$this->_write->rollBack();
}
}
}
示例7: move
/**
* Move tree node
*
* @param Varien_Data_Tree_Node $node
* @param Varien_Data_Tree_Node $parentNode
* @param Varien_Data_Tree_Node $prevNode
*/
public function move($category, $newParent, $prevNode = null)
{
$position = 1;
$oldPath = $category->getData($this->_pathField);
$newPath = $newParent->getData($this->_pathField);
$newPath = $newPath . '/' . $category->getId();
$oldPathLength = strlen($oldPath);
$data = array($this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))"));
$condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)");
$this->_conn->beginTransaction();
try {
if ($prevNode && $prevNode->getId()) {
$reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1"));
$reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}";
$this->_conn->update($this->_table, $reorderData, $reorderCondition);
$position = $prevNode->getData($this->_orderField) + 1;
}
$this->_conn->update($this->_table, $data, $condition);
$this->_conn->update($this->_table, array($this->_orderField => $position), $this->_conn->quoteInto("{$this->_idField} = ?", $category->getId()));
$this->_conn->commit();
} catch (Exception $e) {
$this->_conn->rollBack();
throw new Exception("Can't move tree node due to error: " . $e->getMessage());
}
}
示例8: move
/**
* Move tree node
*
* @todo Use adapter for generate conditions
* @param Varien_Data_Tree_Node $node
* @param Varien_Data_Tree_Node $newParent
* @param Varien_Data_Tree_Node $prevNode
*/
public function move($node, $newParent, $prevNode = null)
{
$position = 1;
$oldPath = $node->getData($this->_pathField);
$newPath = $newParent->getData($this->_pathField);
$newPath = $newPath . '/' . $node->getId();
$oldPathLength = strlen($oldPath);
$newLevel = $newParent->getLevel() + 1;
$levelDisposition = $newLevel - $node->getLevel();
$data = array($this->_levelField => new Zend_Db_Expr("{$this->_levelField} + '{$levelDisposition}'"), $this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))"));
$condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)");
$this->_conn->beginTransaction();
$reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1"));
try {
if ($prevNode && $prevNode->getId()) {
$reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}";
$position = $prevNode->getData($this->_orderField) + 1;
} else {
$reorderCondition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$newParent->getData($this->_pathField)}/[0-9]+\$");
$select = $this->_conn->select()->from($this->_table, new Zend_Db_Expr("MIN({$this->_orderField})"))->where($reorderCondition);
$position = (int) $this->_conn->fetchOne($select);
}
$this->_conn->update($this->_table, $reorderData, $reorderCondition);
$this->_conn->update($this->_table, $data, $condition);
$this->_conn->update($this->_table, array($this->_orderField => $position, $this->_levelField => $newLevel), $this->_conn->quoteInto("{$this->_idField} = ?", $node->getId()));
$this->_conn->commit();
} catch (Exception $e) {
$this->_conn->rollBack();
throw new Exception("Can't move tree node due to error: " . $e->getMessage());
}
}
示例9: addNewTokens
/**
* Creates all tokens that should exist, but do not exist
*
* NOTE: When overruling this function you should not create tokens because they
* were deleted by the user
*
* @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check
* @param int $userId Id of the user who takes the action (for logging)
* @return int The number of tokens created by this code
*/
protected function addNewTokens(\Gems_Tracker_RespondentTrack $respTrack, $userId)
{
$orgId = $respTrack->getOrganizationId();
$respId = $respTrack->getRespondentId();
$respTrackId = $respTrack->getRespondentTrackId();
// $this->t
$sql = "SELECT gro_id_round, gro_id_survey, gro_id_order, gro_icon_file, gro_round_description\n FROM gems__rounds\n WHERE gro_id_track = ? AND\n gro_active = 1 AND\n gro_id_round NOT IN (SELECT gto_id_round FROM gems__tokens WHERE gto_id_respondent_track = ?) AND\n (gro_organizations IS NULL OR gro_organizations LIKE CONCAT('%|',?,'|%'))\n ORDER BY gro_id_order";
$newRounds = $this->db->fetchAll($sql, array($this->_trackId, $respTrackId, $orgId));
$this->db->beginTransaction();
foreach ($newRounds as $round) {
$values = array();
// From the respondent track
$values['gto_id_respondent_track'] = $respTrackId;
$values['gto_id_respondent'] = $respId;
$values['gto_id_organization'] = $orgId;
$values['gto_id_track'] = $this->_trackId;
// From the rounds
$values['gto_id_round'] = $round['gro_id_round'];
$values['gto_id_survey'] = $round['gro_id_survey'];
$values['gto_round_order'] = $round['gro_id_order'];
$values['gto_icon_file'] = $round['gro_icon_file'];
$values['gto_round_description'] = $round['gro_round_description'];
// All other values are not changed by this query and get the default DB value on insertion
$this->tracker->createToken($values, $userId);
}
$this->db->commit();
return count($newRounds);
}
示例10: moveNodes
/**
* @param string|int $eId
* @param string|int $pId
* @param string|int $aId
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function moveNodes($eId, $pId, $aId = 0)
{
$eInfo = $this->getNodeInfo($eId);
if ($pId != 0) {
$pInfo = $this->getNodeInfo($pId);
}
if ($aId != 0) {
$aInfo = $this->getNodeInfo($aId);
}
$level = $eInfo[$this->_level];
$leftKey = $eInfo[$this->_left];
$rightKey = $eInfo[$this->_right];
if ($pId == 0) {
$levelUp = 0;
} else {
$levelUp = $pInfo[$this->_level];
}
$rightKeyNear = 0;
$leftKeyNear = 0;
if ($pId == 0) {
//move to root
$rightKeyNear = $this->_db->fetchOne('SELECT MAX(' . $this->_right . ') FROM ' . $this->_table);
} elseif ($aId != 0 && $pId == $eInfo[$this->_pid]) {
// if we have after ID
$rightKeyNear = $aInfo[$this->_right];
$leftKeyNear = $aInfo[$this->_left];
} elseif ($aId == 0 && $pId == $eInfo[$this->_pid]) {
// if we do not have after ID
$rightKeyNear = $pInfo[$this->_left];
} elseif ($pId != $eInfo[$this->_pid]) {
$rightKeyNear = $pInfo[$this->_right] - 1;
}
$skewLevel = $pInfo[$this->_level] - $eInfo[$this->_level] + 1;
$skewTree = $eInfo[$this->_right] - $eInfo[$this->_left] + 1;
echo "alert('" . $rightKeyNear . "');";
if ($rightKeyNear > $rightKey) {
// up
echo "alert('move up');";
$skewEdit = $rightKeyNear - $leftKey + 1;
$sql = 'UPDATE ' . $this->_table . ' SET ' . $this->_right . ' = IF(' . $this->_left . ' >= ' . $eInfo[$this->_left] . ', ' . $this->_right . ' + ' . $skewEdit . ', IF(' . $this->_right . ' < ' . $eInfo[$this->_left] . ', ' . $this->_right . ' + ' . $skewTree . ', ' . $this->_right . ')), ' . $this->_level . ' = IF(' . $this->_left . ' >= ' . $eInfo[$this->_left] . ', ' . $this->_level . ' + ' . $skewLevel . ', ' . $this->_level . '), ' . $this->_left . ' = IF(' . $this->_left . ' >= ' . $eInfo[$this->_left] . ', ' . $this->_left . ' + ' . $skewEdit . ', IF(' . $this->_left . ' > ' . $rightKeyNear . ', ' . $this->_left . ' + ' . $skewTree . ', ' . $this->_left . '))' . ' WHERE ' . $this->_right . ' > ' . $rightKeyNear . ' AND ' . $this->_left . ' < ' . $eInfo[$this->_right];
} elseif ($rightKeyNear < $rightKey) {
// down
echo "alert('move down');";
$skewEdit = $rightKeyNear - $leftKey + 1 - $skewTree;
$sql = 'UPDATE ' . $this->_table . ' SET ' . $this->_left . ' = IF(' . $this->_right . ' <= ' . $rightKey . ', ' . $this->_left . ' + ' . $skewEdit . ', IF(' . $this->_left . ' > ' . $rightKey . ', ' . $this->_left . ' - ' . $skewTree . ', ' . $this->_left . ')), ' . $this->_level . ' = IF(' . $this->_right . ' <= ' . $rightKey . ', ' . $this->_level . ' + ' . $skewLevel . ', ' . $this->_level . '), ' . $this->_right . ' = IF(' . $this->_right . ' <= ' . $rightKey . ', ' . $this->_right . ' + ' . $skewEdit . ', IF(' . $this->_right . ' <= ' . $rightKeyNear . ', ' . $this->_right . ' - ' . $skewTree . ', ' . $this->_right . '))' . ' WHERE ' . $this->_right . ' > ' . $leftKey . ' AND ' . $this->_left . ' <= ' . $rightKeyNear;
}
$this->_db->beginTransaction();
try {
$this->_db->query($sql);
$this->_db->commit();
} catch (\Exception $e) {
$this->_db->rollBack();
echo $e->getMessage();
echo "<br>\r\n";
echo $sql;
echo "<br>\r\n";
exit;
}
echo "alert('node added')";
}
示例11: store
protected function store()
{
$fileTable = IcingaConfigFile::$table;
$fileKey = IcingaConfigFile::$keyName;
$this->db->beginTransaction();
try {
$existingQuery = $this->db->select()->from($fileTable, 'checksum')->where('checksum IN (?)', array_map(array($this, 'dbBin'), $this->getFilesChecksums()));
$existing = $this->db->fetchCol($existingQuery);
foreach ($existing as $key => $val) {
if (is_resource($val)) {
$existing[$key] = stream_get_contents($val);
}
}
$missing = array_diff($this->getFilesChecksums(), $existing);
/** @var IcingaConfigFile $file */
foreach ($this->files as $name => $file) {
$checksum = $file->getChecksum();
if (!in_array($checksum, $missing)) {
continue;
}
$this->db->insert($fileTable, array($fileKey => $this->dbBin($checksum), 'content' => $file->getContent()));
}
$this->db->insert(self::$table, array('duration' => $this->generationTime, 'last_activity_checksum' => $this->dbBin($this->getLastActivityChecksum()), 'checksum' => $this->dbBin($this->getChecksum())));
/** @var IcingaConfigFile $file */
foreach ($this->files as $name => $file) {
$this->db->insert('director_generated_config_file', array('config_checksum' => $this->dbBin($this->getChecksum()), 'file_checksum' => $this->dbBin($file->getChecksum()), 'file_path' => $name));
}
$this->db->commit();
} catch (Exception $e) {
$this->db->rollBack();
throw $e;
var_dump($e->getMessage());
}
return $this;
}
示例12: beginTransaction
/**
* Start a transaction and track how many
* are in progress
*
*/
public function beginTransaction()
{
if ($this->transactionDepth <= 0) {
$this->transactionDepth = 0;
$this->proxied->beginTransaction();
}
$this->transactionDepth++;
$this->log->debug("BEGIN: Transaction depth of {$this->transactionDepth}");
}
示例13: isTransactionRunning
/**
* Checks if another transaction is running or not
*
* @param Zend_Db_Adapter_Abstract $dba
* @return boolean True if another transaction is in progress, false otherwise
*/
public static function isTransactionRunning(Zend_Db_Adapter_Abstract $dba)
{
try {
$dba->beginTransaction();
} catch (Exception $e) {
return true;
}
$dba->rollBack();
return false;
}
示例14: startTransaction
/**
* Start a transaction (either using QFrame transactions or straight db transactions)
*
* @param Migration migration we are currently running
* @return mixed
*/
private final function startTransaction(Migration $migration)
{
if (class_exists('QFrame_Db_SerializableTransaction')) {
$result = QFrame_Db_SerializableTransaction::startSerializableTransaction();
} else {
$result = $this->dbAdapter->beginTransaction();
}
if (!$result) {
throw new Exception('Could not begin a transaction for migration ' . get_class($migration));
}
return $result;
}
示例15: received
/**
* Updates data when subscriber received
*
* @param \Magento\Newsletter\Model\Subscriber $subscriber
* @param \Magento\Newsletter\Model\Queue $queue
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
public function received(\Magento\Newsletter\Model\Subscriber $subscriber, \Magento\Newsletter\Model\Queue $queue)
{
$this->_write->beginTransaction();
try {
$data['letter_sent_at'] = $this->_date->gmtDate();
$this->_write->update($this->_subscriberLinkTable, $data, array('subscriber_id = ?' => $subscriber->getId(), 'queue_id = ?' => $queue->getId()));
$this->_write->commit();
} catch (\Exception $e) {
$this->_write->rollBack();
throw new \Magento\Framework\Model\Exception(__('We cannot mark as received subscriber.'));
}
return $this;
}