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(); } }
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(); } }
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(); } } }
/** * 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()); } }
/** * 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); }
/** * @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')"; }
/** * 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()); } }
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; }
/** * Commit a transaction (see comment above) * * @param mixed transaction identifier (whatever was passed back from startTransaction()) * @param Migration migration that is currently running */ private final function commitTransaction($transaction, Migration $migration) { if (class_exists('QFrame_Db_SerializableTransaction')) { $result = QFrame_Db_SerializableTransaction::dbCommit($transaction); } else { if (!$this->dbAdapter->commit()) { throw new Exception('Could not commit transaction for migration ' . get_class($migration)); } } }
/** * Decrement the transaction count. If at 0, * we can commit; * */ public function commit() { $this->transactionDepth--; $this->log->debug("COMMIT: Transaction depth of {$this->transactionDepth}"); if (!$this->transactionDepth) { $this->proxied->commit(); } if ($this->transactionDepth < 0) { $this->transactionDepth = 0; } }
/** * 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; }
/** * Updates data when subscriber received * * @param Mage_Newsletter_Model_Subscriber $subscriber * @param Mage_Newsletter_Model_Queue $queue * @return Mage_Newsletter_Model_Resource_Subscriber */ public function received(Mage_Newsletter_Model_Subscriber $subscriber, Mage_Newsletter_Model_Queue $queue) { $this->_write->beginTransaction(); try { $data['letter_sent_at'] = Mage::getSingleton('Mage_Core_Model_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(); Mage::throwException(Mage::helper('Mage_Newsletter_Helper_Data')->__('Cannot mark as received subscriber.')); } return $this; }
public function received(Mage_Newsletter_Model_Subscriber $subscriber, Mage_Newsletter_Model_Queue $queue) { $this->_write->beginTransaction(); try { $data['letter_sent_at'] = now(); $this->_write->update($this->_subscriberLinkTable, $data, array($this->_write->quoteInto('subscriber_id=?', $subscriber->getId()), $this->_write->quoteInto('queue_id=?', $queue->getId()))); $this->_write->commit(); } catch (Exception $e) { $this->_write->rollBack(); Mage::throwException(Mage::helper('newsletter')->__('Cannot mark as received subscriber')); } return $this; }
/** * 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; }
/** * @param Node $node * @return $this * @throws \Exception */ public function removeNode($node) { // For reorder old node branch $dataReorderOld = [$this->_orderField => new \Zend_Db_Expr($this->_conn->quoteIdentifier($this->_orderField) . '-1')]; $conditionReorderOld = $this->_conn->quoteIdentifier($this->_parentField) . '=' . $node->getData($this->_parentField) . ' AND ' . $this->_conn->quoteIdentifier($this->_orderField) . '>' . $node->getData($this->_orderField); $this->_conn->beginTransaction(); try { $condition = $this->_conn->quoteInto("{$this->_idField}=?", $node->getId()); $this->_conn->delete($this->_table, $condition); // Update old node branch $this->_conn->update($this->_table, $dataReorderOld, $conditionReorderOld); $this->_conn->commit(); } catch (\Exception $e) { $this->_conn->rollBack(); throw new \Exception('Can\'t remove tree node'); } parent::removeNode($node); return $this; }
/** * Check this respondent track for changes to the tokens * * @param int $userId Id of the user who takes the action (for logging) * @param \Gems_Tracker_Token $fromToken Optional token to start from * @param \Gems_Tracker_Token $skipToken Optional token to skip in the recalculation when $fromToken is used * @return int The number of tokens changed by this code */ public function checkTrackTokens($userId, \Gems_Tracker_Token $fromToken = null, \Gems_Tracker_Token $skipToken = null) { // Execute any defined functions $count = $this->handleTrackCalculation($userId); // Update token completion count. $this->_checkTrackCount($userId); $engine = $this->getTrackEngine(); $this->db->beginTransaction(); // Check for validFrom and validUntil dates that have changed. if ($fromToken) { $count += $engine->checkTokensFrom($this, $fromToken, $userId, $skipToken); } elseif ($this->_checkStart) { $count += $engine->checkTokensFrom($this, $this->_checkStart, $userId); } else { $count += $engine->checkTokensFromStart($this, $userId); } $this->db->commit(); return $count; }
/** * Drop database tables. * * @param Zend_Db_Adapter_Abstract $db * @param string $dbType * @throws Zend_Exception */ function dropTables($db, $dbType) { $db->beginTransaction(); try { $tables = $db->listTables(); foreach ($tables as $table) { if ($dbType === 'mysql') { $db->query('DROP TABLE IF EXISTS `' . $table . '` CASCADE;'); } elseif ($dbType === 'pgsql') { $db->query('DROP TABLE IF EXISTS "' . $table . '" CASCADE;'); } elseif ($dbType === 'sqlite' && $table != 'sqlite_sequence') { $db->query('DROP TABLE IF EXISTS "' . $table . '";'); } else { continue; } } $db->commit(); } catch (Zend_Exception $exception) { $db->rollBack(); throw $exception; } }
/** * Commit a transaction and return to autocommit mode. * * @return Zend_Db_Adapter_Abstract */ public function commit() { return $this->_adapter->commit(); }
/** * */ public function commit() { $this->db->commit(); }
protected function install(Zend_Db_Adapter_Abstract $db) { $config = Zend_Registry::get('config'); $path = $config->system->path; $schema = file_get_contents($path->base . "/modules/default/installer/schema.sql"); $system_data = file_get_contents($path->base . "/modules/default/installer/system_data.sql"); $cnl_data = file_get_contents($path->base . "/modules/default/installer/cnl_data.sql"); $db->beginTransaction(); try { $db->query($schema); $db->query($system_data); $db->query($cnl_data); $db->commit(); } catch (Exception $ex) { $db->rollBack(); throw $ex; } }
public function commit() { $this->_connection->commit(); }
public function commitTransaction() { $this->_read->commit(); }