Wednesday, August 27, 2014

Drupal feeds batch import - Feeds batch process

Feeds module is a one of the best module to import nodes from external URL, xls file or from  xml file, etc..

After creating feeds import for particular action, we can run it via batch process. Like via cron instead of running it manually.

I will create new post to create about feeds import.

Below line of codes worked perfect for one of  my project:

$file = 'your-xml-file.xml';
$my_importer = feeds_source('your_importer_name');
$config = array('FeedsFileFetcher'=>array('source'=>'sites/default/files/' . $file));
$my_importer->addConfig($config);
while (FEEDS_BATCH_COMPLETE != $my_importer->import());

use below link to integrate above batch process via cron.

http://kali-dasan.blogspot.in/2014/08/drush-custom-command-drush-in-our.html

Tuesday, August 19, 2014

Drush custom command - Drush in our custom module

Drush is a very powerful command line tool to manage Drupal site.

Other than core Drush command, we can also write our own custom drush command to perform some task like cron setup, etc, ...

we can do it by using below 3 steps.

Steps :
1) Write hook_drush_help.
2) Write hook_drush_command.
3) Write drush_hook_command.

1) hook_drush_help.
/**
 * Implements hook_drush_help().
 */
function my_module_drush_help($command) {
  switch ($command) {
    case 'drush:test-import':
     return dt('Import test contents.');
  }
}

2) hook_drush_command.
/**
 * Implements hook_drush_command().
 */
function my_module_drush_command() {
  $items = array();
  $items['test-import'] = array(
    'description' => dt('Import test contents.'),
    'arguments'   => array(
      'arg1'    => dt('An optional example argument'),
    ),
    'examples' => array(
      'Standard example' => 'drush test-import',
      'Argument example' => 'drush test-import 5',
    ),
    'aliases' => array('ti'),
  );
  return $items;
}

3) drush_hook_command.
/**
 * Implements drush_hook_command().
 */
function drush_my_module_test_import($arg = NULL) {
  // print arg if any.
  if (isset($arg)) {
   drush_print($arg);
  } 
  drush_log('importing test contents...', 'ok');
}

Now Goto drush command line interface and try > drush test-import or > drush ti