00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract extends Mage_Core_Model_Mysql4_Abstract
00034 {
00035
00036
00037
00038 protected function _construct()
00039 {
00040
00041 }
00042
00043 public function saveIndex($data, $storeId, $productId)
00044 {
00045 return $this->saveIndices(array($data), $storeId, $productId);
00046 }
00047
00048 public function saveIndices(array $data, $storeId, $productId)
00049 {
00050 $this->_executeReplace($data, $storeId, $productId);
00051 }
00052
00053 protected function _executeReplace($data, $storeId, $productId)
00054 {
00055 $this->beginTransaction();
00056 try {
00057 foreach ($data as $row) {
00058 $row[$this->_entityIdFieldName] = $productId;
00059 $this->_getWriteAdapter()->insert($this->getMainTable(), $row);
00060 }
00061 $this->commit();
00062 } catch (Exception $e) {
00063 $this->rollBack();
00064 throw $e;
00065 }
00066
00067 return $this;
00068 }
00069
00070 public function cleanup($productId, $storeId = null, $attributeId = null)
00071 {
00072 $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_entityIdFieldName} = ?", $productId);
00073
00074 if (!is_null($storeId))
00075 $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_storeIdFieldName} = ?", $storeId);
00076
00077 if (!is_null($attributeId))
00078 $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_attributeIdFieldName} = ?", $attributeId);
00079
00080 $conditions = implode (' AND ', $conditions);
00081 $this->_getWriteAdapter()->delete($this->getMainTable(), $conditions);
00082 }
00083
00084 public function loadAttributeCodesByCondition($conditions)
00085 {
00086 $table = $this->getTable('eav/attribute');
00087 $select = $this->_getReadAdapter()->select();
00088 $select->from($table, 'attribute_id');
00089 $select->distinct(true);
00090
00091 if (is_array($conditions)) {
00092 foreach ($conditions as $k=>$condition) {
00093 if (is_array($condition)) {
00094 if ($k == 'or') {
00095 $function = 'where';
00096 foreach ($condition as $field=>$value) {
00097 if (is_array($value))
00098 $select->$function("{$field} in (?)", $value);
00099 else
00100 $select->$function("{$field} = ?", $value);
00101
00102 $function = 'orWhere';
00103 }
00104 } else {
00105 $select->where("{$k} in (?)", $condition);
00106 }
00107 } else {
00108 $select->where("{$k} = ?", $condition);
00109 }
00110 }
00111 } else {
00112 $select->where($conditions);
00113 }
00114
00115 return $this->_getReadAdapter()->fetchCol($select);
00116 }
00117 }