Skip to content

Instantly share code, notes, and snippets.

View BramDriesen's full-sized avatar
:shipit:
On it!

Bram Driesen BramDriesen

:shipit:
On it!
View GitHub Profile
@BramDriesen
BramDriesen / drupal_load_single_field_from_entity.php
Last active October 28, 2017 10:13
Load a single field of an entity.
<?php
// Save the original field collection data.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'commerce_product')
->entityCondition('bundle', $entity->type)
->propertyCondition('product_id', $entity->product_id);
$result = $query->execute();
if (isset($result['commerce_product'])) {
$original_product = $result['commerce_product'];
@BramDriesen
BramDriesen / drupal_save_single_field
Last active October 28, 2017 10:13
Save a single field value of an entity/node
<?php
$node = node_load(1); // 1 is node id we want to load
// Change field value
$node->field_product_description[$node->language][0]['value'] = 'This is a very nice and useful product. Buy it now! We want your money!';
// Get the numeric id of your field by passing field name
$info = field_info_field('field_product_description');
$fields = array($info['id']);
# D8 Search API Solr: Wipe a Solr core completely NEEDS EDITING
drush --uri=[domain] ev '
$search_api_server_machine_name = "acquia_search_server"; ## EDIT THIS IF NEEDED
$backend = Drupal\search_api\Entity\Server::load($search_api_server_machine_name)->getBackend();
$connector = $backend->getSolrConnector();
# Code based on \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::deleteAllIndexItems()
$query = "solrfieldname:solrfieldvalue"; ## REPLACE "solrfieldname:solrfieldvalue" WITH "*:*" TO DELETE EVERYTHING
$update_query = $connector->getUpdateQuery();
$update_query->addDeleteQuery($query);
$update_query->addOptimize();
# D7 Search API Solr or apachesolr.module
drush --uri=[domain] ev '
// Get Solr.
function XX_get_solr() {
$solr = false;
if (function_exists("apachesolr_get_solr")) {
// apachesolr.module
$solr = apachesolr_get_solr();
}
elseif (function_exists("search_api_server_load")) {
echo 'flush_all' | nc localhost 11211
/bin/echo -e 'flush_all\nquit' | nc -q1 $(hostname -s) 11211
@BramDriesen
BramDriesen / link
Created December 11, 2017 13:18
URL to load the login page of a hotspot in case it doesn't auto-load.
Siege - Load testing
Jmeter - Load testing
Tree - Building files tree
Truncate - Truncating files
Lnav - Log file navigation
sudo apt-get install curl
curl -O https://bin.equinox.io/c/mvjh5YAmwCZ/cryptotrader-stable-linux-amd64.tgz
tar -xvzf cryptotrader-stable-linux-amd64.tgz -C /usr/local/bin/
@BramDriesen
BramDriesen / strings_translations_hook_update_N.php
Created October 4, 2018 15:00 — forked from citlacom/strings_translations_hook_update_N.php
Programmatically set strings translations in hook_update_N()
/**
* Implements hook_update_N().
*/
function hook_update_N(&$sandbox) {
$report = array(
'skips' => 0,
'updates' => 0,
'deletes' => 0,
'additions' => 0
);