Showing posts with label drush. Show all posts
Showing posts with label drush. Show all posts

Saturday, December 14, 2013

Getting drush to work ( on flexwebhosting ) fixing "exec() has been disabled for security reasons" and "This configuration is incompatible with drush."

I run in a bit of trouble installing drush on a new webhost.
I just started following the tutorial on drupal.org:
Specific instructions for installing Drush on different platforms
Since I'm using CentOS I picked the Install Drush on CentOS (with H-Sphere)
But then when I tried to run drush after install I got some errors.
The first one I got was: "exec() has been disabled for security reasons"
After I fixed that one I got:
"The following restricted PHP modes have non-empty values: [error] disable_functions. This configuration is incompatible with drush."

Both errors can be fixed by putting this in the command line on the server:
# mkdir -p ~/.drush
# cp -i /usr/local/lib/php.ini ~/.drush/
# nano ~/.drush/php.ini

Then find the "disable_functions" string and make it is empty:
disable_functions =
save the php.ini file and drush should be working now :)

source articles:
https://drupal.org/node/2009426
http://ventraip.com.au/forums/index.php?/topic/5394-drush-phpini-and-exec/
http://www.6by9.net/drush-on-an-hosting-fix-using-custom-php-ini/

Friday, June 21, 2013

Create one time login link from the command line using drush no need to reset your password

I don't use this command as much but when I need it I always forget what this string of code was.

So I'll post it on my blog :)

The magic:
drush uli

Or if your targeting a specific user:
drush uli username

Using drush you can create a one time login link for a user or admin.
This is especially usefull if you want to login to the site without changing the password.
For example if you have a client with a drupal site that doesn't know the administrators pass or doesn't want to change it because you need it.
This can also be used to change the password if you don't know where the password reset link would be send or don't have access to the email address ( anymore )

Friday, October 26, 2012

adding a city autotagging field to an user by creating a custom drupal 7 module

This posts tells you about how to programmatically create a field, instance, taxonomy library and create an autotagging widget in the form with it.

First in your module.install file create a hook_enable() function.
In the final version this would be hook_install() but while testing the module I find it easier to use hook enable so you can do: drush en mymodule -y and drush dis my module -y to enable and disable the module.

My module is called popover so that's the name I'll be using next.


/**
 * Implements hook_enable
 * runs every time this module is enabled, to run only at install use hook_install
 * Once the module has been enabled ( even only once ) hook_install won't be called anymore.
 */
function popover_enable() {
        // starting with the taxonomy library ( vocabulary ) first:

$vocabulary = (object) array(
'name' => 'City',
'description' => 'Pick your city :)',
'machine_name' => 'city',
);
taxonomy_vocabulary_save($vocabulary);
$terms = array(
'Amsterdam',
'Rotterdam',
'Rosmalen',
'Driebergen',
'Zeist',
'Utrecht',
);
        // I've created a custom function to save multiple terms to one vocabulary:
_popover_taxonomy_terms_save($terms,$vocabulary->vid);

        // building the field
$field = array(
'field_name' => 'field_' .$vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);

        // connecting the user to the field I've just created
$instance = array(
'field_name' => 'field_' . $vocabulary->machine_name,
'entity_type' => 'user',
'label' => $vocabulary->name,
'bundle' => 'user',
'required' => TRUE,
'widget' => array(
'type' => 'taxonomy_autocomplete',
'weight' => -4,
),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
'teaser' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
),
);
        // another custom field creator function
popover_field_create_update_instance($instance);
}



And the function I'm calling from the code above:

/**
 * save multiple terms to one taxonomy Vocabulary
 * @param  array $terms array of term names
 * @param  int   $vid   Vocabulary id
 */
function _popover_taxonomy_terms_save($terms,$vid) {
foreach($terms as $term) {
taxonomy_term_save(
(object) array(
'name' => $term,
'vid' => $vid,
)
);
}
}

/**
 * field creater helper function checks if field already is in this bundle if so do update instead of create
 */
function popover_field_create_update_instance($instance) {
if( field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']) == NULL) {
return field_create_instance($instance);
}
else{
return field_update_instance($instance);
}
}



Now because the instance is in the user bundle the field should now be showing up on the user edit form.

To delete the instance, field and vocabulary upon uninstall of the module. I've written the following:


/**
 * Implements hook_disable()
 * TODO: needs to be hook_uninstall in the future but again for testing using the hook_disable
 */
function popover_disable() {
// create array with instances/fields/vocabularies to cleanup
  $cleanups = array(
  'city',
  // you can add more fields here...
  );
  foreach($cleanups as $name) {
  _popover_cleanup_instance_field_vocabulary($name);
  }

  // force field purge ( so it is really deleted without waiting for cron )
  // I think I would remove this in the final version as well since your not going to uninstall a
  // module and then reinstall it again immediately after. besides opening the module page 
  // and then the unistall page calls cron if I remember correctly but not sure about that... anyway:
field_purge_batch(5000); // not sure if this is a to high number...
}

/**
 * cleanup helper function
 * @param  String $name machine_name of the vocabulary ( 'field_' is added for the field/instance)
 */
