Blogs

Drupal 7 node creation programmatically

  $node = new stdClass();
  $node->title = "TITLE";
  $node->type = "NODE_TYPE";
  node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  $node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
  $node->uid = $user->uid; 
  $node->status = 1; //(1 or 0): published or not
  $node->promote = 0; //(1 or 0): promoted to front page
  $node->comment = 1; // 0 = comments disabled, 1 = read only, 2 = read/write

  // Term reference (taxonomy) field

Docker set up on linux mint

Install docker

$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
$ sh -c 'echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list'
$ sudo apt-get update
$ sudo apt-get purge lxc-docker
$ sudo apt-get install linux-image-extra-$(uname -r)
$ sudo apt-get install docker-engine
$ sudo service docker start
$ sudo usermod -aG docker $USER

Install docker-compose

Linux basic commands

Check size directories

$ du -sh *

Search file

$ sudo find [path] -name "[filename]"

Unzip tar.gz using tar command

$ tar -xvzf filename.tar.gz

f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
z: tells tar to decompress the archive using gzip
x: tar can collect files or extract them. x does the latter.

Drush export/import database

Drupal 6 and 7

$ drush cc
$ drush sql-dump > ~/my-sql-dump-file-name.sql

Drupal 8

$ drush cr
$ drush sql-dump > ~/my-sql-dump-file-name.sql

Download Database from the server

$ scp username@example.com:~/my-sql-dump-file-name.sql ~/projects

Import Database

$ drush sql-drop
$ drush sql-cli < ~/my-sql-dump-file-name.sql

Set up my local environment using Linux-mint

Install GIT

$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git

set up your email and username

$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"

Install Sublime

Open a terminal with Ctrl+Alt+T and type:

$ sudo add-apt-repository ppa:webupd8team/sublime-text-2
$ sudo apt-get update

Optional: remove any installed Sublime Text packages: