Skip to content

Instantly share code, notes, and snippets.

View juampynr's full-sized avatar

Juampy NR juampynr

View GitHub Profile
@juampynr
juampynr / mymodule.md
Last active July 16, 2022 23:41
Drupal 7 Database Updates tricks

This document contains a common database updates in Drupal 7 projects.

Change a field type from textarea to textfield (wipe out its data)

Let's suppose we want to change field_article_summary from text to textarea, but we do not care about loosing its current data.

Start by removing the field through the Admin Interface in your local environment. Then, add the field with the new configuration and recreate the feature where it was exported. Finally, add the following database update:

$ git diff
diff --git a/prepare_dir.sh b/prepare_dir.sh
index 69b122d..ebb9e8c 100755
--- a/prepare_dir.sh
+++ b/prepare_dir.sh
@@ -85,7 +85,7 @@ MESSAGE="Checked out a new branch for this pull request, and merged it to $MERGE
# If this the merge branch is not master, also merge to master to be sure all
# work is combined.
-if [[ "$MERGE_BRANCH" -ne "master" ]]; then
@juampynr
juampynr / debug.md
Last active April 25, 2017 17:19
Mysql log all queries into a file

Installation

Add the following to your .bashrc or .profile file in your user's home path:

# Log all queries.
function mysqlLog {
  drush sql-cli << EOF
SET GLOBAL query_cache_type=OFF;
SET global log_output = 'FILE';
SET global general_log_file='/tmp/query.log';
5f37bb91 (Dave Reid 2011-08-12 09:19:12 -0500 367) }
a83b0c82 (Dave Reid 2012-03-27 19:22:59 -0500 368)
8f0209d0 (colan 2012-11-03 20:36:51 -0400 369) // Get all translations of tag data for this entity.
6fbd22a5 (Damien McKenna 2013-12-31 19:10:23 -0500 370) $result = db_query("SELECT entity_id, revision_id, language, data FROM {metatag} WHE
1ee36b5c (Damien McKenna 2013-03-04 07:44:23 -0500 371) ':type' => $entity_type,
1ee36b5c (Damien McKenna 2013-03-04 07:44:23 -0500 372) ':ids' => $entity_ids,
f911e5c0 (Damien McKenna 2013-07-24 15:11:23 -0400 373) ));
8f0209d0 (colan 2012-11-03 20:36:51 -0400 374)
8f0209d0 (colan 2012-11-03 20:36:51 -0400 375) // Marshal it into an array keyed by entity ID. Each value is an array of
8f0209d0 (colan 2012-11-03 20:36:51 -0400 376) // translations keyed by language code.
@juampynr
juampynr / checklist.md
Last active August 29, 2015 14:01
DrupalCamp Spain 2014 Checklist http://2014.drupalcamp.es
@juampynr
juampynr / gist:27cdd7f5c358ac9ec1fa
Last active August 29, 2015 14:02
Upgrading Drupal core and contrib

Pre-upgrade steps:

# Start by fetching production's database.
drush syncdb @prod @local

# Make sure your main branch is up to date:
git checkout master
git pull --rebase
@juampynr
juampynr / README.md
Last active September 3, 2015 16:03
Custom Apache Solr Query

The following script is an example on how to build a custom query with Drupal's Apache Solr Search module.

In order to test it, you can copy the file to the root of your Drupal site, set the nid at the top, adjust the query and run it with the following Drush command:

drush scr custom_solr_query.php

You can find further details about it at this article from the Lullabot Blog.

@juampynr
juampynr / move.sh
Created September 3, 2014 09:55
Move site within sites directory
cd sites/example
drush -v sqlq 'UPDATE system SET filename = REPLACE(filename, "example", "example2")'
mv sites/example sites/example2
drush rr -v # This is Registry Rebuild Drush command
# Then, browse your code and search for URLs containing sites/example.
@juampynr
juampynr / mymodule.php
Last active August 29, 2015 14:07
Database update with Batch API template
<?php
/**
* @file mymodule.install
* Install hooks for mymodule.
*/
/**
* Description of what the database update does. Do not use "Implements..." since it adds
* zero information and makes reading the list of pending database updates in Drush harder
* to read.
@juampynr
juampynr / gist:60d5134a2555a3eaeec4
Last active August 29, 2015 14:07
Check database table size
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "mydatabase" ORDER BY round(((data_length + index_length) / 1024 / 1024),2) DESC
LIMIT 0,15;