Posts

Showing posts from 2017

Set up Drupal7 to Drupal8 migration in simple steps (using Drush)

Step1: Download Drupal8 and its dependencies using composer Note: Drush8 is needed for migrate_upgrade module to execute. migrate_upgrade is not working with Drush9. >sudo composer create-project drupal-composer/drupal-project:~8.4 migrate843 --stability dev --no-interaction This will install drush and drupal-console Reference: https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies Step2: Install Drupal using Drush > sudo ../vendor/bin/drush site-install --db-url=mysql://username:password@host/dbname Step3: Enable migration related modules drush en migrate drush en migrate_drupal drush en migrate_tools drush en migrate_plus drush en migrate_upgrade Step4: Now run the migration. -- configure - only  option, which instead of running the migration will generate migration configuration entities, which may then be edited to customize the migration path and run using the  migrate_tools module ...

Drupal general concepts that you should know

Image
namespace: In simple terms,  think of a namespace as a person's surname . If there are two people named "John" you can use their surnames to tell them apart. https://stackoverflow.com/questions/3384204/what-are-namespaces Solve the issues of resuable code such as classes or functions. namespace example: the file  foo.txt  can exist in both directory  /home/greg  and in  /home/other , but two copies of  foo.txt  cannot co-exist in the same directory. In addition, to access the  foo.txt  file outside of the  /home/greg  directory, we must prepend the directory name to the file name using the directory separator to get  /home/greg/foo.txt . This same principle extends to namespaces in the programming world. Avoids namespace collisions Name collisions example:  you create a function named db_connect, and somebody elses code that you use in your file (i.e. an include) has the same functio...

Install Drush 8.x on Ubuntu 16.04

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"  mv composer.phar /usr/local/bin/composer composer vim ~/.bashrc Add this => export PATH="$HOME/.composer/vendor/bin:$PATH" and ~/.bashrc source  ~/.bashrc composer global require drush/drush:8.x drush --version drush 7 version install ================ composer global require  drush / drush :7.1.0  export PATH="/root/.composer/vendor/b in:$PATH"

What GIT submodule update does

Your main project points to a particular commit that the submodule should be at. What  git submodule update  does is to try to checkout that commit in each submodule that has been initialized. The submodule is really an independent repository - just creating a new commit in the submodule and pushing that isn't enough, you also need to explicitly add the new version of the submodule in the main project. So, in your case, you should find the right commit in the submodule - let's assume that's the tip of master: cd mod git checkout master git pull origin master Now go back to the main project, stage the submodule and commit that: cd .. git add mod git commit -m "Updating the submodule 'mod' to the latest version" Now push your new version of the main project: git push origin master From this point on, if anyone else updates their main project, then  git submodule update  for them will update the submodule, assuming it's been initialized.

Docker

# Backup docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql # Restore cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE #create a container and link sudo docker run --name wordpress -p 8080:80 --link db_container -d wordpress here db_container is a database container

Saucelabs integration with codeception/codeceptjs

Some notes; 1. How to run Saucelabs proxy connect bin/sc -u YOUR_USERNAME -k YOUR_ACCESS_KEY bin> ./sc  YOUR_USERNAME -k YOUR_ACCESS_KEY

API.AI

some notes: There are official SDKs such as nodejs, python, HTML+javascript, Andriod Chatbot is called Agent. There are many prebuilt Agents available. Agent can be embed code in iframe. Example chatbot client: http://miningbusinessdata.com/adding-faq-chatbot-to-your-wordpress-site-using-api-ai/

Code quality analysis of Drupal. Can I use Sonar?

For better understanding: https://docs.acquia.com/article/tools-analyzing-your-drupal-codebase Following artcle my experience with Sonar and  Drupal. https://docs.sonarqube.org/display/PLUG/SonarPHP has following number of rules. Sonarway (for PHP) has following number of rules 1. Bug:15 2. Vulnerability:3 3. Code smell:45 Drupal has following number of rules 1. Bug: 3 2. Vulnerability: 0 3. Code smell: 10 Its possible that you can define following inheritance in Quality profile. For example: Sonarway=>Drupal Drupal uses PHPCodeSniffer (Drupal standards) or Coder to verify its coding standards. Both of them dont have integration with Sonar. 3. Sonar comes up with some Drupal Coding Standards. But is is not same as what we do in PHPCodeSniffer and Coder. 4. It's still better to fix critical / blocker issues from Sonar Way and Drupal Quality profiles. Its best to use PHPCodeSniffer with Drupal standards and  some repor...

