Example #1
0
 /**
  * Insert data from select statement of read adapter to
  * destination table related with index adapter
  *
  * @param Varien_Db_Select $select
  * @param string $destTable
  * @param array $columns
  * @param bool $readToIndex data migration direction (true - read=>index, false - index=>read)
  * @return Mage_Index_Model_Resource_Abstract
  */
 public function insertFromSelect($select, $destTable, array $columns, $readToIndex = true)
 {
     if ($readToIndex) {
         $from = $this->_getWriteAdapter();
         $to = $this->_getIndexAdapter();
     } else {
         $from = $this->_getIndexAdapter();
         $to = $this->_getWriteAdapter();
     }
     if ($from === $to) {
         $query = $select->insertFromSelect($destTable, $columns);
         $to->query($query);
     } else {
         $stmt = $from->query($select);
         $data = array();
         $counter = 0;
         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
             $data[] = $row;
             $counter++;
             if ($counter > 2000) {
                 $to->insertArray($destTable, $columns, $data);
                 $data = array();
                 $counter = 0;
             }
         }
         if (!empty($data)) {
             $to->insertArray($destTable, $columns, $data);
         }
     }
     return $this;
 }
Example #2
0
 /**
  *
  * Returns Insert From Select On Duplicate query with analytic functions
  *
  * @param Varien_Db_Select $select
  * @param string $table
  * @param array $table
  * @return string
  */
 public function getInsertFromSelectUsingAnalytic(Varien_Db_Select $select, $table, $fields)
 {
     return $select->insertFromSelect($table, $fields);
 }