/** * @param StandardSearchIndexerInterface $category * @param Key $key * @param $previousHandle */ public function updateSearchIndexKeyColumns(CategoryInterface $category, AttributeKeyInterface $key, $previousHandle = null) { $controller = $key->getController(); /* * Added this for some backward compatibility reason – but it's obviously not * right because it makes it so no search index columns get created. if (!$previousHandle) { $previousHandle = $key->getAttributeKeyHandle(); }*/ if ($key->getAttributeKeyHandle() == $previousHandle || $key->isAttributeKeySearchable() == false || $category->getIndexedSearchTable() == false || $controller->getSearchIndexFieldDefinition() == false) { return false; } $fields = array(); $dropColumns = array(); $definition = $controller->getSearchIndexFieldDefinition(); $sm = $this->connection->getSchemaManager(); $toTable = $sm->listTableDetails($category->getIndexedSearchTable()); if ($previousHandle) { if (isset($definition['type'])) { $dropColumns[] = 'ak_' . $previousHandle; } else { foreach ($definition as $name => $column) { $dropColumns[] = 'ak_' . $previousHandle . '_' . $name; } } } if (isset($definition['type'])) { if (!$toTable->hasColumn('ak_' . $key->getAttributeKeyHandle())) { $fields[] = array('name' => 'ak_' . $key->getAttributeKeyHandle(), 'type' => $definition['type'], 'options' => $definition['options']); } } else { foreach ($definition as $name => $column) { if (!$toTable->hasColumn('ak_' . $key->getAttributeKeyHandle() . '_' . $name)) { $fields[] = array('name' => 'ak_' . $key->getAttributeKeyHandle() . '_' . $name, 'type' => $column['type'], 'options' => $column['options']); } } } $fromTable = $sm->listTableDetails($category->getIndexedSearchTable()); $parser = new \Concrete\Core\Database\Schema\Parser\ArrayParser(); $comparator = new \Doctrine\DBAL\Schema\Comparator(); if ($previousHandle != false) { foreach ($dropColumns as $column) { $toTable->dropColumn($column); } } $toTable = $parser->addColumns($toTable, $fields); $diff = $comparator->diffTable($fromTable, $toTable); if ($diff !== false) { $sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff); $arr = array(); foreach ($sql as $q) { $arr[] = $q; $this->connection->exec($q); } } }
public function updateSearchIndex($prevHandle = false) { $type = $this->getAttributeType(); $cnt = $type->getController(); if ($this->akHandle == $prevHandle) { return false; } if ($this->getIndexedSearchTable() == false) { return false; } if ($cnt->getSearchIndexFieldDefinition() == false) { return false; } $fields = array(); $dropColumns = array(); $definition = $cnt->getSearchIndexFieldDefinition(); /** @var \Concrete\Core\Database\Connection $db */ $db = Loader::db(); $platform = $db->getDatabasePlatform(); $sm = $db->getSchemaManager(); $toTable = $sm->listTableDetails($this->getIndexedSearchTable()); if ($prevHandle) { if (isset($definition['type'])) { $dropColumns[] = 'ak_' . $prevHandle; } else { foreach ($definition as $name => $column) { $dropColumns[] = 'ak_' . $prevHandle . '_' . $name; } } } if (isset($definition['type'])) { if (!$toTable->hasColumn('ak_' . $this->akHandle)) { $fields[] = array('name' => 'ak_' . $this->akHandle, 'type' => $definition['type'], 'options' => $definition['options']); } } else { foreach ($definition as $name => $column) { if (!$toTable->hasColumn('ak_' . $this->akHandle . '_' . $name)) { $fields[] = array('name' => 'ak_' . $this->akHandle . '_' . $name, 'type' => $column['type'], 'options' => $column['options']); } } } $fromTable = $sm->listTableDetails($this->getIndexedSearchTable()); $parser = new \Concrete\Core\Database\Schema\Parser\ArrayParser(); $comparator = new \Doctrine\DBAL\Schema\Comparator(); if ($prevHandle != false) { foreach ($dropColumns as $column) { $toTable->dropColumn($column); } } $toTable = $parser->addColumns($toTable, $fields); $diff = $comparator->diffTable($fromTable, $toTable); if ($diff !== false) { $sql = $platform->getAlterTableSQL($diff); $arr = array(); foreach ($sql as $q) { $arr[] = $q; $db->exec($q); } } }