Skip to content

Instantly share code, notes, and snippets.

View vincenzo's full-sized avatar

Vinnie Russo vincenzo

  • Italy
View GitHub Profile
@vincenzo
vincenzo / droptables.sh
Last active August 29, 2015 14:26
MySQL: drop all tables without dropping the DB
mysqldump -hhost -uusername -ppassword --no-data --add-drop-table databasename | grep ^DROP | mysql -uusername -ppassword -hhost databasename
@vincenzo
vincenzo / gist:97fcc533945579275a0a
Created February 26, 2015 10:20
Drupal: alter the length of a text field with data already in it.
// Our field's machine name is field_short_description and it is a text field which originally had a max length of 250 characters.
// Now we desire to alter that length so that it will be 450 characters.
// If you use Features and you have this field exported as part of a content type, you must update the settings in there too.
// However, updating the settings just in a Feature will not do the trick for a field that has already data in it, hence the following code.
// You can put this code in a hook_update_N().
// Alter 'field_data_field_short_description' table.
db_change_field(
'field_data_field_short_description',
'field_short_description_value',
@vincenzo
vincenzo / book-table.sql
Last active December 22, 2015 14:19
DRUPAL - Retrieve all nodes that were children in a Book and whose root parent was of a specific node type
mlid int(10) unsigned NO PRI 0
nid int(10) unsigned NO UNI 0
bid int(10) unsigned NO MUL 0
@vincenzo
vincenzo / Match dependencies
Created January 12, 2013 23:30
Ok, Drupal. Imagine that, for whatever reason, you have a profile with a number of dependencies and you have to make sure you have all the modules in your codebase that match those dependencies. Here is a possible bash command to list modules that are not found. Fairly sure one can do better, but this was written on the fly and worked. Gotta lov…
cat yourprofile.info | grep "dependencies\[]" | cut -d "=" -f 2 | while read MODULE; do echo "${MODULE}: $(find /var/www/yoursite -iname ${MODULE}.module | wc -l)"; done | sort | grep ": 0" | cut -d ":" -f 1
@vincenzo
vincenzo / correct.php
Last active October 1, 2015 20:58
Soundex - Correct and Train
<?php
function correct($word, $dic) {
if (array_key_exists($word, $dic)) {
return $word;
}
$search_result = $dic[soundex($word)];
foreach ($search_result as $key => &$res) {
@vincenzo
vincenzo / gist:2053654
Created March 16, 2012 23:47
Programmatic CCK Content Type - Step 4
<?php
function _example_cck_content_save_cck_node($op = 'install') {
module_load_include('inc', 'example_cck_content', 'example_cck_content.def');
$content = _example_cck_content_cck_export();
// we do not want too many modules enabled - the content_copy module is just needed
// in order to install the content type, so we just require it here (require_once prevent to
// include it more than once in case it is already enabled)
require_once './' . drupal_get_path('module', 'content') . '/modules/content_copy/content_copy.module';
@vincenzo
vincenzo / gist:2043713
Created March 15, 2012 11:16
Programmatic CCK Content Type Updated - Step 6 - part 2
<?php
/**
* Implementation of hook_requirements()
*/
function example_cck_content_requirements($phase) {
$requirements = array();
$t = get_t();
// an array of the dependencies
@vincenzo
vincenzo / gist:2043687
Created March 15, 2012 11:09
Programmatic CCK Content Type Updated - Step 6 - part 1
; $Id$
name = Example CCK Content
description = Provide an example CCK content type
dependencies[] = content
dependencies[] = filefield
dependencies[] = imagefield
dependencies[] = text
core = 6.x
@vincenzo
vincenzo / gist:2043645
Created March 15, 2012 11:01
Programmatic CCK Content Type Updated - Step 5
<?php
/**
* Implementation of hook_install
*/
function example_cck_content_install() {
_example_cck_content_save_cck_node();
}
@vincenzo
vincenzo / gist:2043602
Created March 15, 2012 10:49
Programmatic CCK Content Type Updated - Step 4
<?php
function _example_cck_content_save_cck_node() {
module_load_include('inc', 'example_cck_content', 'example_cck_content.def');
$content = _example_cck_content_cck_export();
// we do not want too many modules enabled - the content_copy and
// alternate_content_copy modules are just needed in order to install the
// content type, so we just require them here (require_once prevent to
// include it more than once in case it is already enabled)