コード例 #1
0
ファイル: Tree.php プロジェクト: IlyaGluschenko/test001
 /**
  * @param string|int $nodeId
  * @param array $data
  * @return false|string
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function appendChild($nodeId, $data)
 {
     $info = $this->getNodeInfo($nodeId);
     if (!$info) {
         return false;
     }
     $data[$this->_left] = $info[$this->_right];
     $data[$this->_right] = $info[$this->_right] + 1;
     $data[$this->_level] = $info[$this->_level] + 1;
     $data[$this->_pid] = $nodeId;
     // creating a place for the record being inserted
     if ($nodeId) {
         $this->_db->beginTransaction();
         try {
             $sql = 'UPDATE ' . $this->_table . ' SET' . ' `' . $this->_left . '` = IF( `' . $this->_left . '` > :left,' . ' `' . $this->_left . '`+2, `' . $this->_left . '`),' . ' `' . $this->_right . '` = IF( `' . $this->_right . '`>= :right,' . ' `' . $this->_right . '`+2, `' . $this->_right . '`)' . ' WHERE `' . $this->_right . '` >= :right';
             $this->_db->query($sql, ['left' => $info[$this->_left], 'right' => $info[$this->_right]]);
             $this->_db->insert($this->_table, $data);
             $this->_db->commit();
         } catch (\PDOException $p) {
             $this->_db->rollBack();
             echo $p->getMessage();
             exit;
         } catch (\Exception $e) {
             $this->_db->rollBack();
             echo $e->getMessage();
             echo $sql;
             exit;
         }
         // TODO: change to ZEND LIBRARY
         $res = $this->_db->fetchOne('select last_insert_id()');
         return $res;
     }
     return false;
 }
コード例 #2
0
ファイル: Db.php プロジェクト: pradeep-wagento/magento2
 /**
  * @param Node $data
  * @param Node $parentNode
  * @param Node $prevNode
  * @return Node
  */
 public function appendChild($data, $parentNode, $prevNode = null)
 {
     $orderSelect = $this->_conn->select();
     $orderSelect->from($this->_table, new \Zend_Db_Expr('MAX(' . $this->_conn->quoteIdentifier($this->_orderField) . ')'))->where($this->_conn->quoteIdentifier($this->_parentField) . '=' . $parentNode->getId());
     $order = $this->_conn->fetchOne($orderSelect);
     $data[$this->_parentField] = $parentNode->getId();
     $data[$this->_levelField] = $parentNode->getData($this->_levelField) + 1;
     $data[$this->_orderField] = $order + 1;
     $this->_conn->insert($this->_table, $data);
     $data[$this->_idField] = $this->_conn->lastInsertId();
     return parent::appendChild($data, $parentNode, $prevNode);
 }
コード例 #3
0
 /**
  * Create $total Magento customers with emails "customer_$i[at]test.com" and save mapping to MageId into
  * $this->_testMageCustomers & $this->_testMageCustomersReverted
  *
  * ATTENTION: There is warning "Test method "_createMageCustomers" in test class "..." is not public."
  * in case of method's visibility is 'protected' (after $total argument was added).
  *
  * @param int $total total count of the Magento customers to be created.
  */
 protected function _createMageCustomers($total = 13)
 {
     $tbl = $this->_resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER);
     for ($i = 1; $i <= $total; $i++) {
         $email = "customer_{$i}@test.com";
         $this->_conn->insert($tbl, [Cfg::E_CUSTOMER_A_EMAIL => $email]);
         $id = $this->_conn->lastInsertId($tbl);
         $this->_mapCustomerMageIdByIndex[$i] = $id;
         $this->_mapCustomerIndexByMageId[$id] = $i;
         $this->_logger->debug("New Magento customer #{$i} is added with ID={$id} ({$email}).");
     }
     $this->_logger->debug("Total {$total} customer were added to Magento.");
 }
コード例 #4
0
ファイル: Mysql.php プロジェクト: okite11/frames21
 /**
  * @inheritdoc
  */
 public function insertRecords($documentName, $records, $updateOnDuplicate = false)
 {
     $this->resourceAdapter->rawQuery("SET @OLD_INSERT_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
     if ($updateOnDuplicate) {
         $result = $this->resourceAdapter->insertOnDuplicate($documentName, $records);
     } else {
         if (!is_array(reset($records))) {
             $result = $this->resourceAdapter->insert($documentName, $records);
         } else {
             $result = $this->insertMultiple($documentName, $records);
         }
     }
     $this->resourceAdapter->rawQuery("SET SQL_MODE=IFNULL(@OLD_INSERT_SQL_MODE,'')");
     return $result;
 }
コード例 #5
0
ファイル: DbTable.php プロジェクト: vasiljok/magento2
 /**
  * Update session
  *
  * @param string $sessionId
  * @param string $sessionData
  * @return bool
  */
 public function write($sessionId, $sessionData)
 {
     // need to use write connection to get the most fresh DB sessions
     $bindValues = ['session_id' => $sessionId];
     $select = $this->_write->select()->from($this->_sessionTable)->where('session_id = :session_id');
     $exists = $this->_write->fetchOne($select, $bindValues);
     // encode session serialized data to prevent insertion of incorrect symbols
     $sessionData = base64_encode($sessionData);
     $bind = ['session_expires' => time(), 'session_data' => $sessionData];
     if ($exists) {
         $this->_write->update($this->_sessionTable, $bind, ['session_id=?' => $sessionId]);
     } else {
         $bind['session_id'] = $sessionId;
         $this->_write->insert($this->_sessionTable, $bind);
     }
     return true;
 }
コード例 #6
0
 /**
  * Test for getList() method
  *
  * @return void
  */
 public function testGetList()
 {
     $this->assertEquals(0, $this->model->getVersion());
     //the same that a table is empty
     $changelogName = $this->resource->getTableName($this->model->getName());
     $testChengelogData = [['version_id' => 1, 'entity_id' => 1], ['version_id' => 2, 'entity_id' => 1], ['version_id' => 3, 'entity_id' => 2], ['version_id' => 4, 'entity_id' => 3], ['version_id' => 5, 'entity_id' => 1]];
     foreach ($testChengelogData as $data) {
         $this->connection->insert($changelogName, $data);
     }
     $this->assertEquals(5, $this->model->getVersion());
     $this->assertEquals(3, count($this->model->getList(0, 5)));
     //distinct entity_ids
     $this->assertEquals(3, count($this->model->getList(2, 5)));
     //distinct entity_ids
     $this->assertEquals(2, count($this->model->getList(0, 3)));
     //distinct entity_ids
     $this->assertEquals(1, count($this->model->getList(0, 2)));
     //distinct entity_ids
     $this->assertEquals(1, count($this->model->getList(2, 3)));
     //distinct entity_ids
     $this->assertEquals(0, count($this->model->getList(4, 3)));
     //because fromVersionId > toVersionId
 }
コード例 #7
0
ファイル: Sequence.php プロジェクト: nja78/magento2
 /**
  * Retrieve next value
  *
  * @return string
  */
 public function getNextValue()
 {
     $this->adapter->insert($this->meta->getSequenceTable(), []);
     $this->lastIncrementId = $this->adapter->lastInsertId($this->meta->getSequenceTable());
     return $this->getCurrentValue();
 }