コード例 #1
0
 protected function _construct()
 {
     $this->_init('cleaner/magentoDatabase');
     $this->coreResource = Mage::getSingleton('core/resource');
     $this->dbRead = $this->coreResource->getConnection('core_read');
     $this->dbWrite = $this->coreResource->getConnection('core_write');
     $this->tables = $this->getTables();
 }
コード例 #2
0
 public function __construct($name = null, array $data = [], $dataName = '')
 {
     parent::__construct($name, $data, $dataName);
     $this->_manObj = ObjectManager::getInstance();
     $this->_logger = $this->_manObj->get(\Psr\Log\LoggerInterface::class);
     $this->_resource = $this->_manObj->get(\Magento\Framework\App\ResourceConnection::class);
     $this->_conn = $this->_resource->getConnection();
     $this->_toolPeriod = $this->_manObj->get(IPeriod::class);
     /* base services */
     $this->_callDownlineCustomer = $this->_manObj->get(\Praxigento\Downline\Service\ICustomer::class);
     $this->_callDownlineSnap = $this->_manObj->get(\Praxigento\Downline\Service\ISnap::class);
     /* set up application */
     $this->_setAreaCode();
 }
コード例 #3
0
ファイル: ResourceTest.php プロジェクト: natxetee/magento2
 /**
  * Init profiler during creation of DB connect
  */
 public function testProfilerInit()
 {
     $connReadConfig = Mage::getConfig()->getResourceConnectionConfig('core_read');
     $profilerConfig = $connReadConfig->addChild('profiler');
     $profilerConfig->addChild('class', 'Mage_Core_Model_Resource_Db_Profiler');
     $profilerConfig->addChild('enabled', 'true');
     /** @var Zend_Db_Adapter_Abstract $connection */
     $connection = $this->_model->getConnection('core_read');
     /** @var Mage_Core_Model_Resource_Db_Profiler $profiler */
     $profiler = $connection->getProfiler();
     $this->assertInstanceOf('Mage_Core_Model_Resource_Db_Profiler', $profiler);
     $this->assertTrue($profiler->getEnabled());
     $this->assertAttributeEquals((string) $connReadConfig->host, '_host', $profiler);
     $this->assertAttributeEquals((string) $connReadConfig->type, '_type', $profiler);
 }
コード例 #4
0
ファイル: Resource.php プロジェクト: AleksNesh/pandora
 /**
  * Creates a connection to resource whenever needed
  *
  * @param  string $name
  * @return Varien_Db_Adapter_Interface
  */
 public function getConnection($name)
 {
     $connection = parent::getConnection($name);
     /*
      * Make sure the profiler is enabled for all requests
      */
     $connection->getProfiler()->setEnabled(true);
     return $connection;
 }
コード例 #5
0
 /**
  * Constructor for class instance
  *
  * @param Enterprise_Mview_Model_Event $eventModel
  * @param Varien_Db_Adapter_Interface  $connection
  * @param Mage_Core_Model_Resource     $resource
  */
 public function __construct($eventModel = null, $connection = null, $resource = null)
 {
     if ($resource instanceof Mage_Core_Model_Resource) {
         $this->_resource = $resource;
     } else {
         $this->_resource = Mage::getSingleton('core/resource');
     }
     if ($eventModel instanceof Mage_Core_Model_Abstract) {
         $this->_eventModel = $eventModel;
     } else {
         $this->_eventModel = Mage::getModel('enterprise_mview/event');
     }
     if ($connection instanceof Varien_Db_Adapter_Interface) {
         $this->_connection = $connection;
     } else {
         $this->_connection = $this->_resource->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
     }
 }
コード例 #6
0
ファイル: Mysql4.php プロジェクト: nemphys/magento2
 /**
  * Clean database
  *
  * @param SimpleXMLElement $config
  * @return Mage_Install_Model_Installer_Db_Abstract
  */
 public function cleanUpDatabase(SimpleXMLElement $config)
 {
     $resourceModel = new Mage_Core_Model_Resource();
     $connection = $resourceModel->getConnection(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE);
     $dbName = $config->dbname;
     $connection->query('DROP DATABASE IF EXISTS ' . $dbName);
     $connection->query('CREATE DATABASE ' . $dbName);
     return $this;
 }
コード例 #7
0
 /**
  * Constructor
  *
  * @param array $args
  */
 public function __construct(array $args = array())
 {
     $this->_resource = isset($args['resource']) ? $args['resource'] : Mage::getSingleton('core/resource');
     $this->_connection = isset($args['connection']) ? $args['connection'] : $this->_resource->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
     $this->_config = isset($args['config']) ? $args['config'] : Mage::getConfig();
     $this->_categoryModel = isset($args['categoryModel']) ? $args['categoryModel'] : Mage::getModel('catalog/category');
     $this->_productHelper = isset($args['productHelper']) ? $args['productHelper'] : Mage::helper('catalog/product');
     $this->_categoryHelper = isset($args['categoryHelper']) ? $args['categoryHelper'] : Mage::helper('catalog/category');
     $this->_app = isset($args['app']) ? $args['app'] : Mage::app();
 }
