private function getCurrentFilters()
 {
     $result = array();
     $stmtQuery = $this->connectionRead->select()->from($this->tableName, array('id', 'preg_match', 'type'))->query();
     while ($filter = $stmtQuery->fetch()) {
         $result[$filter['id']] = $filter['preg_match'] . $this->separatorHash . $filter['type'];
     }
     return $result;
 }
Beispiel #2
0
 public function getTableDataDump($tableName, $step = 100)
 {
     $sql = '';
     if ($this->_read) {
         $quotedTableName = $this->_read->quoteIdentifier($tableName);
         $colunms = $this->_read->fetchRow('SELECT * FROM ' . $quotedTableName . ' LIMIT 1');
         if ($colunms) {
             $arrSql = array();
             $colunms = array_keys($colunms);
             $quote = $this->_read->getQuoteIdentifierSymbol();
             $sql = 'INSERT INTO ' . $quotedTableName . ' (' . $quote . implode($quote . ', ' . $quote, $colunms) . $quote . ')';
             $sql .= ' VALUES ';
             $startRow = 0;
             $select = $this->_read->select();
             $select->from($tableName)->limit($step, $startRow);
             while ($data = $this->_read->fetchAll($select)) {
                 $dataSql = array();
                 foreach ($data as $row) {
                     $dataSql[] = $this->_read->quoteInto('(?)', $row);
                 }
                 $arrSql[] = $sql . implode(', ', $dataSql) . ';';
                 $startRow += $step;
                 $select->limit($step, $startRow);
             }
             $sql = implode("\n", $arrSql) . "\n";
         }
     }
     return $sql;
 }
 /**
  * Run the jobs that are in the queue
  *
  * @param mixed  $limit Limit of jobs to run
  * @return  int  Number of jobs run
  */
 public function run($limit = NULL)
 {
     // Cleanup crashed jobs
     $pids = $this->_db->fetchCol("SELECT pid FROM {$this->_table} WHERE pid IS NOT NULL GROUP BY pid");
     foreach ($pids as $pid) {
         // Old pid is no longer running, release it's reserved tasks
         if (is_numeric($pid) && !file_exists("/proc/{$pid}/status")) {
             Mage::log("A crashed job queue process was detected for pid {$pid}", Zend_Log::NOTICE, self::ERROR_LOG);
             $this->_db->update($this->_table, array('pid' => new Zend_Db_Expr('NULL')), array('pid = ?' => $pid));
         }
     }
     // Reserve all new jobs since last run
     $pid = getmypid();
     $limit = $limit ? "LIMIT {$limit}" : '';
     $batchSize = $this->_db->query("UPDATE {$this->_db->quoteIdentifier($this->_table, true)} SET pid = {$pid} WHERE pid IS NULL ORDER BY job_id {$limit}")->rowCount();
     // Run all reserved jobs
     $result = $this->_db->query($this->_db->select()->from($this->_table, '*')->where('pid = ?', $pid)->order(array('job_id')));
     while ($row = $result->fetch()) {
         $where = $this->_db->quoteInto('job_id = ?', $row['job_id']);
         $data = substr($row['data'], 0, 1) == '{' ? json_decode($row['data'], TRUE) : ($data = unserialize($row['data']));
         // Check retries
         if ($row['retries'] >= $row['max_retries']) {
             $this->_db->delete($this->_table, $where);
             Mage::log("{$row['pid']}: Mage::getSingleton({$row['class']})->{$row['method']}(" . json_encode($data) . ")\n" . $row['error_log'], Zend_Log::ERR, self::ERROR_LOG);
             continue;
         }
         // Run job!
         try {
             $model = Mage::getSingleton($row['class']);
             $method = $row['method'];
             $model->{$method}(new Varien_Object($data));
             $this->_db->delete($this->_table, $where);
             Mage::log("{$row['pid']}: Mage::getSingleton({$row['class']})->{$row['method']}(" . json_encode($data) . ")", Zend_Log::INFO, self::SUCCESS_LOG);
         } catch (Exception $e) {
             // Increment retries and log error information
             $error = date('c') . " ERROR: " . get_class($e) . ": '{$e->getMessage()}' in {$e->getFile()}:{$e->getLine()}\n" . "Stack trace:\n" . $e->getTraceAsString();
             $bind = array('pid' => new Zend_Db_Expr('NULL'), 'retries' => new Zend_Db_Expr('retries + 1'), 'error_log' => new Zend_Db_Expr('SUBSTR(CONCAT(error_log,' . $this->_db->quote($error) . ',"\\n\\n"),1,20000)'));
             $this->_db->update($this->_table, $bind, $where);
         }
     }
     return $batchSize;
 }
 protected function getLikeExistItem($newItem, $ignoreTitle = true, $attributeSet = NULL)
 {
     $whereSql = '';
     foreach ($newItem as $key => $value) {
         if ($ignoreTitle && $key == 'title') {
             continue;
         }
         if ($whereSql == '') {
             $whereSql .= ' ';
         } else {
             $whereSql .= ' AND ';
         }
         $whereSql .= ' `' . $key . '` ';
         is_null($value) && ($whereSql .= ' IS NULL ');
         is_string($value) && ($whereSql .= ' = ' . $this->mySqlReadConnection->quote($value) . ' ');
         (is_integer($value) || is_float($value)) && ($whereSql .= ' = ' . $value . ' ');
     }
     $dbSelect = $this->mySqlReadConnection->select()->from($this->tableNameNew, '*');
     $whereSql != '' && $dbSelect->where($whereSql);
     $row = $this->mySqlReadConnection->fetchRow($dbSelect);
     if ($row === false) {
         return NULL;
     }
     if (!is_null($attributeSet)) {
         $templateId = (int) $row['id'];
         $templateType = (int) $attributeSet['template_type'];
         $attributeSetId = (int) $attributeSet['attribute_set_id'];
         $tasTable = Mage::getResourceModel('M2ePro/TemplatesAttributeSets')->getMainTable();
         $dbSelect = $this->mySqlReadConnection->select()->from($tasTable, '*')->where('template_type = ?', $templateType)->where('template_id = ?', $templateId);
         $rowsAttributesSets = $this->mySqlReadConnection->fetchAll($dbSelect);
         if ($rowsAttributesSets === false || count($rowsAttributesSets) != 1) {
             return NULL;
         }
         $rowAttributeSet = $rowsAttributesSets[0];
         if ((int) $rowAttributeSet['attribute_set_id'] != $attributeSetId) {
             return NULL;
         }
     }
     return $row;
 }
