Articles

×

Error message

User warning: The following module is missing from the file system: expose_table. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1143 of /home/deb116182/domains/van-ettinger.nl/public_html/includes/bootstrap.inc).

This page is mainly my notebook of usefull snippets of code. Whenever I come across something usefull or come up with something usefull I will post it here.
To be able to reuse it later and to share.

RSS

Local settings

To import local settings into settings.php:

 

if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php')) {
  include DRUPAL_ROOT . '/' . conf_path() . '/settings.local.php';
}

Password generator function

/**
* @param int $min_length
* @param null $characters
* @return string
*/
function _password_generator($min_length = 8, $characters = NULL) {
  $password = '';
  if (is_null($characters)) {
    $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()';
  }
  for ($i=0;$i<$min_length;$i++) {
    $pos = rand(0,(strlen($characters)-1));
    $password .= $characters[$pos];
  }
  return $password;

How to copy hidden files on linux

Sometimes we need to copy a bunch of files from one directory to another on our *nix environment. 
We all know the cp command and use this in these situations. However often directories will contain hidden files or "dot files" such as .htaccess or .git.

To copy these files aswell we need to perform some matching:

cp -r SOURCEDIR/.[a-zA-Z0-9]* TARGETDIR

This will copy the hidden files in most cases.

Custom tables and their queries

Sometimes we need to put data in a custom table in drupal. Usually when this happens we also need to do some fancy queries on these tables.
The db_select function is usually the starting point here, and with methods like join() and condition() and fields() we are able to fetch most of the data.
 

The other day I needed to get data that was between certain dates. Here is what I did: