Skip to content

Instantly share code, notes, and snippets.

@chx
chx / migration-generate.php
Last active June 4, 2016 21:26
Entity migration skeleton, run with drush scr
<?php
$entity_type_id = $_SERVER['argv'][3];
$process = implode(":\n ", array_keys(\Drupal::service('entity_field.manager')->getFieldMap()[$entity_type_id]));
print <<<EOT
id:
label:
source:
plugin:
constants:
@chx
chx / discussion_aliases.yml
Last active June 4, 2016 21:42
How to migrate node/user/etc aliases
id: discussion_aliases
label: Discussion aliases
source:
plugin: d7_node
node_type: discussion
constants:
english: en
node: /node
empty: ""
process:
[4.6MB/0.01s] Reading ./composer.json
[4.7MB/0.01s] Loading config file /home/chx/.composer/config.json
[4.7MB/0.01s] Loading config file /home/chx/.composer/auth.json
[4.7MB/0.01s] Loading config file ./composer.json
[5.0MB/0.02s] Checking CA file /etc/ca-certificates/extracted/tls-ca-bundle.pem
[5.6MB/0.02s] Executing command (/tmp/d8): git branch --no-color --no-abbrev -v
[7.4MB/0.05s] Reading /home/chx/.composer/composer.json
[7.4MB/0.05s] Loading config file /home/chx/.composer/config.json
[7.4MB/0.05s] Loading config file /home/chx/.composer/auth.json
[7.4MB/0.05s] Loading config file /home/chx/.composer/composer.json
sudo composer self-update
Updating to version 02ed27b16b184ecd6befed5bf8f6501084b42c0e.
Downloading: 100%
Use composer self-update --rollback to return to version 1.0.0-alpha11
➜ d8 git:(8.0.x) ✗ time composer require drupal/page_manager
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
^C
composer require drupal/page_manager 0.54s user 0.05s system 15% cpu 3.756 total
➜ d8 git:(8.0.x) ✗ sudo nano /etc/php/php.ini
➜ d8 git:(8.0.x) ✗
@chx
chx / gist:97fc107ee2a968628636
Last active January 22, 2016 15:23 — forked from edysmp/gist:24f0a13c3d4834dbe514
lookupDestinationId
// When looking up the destination ID we require an array with both the
// source key and value, e.g. ['nid' => 41]. In this case, $source_id_values need to be ordered the same
// order as $this->sourceIdFields(). However, the Migration process
// plugin doesn't currently have a way to get the source key so we presume
// the values have been passed through in the correct order.
if (!isset($source_id_values[0])) {
$source_id_values = array_intersect_key($this->sourceIdFields(), $source_id_values);
}
@chx
chx / patch
Last active August 29, 2015 14:23
<?php
/**
* @file
* Contains \Drupal\Core\StreamWrapper\FileDatabaseStream.
*/
namespace Drupal\Core\StreamWrapper;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
@chx
chx / gist:7f6baf855dd1f8be5f21
Last active August 29, 2015 14:20
States to taxonomy IDs
<?php
/**
* @file
* Contains \Drupal\migrate_plus\Plugin\migrate\process\TermReference.
*/
namespace Drupal\migrate_plus\Plugin\migrate\process;
use Drupal\taxonomy\TermStorageInterface;
@chx
chx / gist:2e0a392499843cdd9df5
Created April 20, 2015 18:49
"$err" : "Runner error: BadValue cannot sort with keys that are parallel arrays",
> db.test.drop();
true
> db.test.insert({f1:[1],f2:[1]});
WriteResult({ "nInserted" : 1 })
> db.test.find().sort({'f1':1,'f2':1});
error: {
"$err" : "Runner error: BadValue cannot sort with keys that are parallel arrays",
"code" : 17144
}
@chx
chx / gist:3612ac536e195f93dc02
Last active August 29, 2015 14:18
Get translatable entity menu paths
SELECT path
FROM menu_router
WHERE load_functions IN
(SELECT DISTINCT concat('a:1:{i:1;s:', length(concat(entity_type, '_load')), ':"', entity_type, '_load";}')
FROM field_config fc
INNER JOIN field_config_instance fci ON fci.field_id=fc.id
WHERE fc.active=1 AND fc.translatable=1)
AND path NOT LIKE '%/%/%';
@chx
chx / Drupal 8 HEAD
Created February 28, 2015 05:57
Refactoring fun with benjy
public function next() {
$this->currentIds = NULL;
$this->currentRow = NULL;
$source_configuration = $this->migration->get('source');
while ($this->getIterator()->valid()) {
$row_data = $this->getIterator()->current() + $source_configuration;
$this->getIterator()->next();
$row = new Row($row_data, $this->migration->getSourcePlugin()->getIds(), $this->migration->get('destinationIds'));