コード例 #8
0
ファイル: Resource.php プロジェクト: nhp/Xtest
 /**
  * Creates a connection to resource whenever needed
  *
  * @param string $name
  * @return Varien_Db_Adapter_Interface
  */
 public function getConnection($name)
 {
     if (defined('XTEST_BOOTSTRAPPED')) {
         static $connection;
         if (!$connection) {
             $connection = parent::getConnection('core_write');
         }
         return $connection;
     }
     return parent::getConnection('default_setup');
 }
コード例 #9
0
ファイル: Abstract.php プロジェクト: okite11/frames21
 /**
  * Get connection by name or type
  *
  * @param string $connectionName
  * @return Zend_Db_Adapter_Abstract
  */
 protected function _getConnection($connectionName)
 {
     if (isset($this->_connections[$connectionName])) {
         return $this->_connections[$connectionName];
     }
     if (!empty($this->_resourcePrefix)) {
         $this->_connections[$connectionName] = $this->_resources->getConnection($this->_resourcePrefix . '_' . $connectionName);
     } else {
         $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName);
     }
     return $this->_connections[$connectionName];
 }
コード例 #10
0
 public function getEstado($id)
 {
     $resource = new Mage_Core_Model_Resource();
     $read = $resource->getConnection("core_read");
     $select = $read->select()->from('directory_country_region')->where('region_id = ?', $id);
     $r = $read->fetchAll($select);
     if (array_key_exists(0, $r)) {
         $estado = $r[0];
         if (array_key_exists('default_name', $estado)) {
             return $estado['default_name'];
         }
     }
 }
コード例 #11
0
ファイル: Abstract.php プロジェクト: nemphys/magento2
 /**
  * Get connection by name or type
  *
  * @param string $connectionName
  * @return Varien_Db_Adapter_Interface|bool
  */
 protected function _getConnection($connectionName)
 {
     if (isset($this->_connections[$connectionName])) {
         return $this->_connections[$connectionName];
     }
     $connectionNameFull = ($this->_resourcePrefix ? $this->_resourcePrefix . '_' : '') . $connectionName;
     $connectionInstance = $this->_resources->getConnection($connectionNameFull);
     // cache only active connections to detect inactive ones as soon as they become active
     if ($connectionInstance) {
         $this->_connections[$connectionName] = $connectionInstance;
     }
     return $connectionInstance;
 }
コード例 #12
0
ファイル: Rule.php プロジェクト: nemphys/magento2
 /**
  * Populate ACL with rules from external storage
  *
  * @param Magento_Acl $acl
  */
 public function populateAcl(Magento_Acl $acl)
 {
     $ruleTable = $this->_resource->getTableName("admin_rule");
     $adapter = $this->_resource->getConnection('read');
     $select = $adapter->select()->from(array('r' => $ruleTable));
     $rulesArr = $adapter->fetchAll($select);
     foreach ($rulesArr as $rule) {
         $role = $rule['role_type'] . $rule['role_id'];
         $resource = $rule['resource_id'];
         $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;
         if ($rule['permission'] == 'allow') {
             if ($resource === Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL) {
                 $acl->allow($role, null, $privileges);
             }
             $acl->allow($role, $resource, $privileges);
         } else {
             if ($rule['permission'] == 'deny') {
                 $acl->deny($role, $resource, $privileges);
             }
         }
     }
 }
コード例 #13
0
 /**
  * Populate ACL with roles from external storage
  *
  * @param Magento_Acl $acl
  */
 public function populateAcl(Magento_Acl $acl)
 {
     $roleTableName = $this->_resource->getTableName('admin_role');
     $adapter = $this->_resource->getConnection('read');
     $select = $adapter->select()->from($roleTableName)->order('tree_level');
     foreach ($adapter->fetchAll($select) as $role) {
         $parent = $role['parent_id'] > 0 ? Mage_User_Model_Acl_Role_Group::ROLE_TYPE . $role['parent_id'] : null;
         switch ($role['role_type']) {
             case Mage_User_Model_Acl_Role_Group::ROLE_TYPE:
                 $roleId = $role['role_type'] . $role['role_id'];
                 $acl->addRole($this->_objectFactory->getModelInstance('Mage_User_Model_Acl_Role_Group', array('roleId' => $roleId)), $parent);
                 break;
             case Mage_User_Model_Acl_Role_User::ROLE_TYPE:
                 $roleId = $role['role_type'] . $role['user_id'];
                 if (!$acl->hasRole($roleId)) {
                     $acl->addRole($this->_objectFactory->getModelInstance('Mage_User_Model_Acl_Role_User', array('roleId' => $roleId)), $parent);
                 } else {
                     $acl->addRoleParent($roleId, $parent);
                 }
                 break;
         }
     }
 }