Sonar Installation and using with a project

The below instruction is to run in MAC. Installation of Sonar 5.6.6 Download sonarqube and extract. > cd sonarqube-5.6.6/bin/macosx-universal-64 start sonar > ./sonar.sh console Installing sonar scanner 1. Download sonar scanner sonar-scanner-3.0.3.778-macosx 2. Add the following in ~/.bash_profile export SONAR_RUNNER_HOME="/Users/gopi/Downloads/sonar-scanner-3.0.3.778-macosx" export PATH="/Users/gopi/Downloads/sonar-scanner-3.0.3.778-macosx/bin:$PATH" 3. refresh bash profile > source ~/.bash_profile Running sonar scanner go to your projects folder where you have source code to analyze 1. Create a file sonar-project.properties with following contents # This file is used by sonar-runner # # Required metadata sonar.projectKey=myproject sonar.projectName=custom modules only, features excluded sonar.projectVersion=1.0 # Comma-separated paths to directories with sources (required) sonar.sources=. sonar.exclusions=jquery*,note...

Behat Integration with Drupal using drupalextension module

Follow the http://behat-drupal-extension.readthedocs.io/en/3.1/requirements.html for requirements and run the Selenium server $ mkdir /Users/gopi/behat $  cd /Users/gopi/behat $ curl http://getcomposer.org/installer | php Composer (version 1.3.2) successfully installed to: /Users/gopi/behat/composer.phar Use it: php composer.phar $ sudo vim composer.json {   "require": {     "drupal/drupal-extension": "~3.0" },   "config": {     "bin-dir": "bin/"   } } save the above code in composer.json $ php composer.phar install $ sudo vim behat.yml default:   suites:     default:       contexts:         - FeatureContext         - Drupal\DrupalExtension\Context\DrupalContext         - Drupal\DrupalExtension\Context\MinkContext         - Drupal\DrupalExtension\Context\MessageContext         - Drupa...

Bash Profile

Example bashprofile: > sudo vim  /Users/myname/.bash_profile export PATH=/usr/local/opt/openssl/bin:$PATH export PATH=/usr/local/git/bin:$PATH export PATH=/Applications/MAMP/bin/php/php5.5.26/bin:$PATH #export PATH="$HOME/.composer/vendor/bin:$PATH" export PATH="$PATH:$HOME/.composer/vendor/bin" alias drupalcs="phpcs --standard=Drupal --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt'" alias drupalcbf="phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md"

Overriding Drupal JS function on the fly

Sometimes it is necessary that we solve some JS issues without making new deployment in production. Following example overrides the viewScrollTop JS function (originates from views module). The following code has to be added in AddToHead module of Drupal in the page-bottom section. <script> (function(Drupal, $) {     Drupal.ajax.prototype.commands.viewsScrollTop = function (ajax, response, status) {  // Scroll to the top of the view. This will allow users  // to browse newly loaded content after e.g. clicking a pager  // link.  var offset = $(response.selector).offset();  // We can't guarantee that the scrollable object should be  // the body, as the view could be embedded in something  // more complex such as a modal popup. Recurse up the DOM  // and scroll the first element that has a non-zero top.  var scrollTarget = response.selector;  while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).p...

General Knowledge Base

Bash: cmd.exe C:\xampp\mysql\bin mysql -u root -p --force test2 < C:\Users\rgopi\Downloads\test.sql Ajax:  If you want to do ajax actions on form elements, attach #ajax property in form field definitions. For example, when you use #ajax in an select field, #ajax automatically adds onChange() event to ajax. #ajax support following important parameters #ajax['callback'] => The callback is a function which returns a renderable array which consists of html or ajax commands. #ajax['wrapper']: The CSS ID of the area to be replaced by the content returned by the #ajax['callback'] function. The content returned from the callback will replace the entire element named by #ajax['wrapper']. The wrapper is usually created using #prefix and #suffix properties in the form. Ajax in menu callbacks: If you want to perform ajax actions on menu call backs. Use ajax_deliver. It packages and sends the result of a page callback as an A...