public function updatePayment($transaction_id = NULL, $bank_status = NULL, array $customer = NULL) { if (is_null($transaction_id) || is_null($bank_status)) { Mage::throwException('Geen transaction_id en/of bank_status gevonden...'); } $data = array('bank_status' => $bank_status, 'updated_at' => $this->getCurrentDate()); if ($customer && isset($customer['consumerAccount'])) { $data['bank_account'] = $customer['consumerAccount']; } $where = sprintf("transaction_id = %s", $this->_mysqlw->quote($transaction_id)); $this->_mysqlw->update($this->_table, $data, $where); }
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; }
public function save($settings, $websiteId = 0, $storeId = 0) { $websiteId = intval($websiteId); $storeId = intval($storeId); $this->_deleteSettings($websiteId, $storeId); $newSettings = array(); if (is_array($settings)) { foreach ($settings as $key => $value) { $settingSql = '(' . $this->_connection->quote($key) . ', ' . $websiteId . ',' . $storeId . ','; if ($this->_isTextOption($key)) { $settingSql .= 'null,' . $this->_connection->quote($value); } else { $settingSql .= $this->_connection->quote($value) . ', null'; } $settingSql .= ')'; $newSettings[] = $settingSql; } } if (!empty($newSettings)) { $newSettings = implode(',', $newSettings); $this->_connection->query("insert into {$this->_table} (`code`, `website_id`, `store_id`, `value`, `value_text`) values {$newSettings}"); } return $this; }
/** * 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; }
/** * Safely quotes a value for an SQL statement. * * If an array is passed as the value, the array values are quote * and then returned as a comma-separated string. * * @param mixed $value The value to quote. * @param null $type OPTIONAL the SQL datatype name, or constant, or null. * @return mixed|string An SQL-safe quoted value (or string of separated values). */ public function quote($value, $type = null) { $this->_connect(); if ($type !== null && array_key_exists($type = strtoupper($type), $this->_numericDataTypes) && $this->_numericDataTypes[$type] == Zend_Db::FLOAT_TYPE) { $value = $this->_convertFloat($value); $quoteValue = sprintf('%F', $value); return $quoteValue; } elseif (is_float($value)) { return $this->_quote($value); } return parent::quote($value, $type); }
/** * Safely quotes a value for an SQL statement. * * If an array is passed as the value, the array values are quoted * and then returned as a comma-separated string. * * @param mixed $value The value to quote. * @param mixed $type OPTIONAL the SQL datatype name, or constant, or null. * * @return mixed An SQL-safe quoted value (or string of separated values). */ public function quote($value, $type = null) { if (false === $this->enableDbQuoteOptimization()) { return parent::quote($value, $type); } $this->_connect(); if ($value instanceof Zend_Db_Select) { return '(' . $value->assemble() . ')'; } if ($value instanceof Zend_Db_Expr) { return $value->__toString(); } if (is_array($value)) { foreach ($value as &$val) { $val = $this->quote($val, $type); } return implode(', ', $value); } if ($type !== null && array_key_exists($type = strtoupper($type), $this->_numericDataTypes)) { $quotedValue = '0'; switch ($this->_numericDataTypes[$type]) { case Zend_Db::INT_TYPE: // 32-bit integer $quotedValue = (string) intval($value); break; case Zend_Db::BIGINT_TYPE: // 64-bit integer // ANSI SQL-style hex literals (e.g. x'[\dA-F]+') // are not supported here, because these are string // literals, not numeric literals. if (preg_match('/^( [+-]? # optional sign (?: 0[Xx][\\da-fA-F]+ # ODBC-style hexadecimal |\\d+ # decimal or octal, or MySQL ZEROFILL decimal (?:[eE][+-]?\\d+)? # optional exponent on decimals or octals ) )/x', (string) $value, $matches)) { $quotedValue = $matches[1]; } break; case Zend_Db::FLOAT_TYPE: // float or decimal $quotedValue = sprintf('%F', $value); } return $quotedValue; } return $this->_quote($this->castToNumeric($value)); }