insert example

// Initialize the DIC with a fake module handler for alterable queries.     $container = new ContainerBuilder();
    $container->set('module_handler', $this->createMock('\Drupal\Core\Extension\ModuleHandlerInterface'));
    \Drupal::setContainer($container);

    // Create the tables and load them up with data, skipping empty ones.     foreach (array_filter($database_contents) as $table => $rows) {
      $pilot_row = reset($rows);
      $connection->schema()->createTable($table$this->createSchemaFromRow($pilot_row));

      $insert = $connection->insert($table)->fields(array_keys($pilot_row));
      array_walk($rows[$insert, 'values']);
      $insert->execute();
    }

    return $connection;
  }

  /** * Generates a table schema from a row. * * @param array $row * The reference row on which to base the schema. * * @return array * The Schema API-ready table schema. */
'not null' => TRUE,
      'length' => '255',
      'default' => '0',
    ),
  ),
  'primary key' => array(
    'aid',
  ),
  'mysql_character_set' => 'utf8',
));

$connection->insert('actions')
->fields(array(
  'aid',
  'type',
  'callback',
  'parameters',
  'description',
))
->values(array(
  'aid' => '1',
  'type' => 'comment',
  'callback' => 'comment_unpublish_by_keyword_action',
  
$this->storage = new DatabaseStorage($this->container->get('database'), 'config');
    $this->invalidStorage = new DatabaseStorage($this->container->get('database'), 'invalid');
  }

  protected function read($name) {
    $data = Database::getConnection()->select('config', 'c')->fields('c', ['data'])->condition('name', $name)->execute()->fetchField();
    return unserialize($data);
  }

  protected function insert($name$data) {
    Database::getConnection()->insert('config')->fields(['name' => $name, 'data' => $data])->execute();
  }

  protected function update($name$data) {
    Database::getConnection()->update('config')->fields(['data' => $data])->condition('name', $name)->execute();
  }

  protected function delete($name) {
    Database::getConnection()->delete('config')->condition('name', $name)->execute();
  }

}
static::assertEquals(200, $browser->getResponse()->getStatusCode());
        static::assertArrayHasKey('data', $response);
    }

    public function testAdminIntegrationIdHeader(): void
    {
        $connection = $this->getContainer()->get(Connection::class);
        $ids = new IdsCollection();
        $ids->create('integration');

        $connection->insert('integration', [
            'id' => Uuid::fromHexToBytes($ids->get('integration')),
            'access_key' => 'foo',
            'secret_access_key' => TestDefaults::HASHED_PASSWORD,
            'label' => 'test integration',
            'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            'admin' => 0,
        ]);

        $connection->insert('acl_role', [
            'id' => Uuid::fromHexToBytes($ids->create('acl_role')),
            'name' => 'integration',
            
$this->updateProductTranslation($exist$data);
        } else {
            $this->insertProductTranslation($productId$languageId$data);
        }
    }

    private function insertProductTranslation(int $productId, int $languageId, array $data): void
    {
        $data = array_merge($data['languageID' => $languageId, 'articleID' => $productId]);

        $query = $this->connection->createQueryBuilder();
        $query->insert('s_articles_translations');
        foreach ($data as $key => $value) {
            $query->setValue($key, ':' . $key);
            $query->setParameter(':' . $key$value);
        }
        $query->execute();
    }

    private function updateProductTranslation(int $id, array $data): void
    {
        $query = $this->connection->createQueryBuilder();

        
'email' => 'test@example.com',
            'password' => 'shopware',
            'created_at' => $now->format('Y-m-d H:i:s'),
            'default_payment_method_id' => $defaultPaymentMethod,
            'sales_channel_id' => Uuid::fromHexToBytes(TestDefaults::SALES_CHANNEL),
            'customer_group_id' => Uuid::fromHexToBytes(TestDefaults::FALLBACK_CUSTOMER_GROUP),
            'language_id' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
            'default_billing_address_id' => Uuid::fromHexToBytes($billingAddressId),
            'default_shipping_address_id' => Uuid::randomBytes(),
        ];

        $this->connection->insert('customer', $customer);
        $this->connection->insert('customer_address', $customerAddress);
    }

    private function createProduct(): void
    {
        /** @var EntityRepository $productRepository */
        $productRepository = self::getContainer()->get('product.repository');

        $product = [
            'id' => $this->ids->create('product'),
            'productNumber' => Uuid::randomHex(),
            
'templateId' => Uuid::randomBytes(),
                'name' => 'Cancellation invoice',
                'nameDe' => 'Stornorechnung',
            ],
        ];

        foreach ($documentTypeTranslationMapping as $technicalName => $values) {
            $existingTypeId = $this->getExistingMailTemplateTypeId($technicalName$connection);
            if ($existingTypeId !== null) {
                $values['typeId'] = $existingTypeId;
            } else {
                $connection->insert(
                    'mail_template_type',
                    [
                        'id' => $values['typeId'],
                        'technical_name' => $technicalName,
                        'available_entities' => json_encode(['order' => 'order', 'salesChannel' => 'sales_channel']),
                        'template_data' => '{"order":{"orderNumber":"10060","orderCustomer":{"firstName":"Max","lastName":"Mustermann"}},"salesChannel":{"name":"Storefront"}}',
                        'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                    ]
                );

                $translations = new Translations(
                    [
string $nameDe,
        string $nameEn
    ): void {
        $languageDefault = $this->getEnLanguageId($connection);
        $languageDE = $this->getDeLanguageId($connection);

        $langId = $connection->fetchOne(' SELECT `currency`.`id` FROM `currency` WHERE `iso_code` = :code LIMIT 1 ', ['code' => $isoCode]);

        if (!$langId) {
            $connection->insert('currency', ['id' => $id, 'iso_code' => $isoCode, 'factor' => $factor, 'symbol' => $symbol, 'position' => 1, 'decimal_precision' => 2, 'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)]);
            if ($languageDefault !== $languageDE) {
                $connection->insert('currency_translation', ['currency_id' => $id, 'language_id' => $languageDefault, 'short_name' => $shortNameEn, 'name' => $nameEn, 'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)]);
            }
            if ($languageDE) {
                $connection->insert('currency_translation', ['currency_id' => $id, 'language_id' => $languageDE, 'short_name' => $shortNameDe, 'name' => $nameDe, 'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)]);
            }
        }
    }

    private function getDeLanguageId(Connection $connection): ?string
    {
        
'email' => 'test@example.com',
            'password' => 'shopware',
            'created_at' => $now->format('Y-m-d H:i:s'),
            'default_payment_method_id' => $defaultPaymentMethod,
            'sales_channel_id' => Uuid::fromHexToBytes(TestDefaults::SALES_CHANNEL),
            'customer_group_id' => Uuid::fromHexToBytes(TestDefaults::FALLBACK_CUSTOMER_GROUP),
            'language_id' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
            'default_billing_address_id' => Uuid::fromHexToBytes($billingAddressId),
            'default_shipping_address_id' => Uuid::randomBytes(),
        ]$customerOverrides);

        $this->connection->insert('customer', $customer);
        $this->connection->insert('customer_address', $customerAddress);
    }

    private function dropAccountType(): void
    {
        if ($this->hasColumn('customer', 'account_type')) {
            $this->connection->executeStatement('ALTER TABLE `customer` DROP COLUMN `account_type`');
        }
    }

    /** * @return false|CustomerData */
'format' => 2,
      ])
      ->condition('vid', 3)
      ->execute();
    $migration = $this->getMigration('d6_node:story');
    $table_name = $migration->getIdMap()->mapTableName();
    $default_connection = \Drupal::database();
    $default_connection->truncate($table_name)->execute();
    if ($new_row) {
      $hash = $migration->getIdMap()->getSourceIdsHash(['nid' => $new_row['sourceid1']]);
      $new_row['source_ids_hash'] = $hash;
      $default_connection->insert($table_name)
        ->fields($new_row)
        ->execute();
    }
    $this->executeMigration($migration);
    return $title;
  }

}
'stock' => 0,
                'visibilities' => [
                    [
                        'salesChannelId' => $salesChannelId,
                        'visibility' => ProductVisibilityDefinition::VISIBILITY_ALL,
                    ],
                ],
            ],
        ];

        // the writer does not fire events, so seo urls are not created automatically         $writer->insert($productDefinition$products, WriteContext::createFromContext(Context::createDefaultContext()));

        // Builds the index for visibilities         $this->getContainer()->get(InheritanceUpdater::class)->update('product', [$id], Context::createDefaultContext());

        $this->getContainer()
            ->get(SeoUrlUpdater::class)
            ->update(ProductPageSeoUrlRoute::ROUTE_NAME, [$id]);

        /** @var EntityRepository $productRepo */
        $productRepo = $this->getContainer()->get('product.repository');

        

    private function getTestRule(): array
    {
        return (array) $this->connection->fetchAssociative('SELECT * FROM rule WHERE id = :id', [
            'id' => $this->testRule['id'],
        ]);
    }

    private function addTestConditions(): void
    {
        $this->connection->insert('rule', $this->testRule);
        $this->connection->insert('rule_condition', $this->testCondition);
    }

    private function removeTestConditions(): void
    {
        $this->connection->delete('rule_condition', [
            'id' => $this->testCondition['id'],
        ]);
        $this->connection->delete('rule', [
            'id' => $this->testRule['id'],
        ]);
    }


$connection = \Drupal::database();
// Update the default category to that it is not selected. $connection->update('contact')
  ->fields(['selected' => '0'])
  ->condition('cid', '1')
  ->execute();

// Add a custom contact category. $connection->insert('contact')->fields([
  'category',
  'recipients',
  'reply',
  'weight',
  'selected',
])
  ->values([
    'category' => 'Upgrade test',
    'recipients' => 'test1@example.com,test2@example.com',
    'reply' => 'Test reply',
    'weight' => 1,
    
'net' => 2,
                            'linked' => false,
                        ],
                    ],
                ],
            ],
        ];

        $definition = $this->registerDefinition(PriceFieldDefinition::class);
        $this->getContainer()
            ->get(EntityWriter::class)
            ->insert($definition$data$context);

        $entity = $this->getContainer()->get(EntityReaderInterface::class)
            ->read($definitionnew Criteria([$ids->get('with-was')]), Context::createDefaultContext())
            ->get($ids->get('with-was'));

        static::assertNotNull($entity);

        $price = $entity->get('data');

        /** @var PriceCollection $price */
        static::assertInstanceOf(PriceCollection::class$price);

        
static::assertNotNull($rule->getPayload());
        static::assertInstanceOf(AndRule::class$rule->getPayload());
        static::assertFalse($rule->isInvalid());
        static::assertNull($rule2->getPayload());
        static::assertTrue($rule2->isInvalid());
    }

    public function testLoadValidRulesFromDatabase(): void
    {
        $id = Uuid::randomHex();
        $this->connection->createQueryBuilder()
            ->insert('rule')
            ->values(['id' => ':id', 'name' => ':name', 'priority' => 3, 'invalid' => '0', 'created_at' => ':createdAt'])
            ->setParameter('name', 'Rule')
            ->setParameter('id', Uuid::fromHexToBytes($id))
            ->setParameter('createdAt', (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT))
            ->executeStatement();

        $this->connection->createQueryBuilder()
            ->insert('rule_condition')
            ->values(['id' => ':id', 'type' => ':type', 'value' => 'null', 'position' => '0', 'rule_id' => ':ruleId', 'created_at' => ':createdAt'])
            ->setParameter('id', Uuid::randomBytes())
            ->setParameter('type', (new AndRule())->getName())
            
Home | Imprint | This part of the site doesn't use cookies.