public function up(Schema $schema) { $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); $tableHelper = new SchemaHelper($this->container); $groupTable = $tableHelper->getTableOrCollection('group'); $this->addSql('CREATE TABLE pim_catalog_product_template (id INT AUTO_INCREMENT NOT NULL, valuesData LONGTEXT NOT NULL COMMENT \'(DC2Type:json_array)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'); $this->addSql(sprintf('ALTER TABLE %s ADD product_template_id INT DEFAULT NULL', $groupTable)); $this->addSql(sprintf('ALTER TABLE %s ADD CONSTRAINT FK_5D6997EDA9F591A7 FOREIGN KEY (product_template_id) REFERENCES pim_catalog_product_template (id) ON DELETE SET NULL', $groupTable)); $this->addSql(sprintf('CREATE UNIQUE INDEX UNIQ_5D6997EDA9F591A7 ON %s (product_template_id)', $groupTable)); }
/** * @param ConsoleOutput $output * @param ArgvInput $input */ public function __construct(ConsoleOutput $output, ArgvInput $input) { $this->output = $output; $env = $input->getParameterOption(['-e', '--env']); if (!$env) { $env = 'dev'; } $this->bootKernel($env); $schemaHelper = new SchemaHelper($this->container); $this->productTemplateTable = $schemaHelper->getTableOrCollection('product_template'); }
/** * @param Schema $schema */ public function postUp(Schema $schema) { $upgradeHelper = new UpgradeHelper($this->container); if ($upgradeHelper->areProductsStoredInMongo()) { $database = $upgradeHelper->getMongoInstance(); $tableHelper = new SchemaHelper($this->container); echo "Add index to Version document on column loggetAt...\n"; $versionCollection = new \MongoCollection($database, $tableHelper->getTableOrCollection('version')); $versionCollection->ensureIndex(['loggedAt' => -1], ['background' => true]); echo "Done."; } }
protected function normalizeProductStatuses(\MongoDB $database) { $tableHelper = new SchemaHelper($this->container); $productCollection = new \MongoCollection($database, $tableHelper->getTableOrCollection('product')); $products = $productCollection->find(); echo sprintf("Migrating %s product status values...\n", $products->count()); foreach ($products as $product) { $result = $productCollection->update(['_id' => $product['_id']], ['$set' => ['normalizedData.enabled' => $product['enabled']]], ['w' => true]); if ($result['ok'] != 1) { echo "ERROR on migrating enabled value:"; print_r($result); print_r($product); } } echo sprintf("Migrating %s product status values done.\n", $products->count()); }
protected function removeFilePathFromProductMedias(\MongoDB $database) { $tableHelper = new SchemaHelper($this->container); $productCollection = new \MongoCollection($database, $tableHelper->getTableOrCollection('product')); $products = $productCollection->find(); echo sprintf("Removing filePath from %s medias...\n", $products->count()); foreach ($products as $product) { if (array_key_exists('values', $product)) { $countValues = count($product['values']); for ($i = 0; $i <= $countValues; $i++) { $result = $productCollection->update(['_id' => $product['_id']], ['$unset' => [sprintf('values.%s.media.filePath', $i) => true]], ['w' => true]); if ($result['ok'] != 1) { echo "ERROR on migrating media value:"; print_r($result); print_r($product); } } } } echo sprintf("FilePath removed from %s medias: <info>done</info>.\n", $products->count()); }
/** * @param Schema $schema */ public function up(Schema $schema) { $schemaHelper = new SchemaHelper($this->container); $attributes = $this->container->get('pim_catalog.repository.attribute')->findBy(['attributeType' => [AttributeTypes::METRIC, AttributeTypes::PRICE_COLLECTION]]); $attributeCodes = ['metric' => [], 'price' => []]; foreach ($attributes as $attribute) { if (AttributeTypes::METRIC === $attribute->getAttributeType()) { $attributeCodes['metric'][] = $attribute->getCode(); } if (AttributeTypes::PRICE_COLLECTION === $attribute->getAttributeType()) { $attributeCodes['price'][] = $attribute->getCode(); } } $table = $schemaHelper->getTableOrCollection('product_template'); $templates = $this->connection->fetchAll('SELECT * FROM ' . $table); foreach ($templates as $template) { if (isset($template['valuesData'])) { $values = json_decode($template['valuesData'], true); foreach ($values as $code => $value) { foreach ($value as $index => $data) { if (in_array($code, $attributeCodes['metric']) && isset($data['data']['data'])) { $data['data']['amount'] = $data['data']['data']; unset($data['data']['data']); } elseif (in_array($code, $attributeCodes['price'])) { foreach ($data['data'] as $indexPrice => $price) { if (isset($price['data'])) { $data['data'][$indexPrice]['amount'] = $price['data']; unset($data['data'][$indexPrice]['data']); } } } $values[$code][$index] = $data; } } $this->connection->update($table, ['valuesData' => json_encode($values)], ['id' => $template['id']]); } } }
public function up(Schema $schema) { $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); $tableHelper = new SchemaHelper($this->container); $this->addSql(sprintf('ALTER TABLE %s DROP useable_as_grid_column', $tableHelper->getTableOrCollection('attribute'))); }