コード例 #14
0
 public function deleteAction()
 {
     $post = $this->getRequest()->getParams();
     $id = $post["id"];
     $resource = new Mage_Core_Model_Resource();
     $write = $resource->getConnection('core_write');
     try {
         $write->delete("motoboyconfig", $write->quoteInto("id=?", $id));
         $this->_redirect('*/*/rangecep');
         Mage::getSingleton('adminhtml/session')->addSuccess('Faixa de CEP deletada com sucesso!');
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError('Erro ao deletar Faixa de CEP, contate o suporte!');
     }
 }
コード例 #15
0
 /**
  * Test correct event starting and stopping in magento profile during SQL query fail
  */
 public function testProfilerDuringSqlException()
 {
     /** @var Zend_Db_Adapter_Pdo_Abstract $connection */
     $connection = $this->_model->getConnection('core_read');
     try {
         $connection->query('SELECT * FROM unknown_table');
     } catch (Zend_Db_Statement_Exception $exception) {
     }
     if (!isset($exception)) {
         $this->fail("Expected exception didn't thrown!");
     }
     /** @var Mage_Core_Model_Resource $resource */
     $resource = Mage::getSingleton('Mage_Core_Model_Resource');
     $testTableName = $resource->getTableName('core_resource');
     $connection->query('SELECT * FROM ' . $testTableName);
     /** @var Mage_Core_Model_Resource_Db_Profiler $profiler */
     $profiler = $connection->getProfiler();
     $this->assertInstanceOf('Mage_Core_Model_Resource_Db_Profiler', $profiler);
     $queryProfiles = $profiler->getQueryProfiles(Varien_Db_Profiler::SELECT);
     $this->assertCount(2, $queryProfiles);
 }
コード例 #16
0
 /**
  * Initialize resource and connection instances
  *
  * @param array $args
  */
 public function __construct(array $args = array())
 {
     $this->_resource = Mage::getSingleton('core/resource');
     $this->_connection = !empty($args['connection']) ? $args['connection'] : $this->_resource->getConnection(Mage_Core_Model_Resource::DEFAULT_READ_RESOURCE);
 }
コード例 #17
0
ファイル: Session.php プロジェクト: natxetee/magento2
 /**
  * Constructor
  *
  * @param Mage_Core_Model_Resource $resource
  */
 public function __construct(Mage_Core_Model_Resource $resource)
 {
     $this->_sessionTable = $resource->getTableName('core_session');
     $this->_write = $resource->getConnection('core_write');
 }
コード例 #18
0
ファイル: Osc.php プロジェクト: xiaoguizhidao/emporiodopara
 /**
 Retorna endereços do cliente
 */
 public function getAddressesSelect($customer_id, $scope)
 {
     $customer = Mage::getModel('customer/customer')->load($customer_id);
     $_string_options = '';
     // variável para armazenar as informações dos endereços
     if (count($customer->getAddresses()) > 0) {
         $default_id = 0;
         if ($scope == 'billing') {
             $default_billing_address = $customer->getDefaultBillingAddress();
             if (method_exists($default_billing_address, 'getData')) {
                 $default_id = $default_billing_address->getData('entity_id');
             }
         } else {
             if ($scope == 'shipping') {
                 $default_shipping_address = $customer->getDefaultShippingAddress();
                 if (method_exists($default_shipping_address, 'getData')) {
                     $default_id = $default_shipping_address->getData('entity_id');
                 }
             }
         }
         foreach ($customer->getAddresses() as $address) {
             $info_data = $address->getData();
             if (array_key_exists('region_id', $info_data)) {
                 $resource = new Mage_Core_Model_Resource();
                 $read = $resource->getConnection('core_read');
                 $select = $read->select()->from('directory_country_region')->where('region_id = ?', $info_data['region_id']);
                 $r = $read->fetchAll($select);
                 $result_set = $r[0];
                 $region = $result_set['default_name'];
             } else {
                 $region = "";
             }
             $_string_options .= "<option ";
             if ($address->getData('entity_id') == $default_id) {
                 $_string_options .= "selected='selected'";
             }
             $_string_options .= "value='" . $info_data['entity_id'] . "' > " . $info_data['firstname'] . " " . $info_data['lastname'] . ",\n\t\t\t\t" . $info_data['street'] . ", " . $info_data['postcode'] . ", " . $info_data['city'] . ", " . $region . " </option> \n";
         }
         $_string_options .= "<option value='0'> Novo Endereço </option>";
         return $_string_options;
     } else {
         return null;
     }
 }
コード例 #19
0
 /**
  * Get a list of host names for the supplied database resource.
  *
  * @param \Mage_Core_Model_Resource $resource
  * @return array
  */
 public function getByResource(\Mage_Core_Model_Resource $resource)
 {
     return $this->getByConnection($resource->getConnection('core_read'));
 }
 protected function _construct()
 {
     $this->_resource = Mage::getSingleton('core/resource');
     $this->_connection = $this->_resource->getConnection('core_write');
     $this->_table = $this->_resource->getTableName($this->_table);
 }