/** * Перестраивает индексы * @param string $tableName * @param string $indexName * @return bool */ public static function rebuildIndex($tableName, $indexName = false) { $rebuldIndexes = array(); if (!$indexName) { //если indexName == false, то перестраиваем все индексы $rebuldIndexes = self::getStruct($tableName)->getIndexesNames(); } else { //перестраиваем только $indexName $rebuldIndexes = array($indexName); } foreach ($rebuldIndexes as $rebuldIndexName) { self::$_index[$tableName][$rebuldIndexName] = array(); $index = self::getStruct($tableName)->getIndex($rebuldIndexName); if (isset(self::$_data[$tableName])) { foreach (self::$_data[$tableName] as $scalarPK => $values) { $scalarIndexKey = Lms_Item_Scalar::extractScalarPkValue($values, $index['fields']); self::$_index[$tableName][$rebuldIndexName][$scalarIndexKey][] = $scalarPK; } } } return true; }
public function storeData($data) { $this->_buffer = $data; $this->_scalarPkValue = Lms_Item_Scalar::scalarize($this->_getAssocPkValue(self::FROM_BUFFER)); Lms_Item_Store::setValues($this->getTableName(), $this->_scalarPkValue, $data); }
private static function _fillData($tableName, $rows, $foreignKey) { $newScalarPKs = array(); if (!count($rows)) { return $newScalarPKs; } $struct = Lms_Item_Store::getStruct($tableName); $pk = $struct->getPk(); for ($i = count($rows) - 1; $i >= 0; $i--) { if (is_array($pk)) { $assocPK = array(); foreach ($pk as $pkFieldName) { $assocPK[$pkFieldName] = $rows[$i][$pkFieldName]; } $scalarPk = Lms_Item_Scalar::scalarize($assocPK); } else { $scalarPk = $rows[$i][$pk]; } $newScalarPKs[] = $scalarPk; Lms_Item_Store::setValues($tableName, $scalarPk, $rows[$i], true); if ($foreignKey && isset($rows[$i][$foreignKey])) { $indexKey = $rows[$i][$foreignKey]; Lms_Item_Store::setIndexStatus($tableName, $foreignKey, $indexKey, Lms_Item_Struct::FULL_INDEX); } } Lms_Item_Store::rebuildIndex($tableName); return $newScalarPKs; }