Skip to content

Instantly share code, notes, and snippets.

View weitzman's full-sized avatar

Moshe Weitzman weitzman

View GitHub Profile
@weitzman
weitzman / FeatuesCommands.php
Created June 11, 2017 11:15
Port Features to Drush9
<?php
namespace Drupal\features\Commands;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Component\Diff\DiffFormatter;
use Drupal\config_update\ConfigDiffInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\features\FeaturesAssignerInterface;
use Drupal\features\FeaturesGeneratorInterface;
use Drupal\features\FeaturesManagerInterface;
@weitzman
weitzman / blog.md
Last active September 29, 2017 10:07
Porting Commands to Drush9

Drush 9 features a deep rewrite of our app, both user facing and internals. We created and open sourced AnnotatedCommand, OutputFormatters, and Config. We leveraged Symfony Console for our CLI fundmentals. For details on Drush9, see the video or slides from our Drupalcon Vienna presentation.

** ADD AN ANNOTATED COMMAND EXAMPLE **

Unfortunately, old commandfiles such as example.drush.inc no longer load in Drush 9. We've made it relatively painless to port this code to Drush 9:

** ADD A GIF OF GENERATOR **

  1. Using Drush 9 on a working site, run drush generate drush-command-file. generate is a wrapper for the Drupal Code Generator
@weitzman
weitzman / config.diff
Last active November 10, 2017 13:20
Purger config mismatch - https://www.drupal.org/node/2922493
ubuntu@box921:~/mass$ git diff
diff --git a/conf/drupal/config/purge.logger_channels.yml b/conf/drupal/config/purge.logger_channels.yml
index e16c732..e5b869d 100644
--- a/conf/drupal/config/purge.logger_channels.yml
+++ b/conf/drupal/config/purge.logger_channels.yml
@@ -11,15 +11,3 @@ channels:
- 0
- 2
- 3
- -
@weitzman
weitzman / .ahoy.yml
Last active July 19, 2018 15:36
mass.gov blog post
ahoyapi: v2
commands:
exec:
# These env variables come from https://github.com/wodby/docker4drupal/issues/273
cmd: docker-compose exec -e COLUMNS=$(tput cols) -e LINES=$(tput lines) -e TERM=$TERM drupal "$@"
usage: Run a command in the container
bash:
cmd: ahoy exec bash
usage: Open a shell inside the container.
# Builds a MySQL image with local data directory. See 'command' in docker-compose.yml
# Approach borrowed from https://about.zoosk.com/en/engineering-blog/test-databases-docker-containers/.
FROM mysql:5.6
RUN ["mkdir", "–p", "/var/lib/mysql-image"]
RUN echo "[mysqld]" > /etc/mysql/conf.d/mass-vm.cnf \
&& echo "datadir = /var/lib/mysql-image" >> /etc/mysql/conf.d/mass-vm.cnf
`
- run: docker-compose stop --timeout 30 mysql
- run: docker login -u $DOCKER_USER -p $DOCKER_API_KEY
- run: docker commit $(docker-compose ps -q mysql) mass/mysql-sanitized:latest
- run: docker push mass/mysql-sanitized:latest
#
# Copy and rename this file to .env at root of this project.
#
# Set a docker caching specification for the code mount.
#
# File access in hosted volumes can be very slow on Mac due to issues with the
# filesystem. Using cached or delegated here can really speed things up, but
# this isn't a cross-platform feature.
# See https://docs.docker.com/compose/compose-file/#caching-options-for-volume-mounts-docker-for-mac
eval `ssh-agent -s` > /dev/null 2>&1
ssh-add /var/run/secrets/mass_id_rsa
Host *
IdentityFile /run/secrets/mass_id_rsa
@weitzman
weitzman / ExampleTest.php
Last active January 22, 2019 18:52
A test class that leverages Drupal Test Traits
<?php
// Use your module's testing namespace such as the one below.
namespace Drupal\Tests\moduleName\ExistingSite;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
use weitzman\DrupalTestTraits\ExistingSiteBase;
/**