_removeCartGarbage(); $this->_removeTransactionGarbage(); return $this; } protected function _removeCartGarbage() { $select = $this->_db->select(); $select->from($this->_getPair('Cart'), array()); $select->where('DATE_ADD(`Cart`.`changed`, INTERVAL ' . self::GARBAGE_DAY_PERIOD . ' DAY) <= NOW()'); $select->where('`Cart`.`transactionId` IS NULL'); $this->_deleteFromSelect($select); return $this; } protected function _removeTransactionGarbage() { $select = $this->_db->select()->reset(); $select->from($this->_getPair(), array()); $select->joinLeft( $this->_getPair('Cart'), '`Cart`.`transactionId` = `' . $this->_tableAlias . '`.`id`', array() ); $select->where('DATE_ADD(`' . $this->_tableAlias . '`.`changed`, INTERVAL ' . self::GARBAGE_DAY_PERIOD . ' DAY) <= NOW()'); $select->where('`Cart`.`id` IS NULL'); $this->_deleteFromSelect($select); return $this; } /** * Create delete query from select object * * @param Zend_Db_Select $select * @return App_ECommerce_Order_Garbage_Obj */ protected function _deleteFromSelect(Zend_Db_Select $select) { $sql = 'DELETE'; $sqlParts = ''; foreach ($select->getPart(Zend_Db_Select::FROM) as $partName => $part) { if ($part['joinCondition'] == Zend_Db_Select::FROM) { continue; } $sqlParts .= ' ' . strtoupper($part['joinType']) . ' ' . $part['tableName'] . ' AS ' . $partName . (!empty($part['joinCondition']) ? (strstr($part['joinType'], 'join') ? ' ON' : '') . ' ' . $part['joinCondition'] : '') . ' '; } $sql .= ' ' .implode(', ', array_keys($select->getPart(Zend_Db_Select::FROM))); $sql .= $sqlParts; if ($select->getPart(Zend_Db_Select::WHERE)) { $sql .= 'WHERE'; foreach ($select->getPart(Zend_Db_Select::WHERE) as $wherePart) { $sql .= ' ' . $wherePart . ' '; } } $this->_db->exec($sql); return $this; } }