function _popover_cleanup_instance_field_vocabulary($name) {
$instance = field_info_instance('user','field_' . $name,'user');
// removing instance of field_$name in the user bundle
field_delete_instance($instance, true);
// deleting field
field_delete_field('field_' . $name);

// delete city vocabulary
$vid = db_select('taxonomy_vocabulary', 'v')
    ->fields('v', array('vid'))
    ->condition("v.machine_name", $name)
    ->execute()
 ->fetchField();
  taxonomy_vocabulary_delete($vid);
}

You can see the whole module on my github But I'm still working on it so don't expect it to work 100%

Thursday, October 11, 2012

drush make with install profile run from github

keeping installing sites and enabling all those modules you use every time is a pain in the ass.

Well no more!

I discovered that there is an easier way!

To work with this you need to have a basic drupal webserver running or need to install that first.
also drush 5.x needs to be enabled so you can run drush make

To get a quick and dirty solution just for testing or for me to remember how to get the install, you need to run the following command in the folder where you want the drupal install:
drush make https://raw.github.com/scubafly/drupal-make-files/master/d7.make -y

To jump to understanding what I did, here's what I did:

First I made a list of modules that I always use.
Then based on that list I created a .make file which now sits at https://raw.github.com/scubafly/drupal-make-files/master/d7.make 

And looks like this:
core = 7.x
api = 2

; core
projects[] = drupal
; basic drupal 7 install always needed file with devel included
projects[] = admin_menu
projects[] = ctools
projects[] = devel
projects[] = link
projects[] = mail_logger
projects[] = l10n_client
projects[] = l10n_update
projects[] = backup_migrate
projects[] = entity
projects[] = module_filter
projects[] = pathauto
projects[] = profile2
projects[] = token
projects[] = taxonomy_csv
projects[] = wysiwyg
projects[] = views

So now I can run the following command in the terminal while sitting in the folder where I want my drupal install:
drush make https://raw.github.com/scubafly/drupal-make-files/master/d7.make -y
This will download the latest drupal 7 and modules that where included in the make file.

So yeah thats all fun and all, but still you need to click trough the install and use "drush en module, module, module, module" or manually click to enable all the modules you want for every install.

Creating a profile.

The easiest way to create a profile from scratch is to copy the profile from an existing drupal install.
The install profiles can be found in websitefolder/profiles/<profilename>

profiles are somewhat like modules except they are not, they are profiles :)
Now in the .info file you can define which modules should be enabled. If you look at the standard profile ( websitefolder/profiles/standard/standard.info ) you can see that there are dependencies defined.
for example this is how you would define that devel should be enabled upon installation:
dependencies[] = devel

More information how to create profiles can be found here

I've pushed the profile into github so I can include it in my make file. My profile info looks like this at the moment of writing:
name = Jack standaard
description = basic install profile
core = 7.x

;this is used to enable the modules

; d7.make modules
dependencies[] = admin_devel
dependencies[] = admin_menu
dependencies[] = ctools
dependencies[] = block
dependencies[] = color
dependencies[] = contextual
dependencies[] = dashboard
dependencies[] = dblog
dependencies[] = field
dependencies[] = field_sql_storage
dependencies[] = field_ui
dependencies[] = file
dependencies[] = filter
dependencies[] = help
dependencies[] = image
dependencies[] = list
dependencies[] = locale
dependencies[] = menu
dependencies[] = node
dependencies[] = number
dependencies[] = options
dependencies[] = overlay
dependencies[] = path
dependencies[] = rdf
dependencies[] = search
dependencies[] = shortcut
dependencies[] = system
dependencies[] = taxonomy
dependencies[] = text
dependencies[] = trigger
dependencies[] = update
dependencies[] = user
dependencies[] = devel
dependencies[] = link
dependencies[] = mail_logger
dependencies[] = l10n_client
dependencies[] = l10n_update
dependencies[] = backup_migrate
dependencies[] = entity
dependencies[] = module_filter
dependencies[] = pathauto
dependencies[] = profile2
dependencies[] = token
dependencies[] = taxonomy_csv
dependencies[] = wysiwyg
dependencies[] = views
dependencies[] = views_ui


Since I pushed the whole profile to github ( click the link for details ) I can now include the profile to the make file which then ends up looking like this:

core = 7.x
api = 2

; core
projects[] = drupal
; basic drupal 7 install always needed file with devel included
projects[] = admin_menu
projects[] = ctools
projects[] = devel
projects[] = link
projects[] = mail_logger
projects[] = l10n_client
projects[] = l10n_update
projects[] = backup_migrate
projects[] = entity
projects[] = module_filter
projects[] = pathauto
projects[] = profile2
projects[] = token
projects[] = taxonomy_csv
projects[] = wysiwyg
projects[] = views

; add custom profile
projects[jack_standaard][type] = "profile"
projects[jack_standaard][download][type] = "git"
projects[jack_standaard][download][url] = "git://github.com/scubafly/jack_standaard.git"

make sure u use the git read only link as url that works the best without the need of logging in.

now when you run drush make https://raw.github.com/scubafly/drupal-make-files/master/d7.make -y  the drupal, the modules and the profile will be downloaded. And when you open the webpage you should see the 'jack_standaard' profile as option to install.