Skip to content

Instantly share code, notes, and snippets.

View vladdancer's full-sized avatar
🖖

Vlad Moyseenko vladdancer

🖖
View GitHub Profile
@vladdancer
vladdancer / drupla8_image_file_statistics.sql
Last active June 20, 2023 13:52
Get stats about drupal files/commerce orders in database
# All image files
SELECT
floor(filesize/1000000)*1000000 as bucket,
SUM(`filesize`) as bytes,
(SUM(`filesize`) / 1024 / 1024 / 1024 ) AS GB,
COUNT(*) AS COUNT,
RPAD('', LN(COUNT(*)), '*') AS bar
FROM file_managed
WHERE (`filemime` LIKE 'image%') AND (`status` = '1')
GROUP BY bucket
@vladdancer
vladdancer / custom.settings.php
Last active June 21, 2022 10:05
Load PHP class from custom module within settings.php file #php #drupal8+
<?php
/**
* @file
* Load PHP class from custom module within settings.php file.
*/
if (class_exists(ClassLoader::class)) {
$class_loader = new ClassLoader();
$class_loader->addPsr4('Drupal\\mymodule\\', DRUPAL_ROOT . '/modules/custom/mymodule/src');
@vladdancer
vladdancer / legacy_database_info.php
Created June 21, 2022 09:53
Include database connection information from not native connection file #drupal8+
<?php
$legacy_db_key = 'project_legacy_db';
// Define database connection for local lando env.
if (getenv('LANDO_INFO')) {
$lando_info = json_decode(getenv('LANDO_INFO'), TRUE);
$databases[$legacy_db_key]['default'] = [
'database' => 'project_legacy',
'username' => $lando_info['database']['creds']['user'],
@vladdancer
vladdancer / find.sh
Created June 21, 2022 09:41
Find/search file by text
# https://stackoverflow.com/questions/1987926/how-do-i-recursively-grep-all-directories-and-subdirectories
grep --include="*.ext" -nRHI "text" ~/projects/
@vladdancer
vladdancer / drush-run-command-unser-user.drush.php
Created June 21, 2022 09:40
Run drush 9 command from specific user
// https://github.com/drush-ops/drush/issues/3396#issuecomment-1009268719
// Bulk generate using action: https://gist.github.com/seth-shaw-unlv/bd64930fa1f75be3aba05ade34433092
// accountSwitcher->switchTo(new UserSession(['uid' => 1]);
@vladdancer
vladdancer / moderation_state_migration_example.yml
Created June 9, 2022 11:26
Map moderation_state field in migration #drupal8 #drupla9 #migrate
# https://www.drupal.org/project/workflow/issues/3016286
# https://www.drupal.org/project/drupal/issues/3157105#comment-13830538
process:
...
moderation_state:
plugin: default_value
default_value: published
process:
...
@vladdancer
vladdancer / media--pp-external.html.twig
Created June 3, 2022 21:45
PP Media template example
{% if pp_media.asset.meta.type === 'image' %}
{{ attach_library('easy_responsive_images/resizer') }}
{% set srcset = [
asset.sizes['400w'].url ~ ' 600w',
asset.sizes['900w'].url ~ ' 900w',
asset.sizes['3000w'].url ~ ' 3000w',
] %}
<img src="{{ src }}" data-srcset="{{ srcset|join(',')|raw }}" alt="{{ pp_media.asset.meta.alt }}" loading="lazy" />
{% endif %}
@vladdancer
vladdancer / Redirect.php
Created January 28, 2022 18:26
Add extra source records to migrate #drupal8 #drupal9 #migrate
<?php
final class Redirect extends SqlBase {
/**
* Return list of additional redirects that doesn't exist in source db.
*
* Some redirects are not in db, but we need to add them.
*
* @return array[]
@vladdancer
vladdancer / recreateMigrationMapTables.drush.php
Created November 5, 2021 14:17
Recreate migrate map tables for specific migration #migrate #drupal8
<?php
/**
* @file
* recreateMigrationMapTables.drush.php
*
* Usage:
* @code
* drush scr recreateMigrationMapTables.drush.php [MIGRATION_ID]
* @endcode
*/
@vladdancer
vladdancer / routine.sh
Created September 27, 2021 14:25
Drupal routine #php #drupal
# Check php compatibility
# source: https://www.specbee.com/blogs/drupal9-and-its-compatibility-with-php-8-learn-whats-new
vendor/bin/phpcs -p . --standard=PHPCompatibility \
--runtime-set 7.4 \
--extensions=php,module,install,inc \
--report-full==./php7.4-compatibility.txt