Esempio n. 1
0
 /**
  * @param int $n
  * @return void
  */
 public function generateSequences($n = 10)
 {
     $connection = $this->appResource->getConnection('write');
     for ($i = 0; $i < $n; $i++) {
         foreach ($this->entities as $entityName) {
             $sequenceName = $this->appResource->getTableName(sprintf('sequence_%s_%s', $entityName, $i));
             if (!$connection->isTableExists($sequenceName)) {
                 $connection->query($this->ddlSequence->getCreateSequenceDdl($sequenceName));
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Create sequence with metadata and profile
  *
  * @throws \Exception
  * @throws \Magento\Framework\Exception\AlreadyExistsException
  * @return void
  */
 public function create()
 {
     $metadata = $this->resourceMetadata->loadByEntityTypeAndStore($this->data['entity_type'], $this->data['store_id']);
     if ($metadata->getSequenceTable() == $this->getSequenceName()) {
         return;
     }
     $this->data['sequence_table'] = $this->getSequenceName();
     $this->data['is_active'] = 1;
     $profile = $this->profileFactory->create(['data' => array_intersect_key($this->data, array_flip(['prefix', 'suffix', 'start_value', 'step', 'max_value', 'warning_value', 'is_active', 'active_profile']))]);
     $profile->setHasDataChanges(true);
     $this->data['active_profile'] = $profile;
     $metadata = $this->metaFactory->create(['data' => array_intersect_key($this->data, array_flip(['entity_type', 'store_id', 'sequence_table', 'active_profile']))]);
     $metadata->setHasDataChanges(true);
     try {
         $this->resourceMetadata->save($metadata);
         $adapter = $this->appResource->getConnection('write');
         if (!$adapter->isTableExists($this->data['sequence_table'])) {
             $adapter->query($this->ddlSequence->getCreateSequenceDdl($this->data['sequence_table'], $this->data['start_value']));
         }
     } catch (Exception $e) {
         $this->resourceMetadata->delete($metadata);
         $this->logger->critical($e);
         throw $e;
     }
     $this->data = array_flip($this->pattern);
 }