Skip to content

Instantly share code, notes, and snippets.

View andriyun's full-sized avatar
💭
drupaling

Andriyun andriyun

💭
drupaling
View GitHub Profile
@andriyun
andriyun / data.txt
Last active May 23, 2022 08:41
Check for data os2datascanner
CPRnr.:140876-1030
CPRnr.2:1408761030
Email: [email protected]
Telefonnummer: 12 34 56 78
Telefonnummer2: 12345678
@andriyun
andriyun / write-debug-into-file-ruby-on-rails.rb
Last active August 17, 2021 17:39
How to write debug into file in Ruby on Rails in controller
...
File.write("/path/to/log.txt", variable.inspect, mode: "a")
...
@andriyun
andriyun / php-db-connection-with-PDO.php
Last active April 14, 2021 18:29
PHP db connection with PDO
<?php
$DB = new PDO("mysql:host=db_host;dbname=db_name", "db_user", "db_user_pass");
$statement = $DB->prepare("SHOW TABLES;");
$statement->execute();
print_r($statement->fetchAll());
@andriyun
andriyun / drupal-rest-api-create-update-entities.sh
Last active March 12, 2021 13:04
Drupal Rest API Create/Update entities
# Create
curl --include \
--request POST \
--user admin:admin \
--header 'Content-type: application/hal+json' \
http://drift.docksal/entity/node?_format=hal_json \
--data-binary '{"_links":{"type":{"href":"http://drift.docksal/rest/type/node/article"}},"title":[{"value":"Example node title"}],"type":[{"target_id":"article"}]}'
# Update
curl --include \
@andriyun
andriyun / delete-entities-from-drupal-via-drupal.md
Last active January 11, 2022 09:21
Delete entities from drupal via drush

Delete any entity in drupal

drush ev "entity_delete_multiple('v', \Drupal::entityQuery('entity_type_name')->execute());"

Delete node with pecific type

drush ev "entity_delete_multiple('node', \Drupal::entityQuery('node')->condition('type', 'node_type')->execute());"
<?php
/**
* Helper function to log info.
*/
public static function _bc_filelog($message) {
error_log(print_r($message, 1) . PHP_EOL, 3, '../checkout-session-info.log');
}
/**
* {@inheritdoc}
@andriyun
andriyun / update_drupal_configuration_programmatically.md
Last active August 19, 2020 15:42
Update drupal configuration programmatically from yml files.
  • Delete configuration from database using configuration management API.

    Drupal::configFactory()->getEditable('automated_cron.settings')->delete();
  • Create configuration in database using configuration management API.

    Drupal::service('config.storage')->write(
      'views.view.content',
      Symfony\Component\Yaml\Yaml::parse(file_get_contents('./config/sync/views.view.content.yml'))
@andriyun
andriyun / OS2Web_development_guide.md
Last active February 6, 2020 15:34
OS2Web development guide

General rules

Composer based code delivery

All features and functionality should implemented as composer package and should be available to download via composer. By default it's recommended to use packagist.org as package registry.

Configuration

Features functionality should be installed and configured from code during

@andriyun
andriyun / create-remove_database-user.sql
Created January 3, 2019 12:01
SQL sources management (create/remove database/user)
CREATE DATABASE db_name;
GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost' IDENTIFIED BY '[pass]';
DROP DATABASE db_name;
DROP user db_user@localhost;
@andriyun
andriyun / drupal8-change-active-theme-programmatically.php
Last active November 22, 2022 19:56
Drupal 8 switch active theme programmatically
<?php
/**
* See original implementation http://cgit.drupalcode.org/mailsystem/tree/src/MailsystemManager.php#n60
*/
// Switch the theme to the configured mail theme.
$theme_manager = \Drupal::service('theme.manager');
$mail_theme = '[your theme name]';
$current_active_theme = $theme_manager->getActiveTheme();
if ($mail_theme && $mail_theme != $current_active_theme->getName()) {
$theme_initialization = \Drupal::service('theme.initialization');