tag:blogger.com,1999:blog-2122386609137532232024-02-08T09:11:16.066-08:00Manoj's BoxManoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-212238660913753223.post-45694766491476347132015-09-19T05:11:00.002-07:002017-06-21T02:13:47.253-07:00Git - Pre commit hook script for PHP & Drupal<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
Introduction</h2>
<div style="box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 16px; line-height: 25.6px; margin-bottom: 16px;">
I think, most of you know about Git repository's support for hooks. One of those hooks is pre-commit, which will be called before whenever a commit is been made. So I have created one Git pre-commit hook script specifically for PHP & Drupal 7 (Can be customized for your purpose as well) git repository. You can fork or download it from <a href="https://github.com/manoj-apare/pre-commit">manojapare/pre-commit</a></div>
<h2 style="border-bottom: 1px solid rgb(234, 236, 239); box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;">
Prerequisite</h2>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<a aria-hidden="true" class="anchor" href="https://github.com/manoj-apare/pre-commit#installation" id="user-content-installation" style="box-sizing: border-box; color: #4078c0; display: block; left: 0px; line-height: 1; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration-line: none; top: 0px;"></a><ol style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px; margin-top: 0px; padding-left: 2em;">
<li style="box-sizing: border-box;">PHP Code Sniffer (phpcs).</li>
<li style="box-sizing: border-box; margin-top: 0.25em;">Coder module - <code style="background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">Drupal</code> code sniffer standard.</li>
</ol>
</h2>
<h2 style="border-bottom: 1px solid rgb(234, 236, 239); box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;">
Installation</h2>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
For using this hook script just copy/download the script file to your git repository hooks folder that is in <code style="background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">.git/hooks/</code>. Don't forget to give executable permission for the script file.</div>
</h2>
<h2 style="border-bottom: 1px solid rgb(234, 236, 239); box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;">
Working</h2>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
Whenever a git commit is been performed, pre-commit hook script will be executed by git inbuilt hook support. The above script does syntax check, any debugging function, merge conflict tags as well as looks for coding standard in the changes staged to commit (which is a bad practice). In any case, the commit operation will be aborted and can be committed after doing corrections or removing the debugging function xfrom the code.</div>
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
In case you want to force commit with any debugging functions (not recommended) you can do it by using the git command option <code style="background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">-n OR --no-verify</code>.</div>
</h2>
<h3 style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px;">
Syntax check</h3>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
Syntax check is been performed using <code style="background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">php -l</code> command for each php files (file with extensions 'php, inc and module').</div>
</h2>
<h3 style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px;">
Check for debugging functions</h3>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
Checking for debugging function is been performed using <code style="background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">git diff</code> command only to files staged to commit and in turn only to added/modified changes.</div>
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
List of debugging functions included for checking are: dpm, dpq, dvm, ddebug_backtrace, print_r, var_dump, debug_backtrace, console.log. First 4 functions are of Drupal devel module, later 3 are of php and last one is of javascript.</div>
</h2>
<h3 style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px;">
Merge conflict marker check</h3>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
Merge conflict marker check is been performed to all files staged to commit using egrep pattern "(<<<<|====|>>>>)+.*(\n)?".</div>
</h2>
<h3 style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px;">
Coding standard check</h3>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px;">
Checks for coding standard issues using <code style="background-color: rgba(27, 31, 35, 0.05); border-radius: 3px; box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">phpcs</code> with arguments:</div>
<ol style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal; margin-bottom: 16px; margin-top: 0px; padding-left: 2em;">
<li style="box-sizing: border-box;">standard = Drupal</li>
<li style="box-sizing: border-box; margin-top: 0.25em;">extensions = 'php,module,inc,install,test,profile,theme,js,css,info,txt'</li>
</ol>
</h2>
<h2 style="border-bottom: 1px solid rgb(234, 236, 239); box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;">
<a aria-hidden="true" class="anchor" href="https://github.com/manoj-apare/pre-commit#note" id="user-content-note" style="box-sizing: border-box; color: #0366d6; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;"></a>Note</h2>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif; font-size: 1.75em; line-height: 1.225; margin-bottom: 16px; margin-top: 1em; padding-bottom: 0.3em; position: relative;">
<div style="box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; font-weight: normal;">
For better performance of the script, we have excluded the checking of files with following extensions: 'info, png, gif, jpg, ico, patch, htaccess, sh, ttf, woff, eot, svg'. Also excluded files residing in the following directories: 'features, contrib, devel, libraries'.</div>
</h2>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-2836400555252976792015-07-09T08:00:00.003-07:002015-07-09T08:00:14.865-07:00How to create html mail template for Drupal?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
In Drupal 7 by default we can't send html mail, since Drupal will convert all emails to plain text before sending. This could be overridden using Drupal 7<i style="box-sizing: border-box;">htmlmail</i> contributed module. We may also need i>mailsystem module for implementing <i style="box-sizing: border-box;">htmlmail</i>, which is a dependency. The module also give html mail template, which could be customized as well in same way of theme templates.</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Firstly, we can look on the configuration details and then theming of html template mail. If there is a need to make the html template for a particular mail with module name and with a particular mail key then we have to create a new settings in '<i style="box-sizing: border-box;">admin/config/system/mailsystem</i>' namely module_name and key_name respectively. After saving the new settings we have to set '<i style="box-sizing: border-box;">HTMLMAILSystem</i>' for the new '<i style="box-sizing: border-box;">Mail System Settings</i>'. Next in <i style="box-sizing: border-box;">htmlmail</i> configuration '<i style="box-sizing: border-box;">admin/config/system/htmlmail</i>'</div>
<ul style="background-color: white; box-sizing: border-box; color: #5a5a5a; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 20px; margin-bottom: 10px; margin-top: 0px;">
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">step-1:</span> List of available templates and descriptions.</li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">step-2:</span> Email theme, where the above custom template will hold.</li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">step-3:</span> Post-filtering, text format used for filtering the mail.</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Find out the template file which meets your need and copy paste them to your theme template and specify it in above config page.<br style="box-sizing: border-box;" />Now theme the copy of mail template as you wish. That's all and you have completed with your config and theming of html mail template.</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Using the help of Drupal functions like drupal_mail we can send mail using the '<i style="box-sizing: border-box;">htmlmail</i>' module template.<br style="box-sizing: border-box;" />We need to specify the module name and key according to template file we use.<br style="box-sizing: border-box;" />Let us assume, if we use '<i style="box-sizing: border-box;">htmlmail--module_name--key_name.tpl.php</i>' template then drupal_mail call be as below to use this template for the same.</div>
<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; width: 699px; word-break: break-all; word-wrap: break-word;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">
$module = 'module_name';
$key = 'key_name';
$to = $user->mail;
$language = language_default();
$name = $user->name;
$params = array();
$from = 'no-reply@gmail.com';
drupal_mail($module, $key, $to, $language, $params, $from);
</code></pre>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Also it will be a good practice to add hook_mail(), if we call drupal_mail with in our module.<br style="box-sizing: border-box;" />Hope this article about html template mail for Drupal 7 helped you.</div>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-86214296482114540642015-07-09T07:58:00.001-07:002015-07-09T07:58:42.875-07:00How to write MySql single export query<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 class="page-header" style="background-color: white; border: none; box-sizing: border-box; color: #333399; font-family: Abel; font-size: 40px; line-height: 50px; margin: 0px; padding-bottom: 9px;">
<span style="color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; font-weight: normal; line-height: 28.6667px; text-align: justify;">We as a PHP Drupal web platform developer most often has to face the situation to export data from one table to another table of same database or to table of another database (if site uses multiple databases) during the process of any change in normal work flow.</span></h1>
<div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Most of us normally think to export the data from one table to another by firstly querying the required data from source table and then looping through the query result and inserting them to destination table. This can be simply achieved with a single query.</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Major drawback of this is that first select query has to be compiled and run in MySQL server then for each query result front-end server has to loop through it and return the corresponding insert query to MySQL, which in turn has to compile and run for each iteration. If lakhs of data is to be exported, then this will be a huge load for front end server.</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Let me tell you another option. The single query export approach:</div>
<ol style="background-color: white; box-sizing: border-box; color: #5a5a5a; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 20px; margin-bottom: 10px; margin-top: 0px;">
<li style="box-sizing: border-box;">If the source table and destination table are both in same database.<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; width: 659px; word-break: break-all; word-wrap: break-word;"> <code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">
$query = db_query(
"INSERT INTO `destination_table_name` (`title`, `uid`, `created`)
SELECT title, uid, created
FROM `source_table_name`
ORDER BY created DESC
);
</code>
</pre>
</li>
<li style="box-sizing: border-box;">If the source table and destination table are in different database, namely source table is in database_1 and destination table is in database_2.<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; width: 659px; word-break: break-all; word-wrap: break-word;"> <code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">
$query = db_query(
"INSERT INTO `database_2.destination_table_name` (`title`, `uid`, `created`)
SELECT title, uid, created
FROM `database_1.source_table_name`
ORDER BY created DESC
);
</code>
</pre>
</li>
</ol>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Normally this seems weird, but its the real trick. Avoiding of multiple compilation of query in MySQL server and looping in front-end server. Hope this helps!</div>
</div>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-16657279706725397232015-05-23T06:48:00.002-07:002015-09-19T04:53:03.381-07:00Puzzle<div dir="ltr" style="text-align: left;" trbidi="on">
One day I got crazy sloving picture/number grid puzzle available in windows desktop gadget. Then suddenly why I can't try create the same puzzle of my own using html, js & css and the result is what you are seeing.<br />
<iframe allowfullscreen="allowfullscreen" frameborder="0" height="600" src="//jsfiddle.net/manojapare/8Q5MS/embedded/result" width="100%"></iframe>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-76021215613397456102015-05-23T06:45:00.000-07:002015-05-23T06:45:09.170-07:00Getting started with CiviCRM<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="field field-name-body field-type-text-with-summary field-label-hidden" style="background-color: white; box-sizing: border-box; color: #5a5a5a; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 20px; margin-bottom: 25px;">
<div class="field-items" style="box-sizing: border-box;">
<div class="field-item even" style="box-sizing: border-box;">
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
FSF-CiviCRM is a popular Customer Relationship Management (CRM) system. The first step in getting started is understanding the CiviCRM codebase. For better understanding, please download CiviCRM zip file from <a href="https://civicrm.org/download" style="background: 0px 0px; box-sizing: border-box; color: #993399; text-decoration: none;">https://civicrm.org/download</a> and install.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
Object Oriented Programming</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
CiviCRM core is built using OOP singleton concept. Singleton framework is one which initiates one class object only once and reuses it afterwards.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
Business logic</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
CiviCRM business logic is handled in directory 'CRM/' in the root of CiviCRM installation. In this directory, you can see core functionalities such as Groups, Contacts, Profiles etc. Each of them inturn has directories named DAO, BAO, Form, Page etc.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
DAO</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
DAO stands for Data Access Object, which acts as wrapper layer around database. It is recommended to use DAO to interact/manage database data.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
BAO</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
BAO is abbreviation of Business Access Object. Actually, BAO is used to extend the DAO for handling business logic.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
Form</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Form in CiviCRM is implemented as a class extending CRM_Core_Form, which is done using the following methods: preProcess - retrieve data before processing form, buildForm - generate html form using QuickBuildForm helper functions, formRule - form validation rules and postProcess - form subit handler. Also, there will be separate template for each form, which can be found in 'templates/Form/' directory.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
Page</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
If the screen isn't Form, it will be Page. Page is also class similar to Form extended from CRM_Core_Page. The methods available for Page preProcess, run - which displays the page content. Template for the page can be found in the directory 'templates/Page/'.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
xml</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
xml directory contains menu structure of urls mapping to CRM form or page classes and controls access to these URLs using permissions.</div>
<h4 style="box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
Templates</h4>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Directory which contains templates of Form, Page etc.</div>
<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Go through the CiviCRM core for better understanding. Also, before starting work on CiviCRM, please post your plan of work to <a href="http://forum.civicrm.org/" style="background: 0px 0px; box-sizing: border-box; color: #993399; text-decoration: none;">civicrm forum</a> OR consult other developers instantly on <a href="http://irc.civicrm.org/" style="background: 0px 0px; box-sizing: border-box; color: #993399; text-decoration: none;">CiviCRM IRC</a></div>
</div>
</div>
</div>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-21046063750070106502015-05-02T10:12:00.001-07:002015-07-09T08:05:01.196-07:00Geany editor snippets for Drupal<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 class="page-header" style="background-color: white; border: none; box-sizing: border-box; color: #333399; font-family: Abel; font-size: 40px; line-height: 50px; margin: 0px; padding-bottom: 9px;">
<span style="font-weight: normal;"><span style="color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; text-align: justify;">This article discuss about setting snippets for Geany, a light weight IDE especially for Drupal 7 web developers as per </span><a href="https://drupal.org/coding-standards/docs" style="background: 0px 0px; box-sizing: border-box; color: #993399; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; text-align: justify; text-decoration: none;">coding standards</a><span style="color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; text-align: justify;">. For those whom doesn't know, snippets are a small piece of source code which are meant for reuse. For example: while coding instead of typing full if conditional statement structure for each time we can just reuse them by the means of creating snippet for the same.</span></span></h1>
<div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Creation of snippet is simple as like coding in any language. Before implementing custom snippets for Drupal 7 as per coding satandard we have to study about geany snippets.conf file structure, which can be found in '/home/user/.config/geany'.<br />
Firstly we can look on the keywords available</div>
<ol style="background-color: white; box-sizing: border-box; color: #5a5a5a; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 20px; margin-bottom: 10px; margin-top: 0px;">
<li style="box-sizing: border-box;">'\n' OR '%newline%': Used for new line.</li>
<li style="box-sizing: border-box;">'\t' OR '%ws%': Used for one indentation step.</li>
<li style="box-sizing: border-box;">'\s': Used for white space.</li>
<li style="box-sizing: border-box;">'%key%': Keys defined in special section.</li>
<li style="box-sizing: border-box;">'%cursor%': Defines where the cursor has to be placed. We can use multiple cursors in one snippet and can be jumped to next cursor position by using 'Move snippet cursor' keybinding.</li>
</ol>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Now we can look on important sections available in snippets.conf file.</div>
<ul style="background-color: white; box-sizing: border-box; color: #5a5a5a; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 20px; margin-bottom: 10px; margin-top: 0px;">
<li style="box-sizing: border-box;">Default is where we define snippets for files type other than the defined or known file types.</li>
<li style="box-sizing: border-box;">Special is where we can define our own special configuration keywords like<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><br style="box-sizing: border-box;" /></code>
<br />
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;"># special keys to be used in other snippets, cannot be used "standalone"</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;"># can be used by %key%, e.g. %brace_open%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;"># nesting of special keys is not supported (e.g. brace_open=\n{\n%brace_close% won't work)</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;"># key "wordchars" is very special, it defines the word delimiting characters when looking for</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;"># a word to auto complete, leave commented to use the default wordchars</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">[Special]</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">brace_open=\s{\n\t</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">brace_close=}\n</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">brace_close_cursor=\n\t%cursor%\n}%cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">block=\s{\n\t%cursor%\n}</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">block_cursor=\s{\n\t%cursor%\n}%cursor%</span></code></div>
</div>
</li>
<li style="box-sizing: border-box;">Keybindings is where we can define keybindings or keyboard shortcut for snippets defined.<div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><br style="box-sizing: border-box;" /># Optional keybindings to insert snippets<br style="box-sizing: border-box;" /># Note: these can be overridden by Geany's configurable keybindings<br style="box-sizing: border-box;" />[Keybindings]<br style="box-sizing: border-box;" />#for=7</code></div>
</li>
<li style="box-sizing: border-box;">PHP is where we define snippets for php files.</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
For Drupal 7 snippets, we have to define snippets in php section like:</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><br style="box-sizing: border-box;" />[PHP]</code><br />
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">if=// Documentation.\nif (%cursor%)%block_cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">els=else%brace_open%// Documentation.%brace_close_cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">eli=elseif (%cursor%)%brace_open%// Documentation.%brace_close_cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">whi=// Documentation.\nwhile (%cursor%)%block_cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">do=// Documentation.\ndo%block% while (%cursor%);%cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">swi=// Documentation.\nswitch (%cursor%)%brace_open%case %cursor%:\n\t\t%cursor%\n\t\tbreak;\n\tdefault:\n\t\t%cursor%\n}%cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">try=// Documentation.\ntry%block%\ncatch (%cursor%)%brace_open%// Documentation.%brace_close_cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">for=// Documentation.\nfor (%cursor%; %cursor%; %cursor%)%block_cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">fun=\n/**\n * Documentation.\n */\nfunction %cursor%(%cursor%)%block_cursor%</span><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">arr=array(\n\t%cursor%\n)%cursor%</span></code></div>
<div style="text-align: left;">
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.6000003814697px; padding: 2px 4px;"><span style="font-size: 12.6000003814697px; line-height: 28.6667px;">foe=// Documentation.\nforeach (%cursor% as %cursor% => %cursor%)%block_cursor%</span></code></div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
You can try these by copy and paste on snippets.conf file's PHP section. Save the file and type if and press tab to see the geany snippets magic. The following will create if conditional statement structure and cursor will be focused on first '%cursur%', to move next step press the keyboard shortcut for 'Move snippet cursor' which can be set in edit -> preferences -> keybindings -> editor Action section. In these snippets definition you have noticed the special keywords such as '%brace_open%', '%brace_close%' and '%block%' which are defined in Special section as explained above.</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
<span style="line-height: 28.6667003631592px;">Like this you can create or customize already available snippets. Firstly using snippets take time, gradually on practice these will reduce the time of development. Hope this will help you using geany editor for Drupal development.</span></div>
</div>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-46467741822466890042015-05-02T10:07:00.000-07:002015-07-09T08:04:43.410-07:00Set up Authorize.Net ARB to work with Drupal commerce<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 class="page-header" style="background-color: white; border: none; box-sizing: border-box; color: #333399; font-family: Abel; font-size: 40px; line-height: 50px; margin: 0px; padding-bottom: 9px;">
<span style="color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; font-weight: normal; line-height: 28.6667px; text-align: justify;">Authorize.net is a popular alternative to Paypal for eCommerce websites especially its recurring transaction product - Authorize.net ARB (Automated Recurring Billing). Drupal support for Authnet ARB is available through Ubercart but it is not available for Drupal_commerce. However there is a workaround to setup Authorizet.net ARB to work with Drupal commerce. Read on to know more.</span></h1>
<div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
There is no Authorize.net ARB module for Drupal commerce but there is a sandbox module - <a href="https://www.drupal.org/sandbox/vlkff/1572412" style="background: 0px 0px; box-sizing: border-box; color: #993399; text-decoration: none;">Authnet ARB</a> This module does not work straight out of box but you need to make a few changes. But before that lets get familiar with the module</div>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Drupal authnet_arb sandbox module uses authorize.net SDK for ARB API request, so we have to install the sdk for using this module. First of all we can look on what else features the authnet_arb module provide and then we can look on how to integrate it with drupal commerce.</div>
<h4 style="background-color: white; box-sizing: border-box; color: #1a1a1a; font-family: Abel; font-size: 18px; font-weight: 500; line-height: 1.1; margin-bottom: 5px; margin-top: 10px; padding-bottom: 0px;">
Features provided by authnet_arb module.</h4>
<ol style="background-color: white; box-sizing: border-box; color: #5a5a5a; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 20px; margin-bottom: 10px; margin-top: 0px;">
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">Payment method for ARB:</span><br style="box-sizing: border-box;" />The sandbox module provides an additional payment method named <i style="box-sizing: border-box;">'Recurring payments with Authorize.Net ARB (with credit card)'</i> along with default drupal commerce payement methods. Enabling this payment method, we get an option for choosing <i style="box-sizing: border-box;">'Recurring payments'</i> method of payment in drupal commerce payment form.<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; width: 659px; word-break: break-all; word-wrap: break-word;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">
/**
* Implements hook_commerce_payment_method_info().
*/
function authnet_arb_commerce_payment_method_info() {
$payment_methods = array();
$payment_methods['authnet_arb'] = array(
'base' => 'authnet_arb',
'title' => t('Recurring payments with Authorize.Net ARB (with credit card)'),
'short_title' => t('Authorize.Net ARB CC'),
'display_title' => t('Recurring payments'),
'description' => t('Integrates Authorize.Net ARB for transactions.'),
'callbacks' => array(
'settings_form' => 'authnet_arb_commerce_settings_pane',
'submit_form' => 'authet_arb_payment_pane',
'submit_form_submit' => 'authet_arb_payment_pane_submit',
'submit_form_validate' => 'authet_arb_payment_pane_validate',
),
'file' => 'commerce.inc',
);
return $payment_methods;
}
</code></pre>
</li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">Silent post URL:</span><div style="box-sizing: border-box; color: #363636; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Silent post is the feature provided by Authorize.Net, which will post a http request to our domain silent url (which we need to configure in Authorize.Net account settings page) with the transaction details of ARB subscriptions payement as xml. Using this we can listen to the post request coming to our drupal site and do necessary business logic according to transaction status details.</div>
<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; width: 659px; word-break: break-all; word-wrap: break-word;"><code style="background-color: transparent; border-radius: 0px; box-sizing: border-box; color: inherit; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; white-space: pre-wrap;">
/**
* Implements hook_menu().
*/
function authnet_arb_menu () {
$items = array();
$items['authnet-arb-silentpost'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'authnet_arb_silentpost',
'access callback' => TRUE,
);
return $items;
}
</code></pre>
</li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">Authnet ARB settings:</span><br style="box-sizing: border-box;" />Admin config page for setting the API <i style="box-sizing: border-box;">login Id</i> and <i style="box-sizing: border-box;">transaction key</i>. This form also provide an option for sandbox transactions, which will be more useful while testing.<br style="box-sizing: border-box;" /><img alt="Authnet_ARB_part_1_img1.png" src="http://cdn3.zyxware.com/files/u1/images/2014/03/Authnet_ARB_part_1_img1.png" height="522" style="border: 0px; box-sizing: border-box; vertical-align: middle;" width="650" /></li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">ARB Subscription cancellation form:</span><br style="box-sizing: border-box;" />Using this subscribers can cancel their ARB subscription any time they want.</li>
</ol>
<div style="background-color: white; box-sizing: border-box; color: #363636; font-family: 'Open Sans', sans-serif; font-size: 14px; line-height: 28.6667px; margin-bottom: 10px; text-align: justify;">
Since we are now familiar with the module, lets get to work on those changes to make this module production ready.<br />
<h3>
Making production ready</h3>
<div>
<div style="box-sizing: border-box; line-height: 28.6667px; margin-bottom: 10px;">
Before integration we have make some hack on the sandbox module to make it effectively work with drupal_commerce and bug free.</div>
<div style="box-sizing: border-box; line-height: 28.6667px; margin-bottom: 10px;">
In Drupal organization hacking module and generating a patch is more oftenly done by all drupal contributors.<br />
Basically to be a good drupal contributor before hacking a set of code we need to have clear idea of what is the cause of problem and why we need to fix it. Hence we can look on the problem, whenever creating ARB subscription or an API request is been to happen SDK will check for sandbox boolean value is true or false. Since <span style="box-sizing: border-box; font-weight: 700;"><i style="box-sizing: border-box;">authnet_arb</i></span> is a sandbox module its not checking whether the payment method is been set as sandbox and then set the SDK sandbox boolean as proper. So we have to hack the sandbox module for this to work properly before each API request is to created or generated. Here come the sample code needed to set sandbox boolean of SDK.</div>
<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; text-align: start; width: 699px; word-break: break-all; word-wrap: break-word;"> $request = new AuthorizeNetARB($settings['login'], $settings['tran_key']);
if ($settings['sandbox']) {
$request->setSandbox(TRUE);
} else {
$request->setSandbox(FALSE);
}
</pre>
<div style="box-sizing: border-box; line-height: 28.6667px; margin-bottom: 10px;">
Another feature we needed while implementing Authorize.Net ARB is the option for update subscription details such as credit card. <span style="box-sizing: border-box; font-weight: 700;"><i style="box-sizing: border-box;">authnet_arb</i></span> sandbox module doesn't provide this update feature, instead they says it need to be implemented. Here I havehack that also as follow:</div>
<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; line-height: 1.42857143; margin-bottom: 10px; overflow: auto; padding: 9.5px; text-align: start; width: 699px; word-break: break-all; word-wrap: break-word;"> function authnet_arb_update_subscription ($update_values) {
$settings = authnet_arb_settings();
require_once authnet_arb_sdk_path().'/AuthorizeNet.php';
$subscription = new AuthorizeNet_Subscription;
$subscription->billToFirstName = $update_values['first_name'];
$subscription->billToLastName = $update_values['last_name'];
$subscription->billToAddress = $update_values['thoroughfare'] . ' ' . $update_values['premise'];
$subscription->billToCity = $update_values['locality'];
$subscription->billToState = $update_values['administrative_area'];
$subscription->billToZip = $update_values['postal_code'];
$subscription->billToCountry = 'US';
$subscription->creditCardCardNumber = $update_values['card_number'];
$subscription->creditCardExpirationDate = $update_values['expiration_date'];
$request = new AuthorizeNetARB($settings['login'], $settings['tran_key']);
if ($settings['sandbox']) {
$request->setSandbox(TRUE);
} else {
$request->setSandbox(FALSE);
}
$response = $request->updateSubscription($update_values['subscription_id'], $subscription);
return $response;
}
</pre>
<div style="box-sizing: border-box; line-height: 28.6667px; margin-bottom: 10px;">
There is one more feature need to implement delete subscription. That you can try. That's all enjoy coding and hacking.</div>
</div>
</div>
</div>
</div>
Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0tag:blogger.com,1999:blog-212238660913753223.post-53836178024197337962012-03-19T01:44:00.002-07:002012-03-19T01:52:13.519-07:00Rails 3: Memcached server<div dir="ltr" style="text-align: left;" trbidi="on">Rails 3 uses :cookie_store as its default way of storing session values i.e., the session variables are stored in client side browser cookies. So even after the server is restarted the previous session variables persists. To avoid this I used memcached server for rails 3 session store.<br />
<br />
Steps for using :memcache_store in rails 3:<br />
1. Install memcached server of 1.4.x or higher version, for installation refer <a href="http://lang-asa.blogspot.in/2010/02/memcached-on-mac-and-windows-7.html">http://lang-asa.blogspot.in/2010/02/memcached-on-mac-and-windows-7.html</a>.<br />
<br />
2. Add gem 'dalli' in gemfile and run bundle install.<br />
<br />
3. Replace the line on config/initializers/session_store.rb<br />
SampleApp::Application.config.session_store :cookie_store<br />
with this line<br />
SampleApp::Application.config.session_store :dalli_store<br />
<br />
4. Add these lines to config/environment.rb<br />
require 'action_dispatch/middleware/session/dalli_store'<br />
CACHE = Dalli::Client.new(:namespace => "SampleApp", :memcache_server => ['127.0.0.1:11211'])<br />
<br />
5. Now start the memcached server installed on your machine.<br />
<br />
Success!, now you are ready to run the Rails 3 application.<br />
<br />
If you are wishing to deploy the application to heroku, just refer this <a href="http://devcenter.heroku.com/articles/memcache">http://devcenter.heroku.com/articles/memcache</a></div>Manoj Khttp://www.blogger.com/profile/01262122521251018670noreply@blogger.com0