Skip to content

Instantly share code, notes, and snippets.

@szeidler
szeidler / ddrupal.sh
Created May 19, 2017 11:12
Use Drupal console with docker4drupal
#!/bin/sh
docker-compose exec --user 82 php drupal
#alias ddrupal = docker-compose exec --user 82 php drupal
@szeidler
szeidler / drushrc.php
Created May 19, 2017 11:44
drushrc.php for Drush Patchfile and Docker4Drupal
<?php
// Get the site absolute filepath. Extracted from drush_site_path().
function drush_get_absolute_site_path() {
$possible_paths = array(
'/var/www/drupal/web/sites/default',
'/var/www/html/web/sites/default',
'/var/www/html/sites/default',
);
@szeidler
szeidler / services-add_item_id_attribute-1653592.patch
Created June 30, 2017 14:16
Add support for index values on xml output. Otherwise you will lose information about numeric array keys.
diff --git a/servers/rest_server/includes/ServicesFormatter.inc b/servers/rest_server/includes/ServicesFormatter.inc
index 9799b19..8ce275a 100644
--- a/servers/rest_server/includes/ServicesFormatter.inc
+++ b/servers/rest_server/includes/ServicesFormatter.inc
@@ -61,6 +61,7 @@ class ServicesXMLFormatter implements ServicesFormatterInterface {
$assoc = FALSE || empty($data);
foreach ($data as $key => $value) {
if (is_numeric($key)) {
+ $id = $key;
$key = 'item';
@szeidler
szeidler / docker-cleanup-resources.md
Created July 18, 2017 15:05 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@szeidler
szeidler / easy-drush-file-rsync.sh
Created July 25, 2017 11:05
Easy drush file rsync
drush rsync @source_alias:%files @target_alias:%files --dry-run --ignore-existing --progress
@szeidler
szeidler / d4d-add-developer-tools.sh
Last active August 8, 2017 16:38
Add developer tools to docker4drupal (Drush Pachfile, Registry Rebuild)
#!/bin/bash
# Remove and reinstall drush patchfile.
docker-compose exec --user root php sh -c 'if [ -d "/home/www-data/.drush/drush-patchfile" ]; then rm -rf /home/www-data/.drush/drush-patchfile; fi;'
docker-compose exec --user 82 php sh -c 'git clone https://[email protected]/szeidler/drush-patchfile.git /home/www-data/.drush/drush-patchfile'
# Remove and reinstall registry rebuild.
docker-compose exec --user root php sh -c 'if [ -d "/home/www-data/.drush/registry_rebuild" ]; then rm -rf /home/www-data/.drush/registry_rebuild; fi;'
docker-compose exec --user 82 php drush @none dl registry_rebuild-7.x
@szeidler
szeidler / update-d4d-images.sh
Last active August 27, 2017 15:34
Update docker4drupal images to recent version - recursive.
#!/bin/bash
# Update PHP 7.0
find . -maxdepth 2 -name "docker-compose.yml" -exec sed -i '' 's#wodby/drupal-php:7.0-[0-9].[0-9].[0-9]#wodby/drupal-php:7.0-2.4.6#g' '{}' \;
# Update PHP 7.1
find . -maxdepth 2 -name "docker-compose.yml" -exec sed -i '' 's#wodby/drupal-php:7.1-[0-9].[0-9].[0-9]#wodby/drupal-php:7.1-2.4.6#g' '{}' \;
# Update MariaDB
find . -maxdepth 2 -name "docker-compose.yml" -exec sed -i '' 's#wodby/mariadb:10.1-[0-9].[0-9].[0-9]#wodby/mariadb:10.1-2.3.4#g' '{}' \;
@szeidler
szeidler / merge-fotoweb-metadata-into-file-entity-fields.php
Created October 19, 2017 11:50
Merge Fotoweb metadata into File Entity fields
<?php
function mymodule_file_presave($file) {
if ($file->type === 'image' && file_uri_scheme($file->uri) === 'fotoweb') {
$wrapper = entity_metadata_wrapper('file', $file);
$field_map = array(
'field_file_image_alt_text' => 120,
'field_file_image_title_text' => 5,
'field_image_caption' => 121,
'field_image_byline' => 80,
@szeidler
szeidler / fotoweb-write-back-metadata.php
Created October 19, 2017 12:01
Writeback metadata using the FotowebSteamWrapper
if ($file_wrapper = file_stream_wrapper_get_instance_by_uri($file->uri)) {
// Specifiy the Fotoweb property to update.
$metadata_key_to_update = 60;
// Set the new value.
$file->metadata['asset_metadata'][$metadata_key_to_update]['value'] = 'My new caption';
// Update the metadata and trigger the file_save, which could
// overwrite the $file->metadata with the actual asset metadata
// for data consistency.
@szeidler
szeidler / term_merge-prevent_duplicate_references-2924108-2.patch
Created November 16, 2017 17:34
Prevent references fields from creating duplicates
diff --git a/src/TermMerger.php b/src/TermMerger.php
index 2b341f6..d96ae0d 100644
--- a/src/TermMerger.php
+++ b/src/TermMerger.php
@@ -177,13 +177,30 @@ class TermMerger implements TermMergerInterface {
}
$referenceUpdated = FALSE;
- foreach ($values as &$value) {
+ $targetTermExists = FALSE;