_removeCartGarbage(); //$this->_removeTransactionGarbage(); $this->_removeUserGarbage(); 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(); $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; } protected function _removeUserGarbage() { $select = $this->_db->select(); $select->from($this->_getPair('User')); $select->joinLeft( $this->_getPair('CartItem'), '`CartItem`.`productId` = `User`.`id` AND `CartItem`.`cartItemType` = "User\\\\Register\\\\"', array() ); $select->where('`User`.`bought` IS NULL'); $select->where('`CartItem`.`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; } }