Beispiel #5
0
 /**
  * Retrieve table status
  *
  * @param string $tableName
  * @return Varien_Object
  */
 public function getTableStatus($tableName)
 {
     $row = $this->_write->showTableStatus($tableName);
     if ($row) {
         $statusObject = new Varien_Object();
         $statusObject->setIdFieldName('name');
         foreach ($row as $field => $value) {
             $statusObject->setData(strtolower($field), $value);
         }
         $cntRow = $this->_write->fetchRow($this->_write->select()->from($tableName, 'COUNT(1) as rows'));
         $statusObject->setRows($cntRow['rows']);
         return $statusObject;
     }
     return false;
 }
Beispiel #6
0
 public function getValues($type)
 {
     $dbSelect = $this->mySqlReadConnection->select()->from($this->tableName, '*')->where('`type` = ?', (string) $type);
     return $this->mySqlReadConnection->fetchAll($dbSelect);
 }
 /**
  * @param Varien_Db_Adapter_Pdo_Mysql $db
  * @return Varien_Db_Select
  */
 protected function _getFilterableAttributeSelect($db)
 {
     return $db->select()->from(array('a' => $this->getTable('eav/attribute')), null)->joinInner(array('t' => $this->getTable('eav/entity_type')), "`t`.`entity_type_id` = `a`.`entity_type_id` AND `t`.`entity_type_code` = 'catalog_product'", null)->joinInner(array('ca' => $this->getTable('catalog/eav_attribute')), "`ca`.`attribute_id` = `a`.`attribute_id`", null)->where("`ca`.`is_filterable` <> 0");
 }
 /**
  * Retrieve select object for loading entity attributes values
  *
  * @param   Varien_Object $object
  * @param   mixed $rowId
  * @return  Zend_Db_Select
  */
 protected function _getLoadAttributesSelect($object, $table)
 {
     $select = $this->_read->select()->from($table)->where($this->getEntityIdField() . '=?', $object->getId());
     return $select;
 }