private function clearRemovedFilters($currentFilters, $receivedFilters) { $calculatedFiltersIds = $this->getFiltersForDeleting($currentFilters, $receivedFilters); if (count($calculatedFiltersIds) <= 0) { return; } $this->connectionWrite->delete($this->tableName, '`id` IN (' . implode(',', $calculatedFiltersIds) . ')'); }
/** * 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; }
/** * Delete table row * * @param string $table * @param string $idField * @param string|int $id * @param null|string $parentField * @param int|string $parentId * @return Mage_Core_Model_Resource_Setup */ public function deleteTableRow($table, $idField, $id, $parentField = null, $parentId = 0) { if (strpos($table, '/') !== false) { $table = $this->getTable($table); } $condition = $this->_conn->quoteInto("{$idField}=?", $id); if ($parentField !== null) { $condition .= $this->_conn->quoteInto(" AND {$parentField}=?", $parentId); } $this->_conn->delete($table, $condition); if (isset($this->_setupCache[$table][$parentId][$id])) { unset($this->_setupCache[$table][$parentId][$id]); } return $this; }
public function deleteValues($type) { $this->mySqlWriteConnection->delete($this->tableName, "type = '{$type}'"); }
/** * @param Varien_Db_Adapter_Pdo_Mysql $adapter * @param Unirgy_StoreLocator_Model_Mysql4_Location $resource */ protected function clearOldLocations($adapter, $resource) { $overwrite = $this->_shouldOverwrite(); if ($overwrite && !$this->_tablesCleared) { $adapter->delete($resource->getMainTable()); $this->_tablesCleared = true; } }