/[drupal]/contributions/modules/node_factory/node_factory.module
ViewVC logotype

Diff of /contributions/modules/node_factory/node_factory.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.18, Thu Aug 28 08:59:30 2008 UTC revision 1.1.2.19, Thu Aug 28 10:08:50 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node_factory.module,v 1.1.2.17 2008/08/18 14:50:19 clemenstolboom Exp $  // $Id: node_factory.module,v 1.1.2.18 2008/08/28 08:59:30 clemenstolboom Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 259  function node_factory_nodeapi( &$node, $ Line 259  function node_factory_nodeapi( &$node, $
259  function node_factory_drush_command() {  function node_factory_drush_command() {
260    $item = array();    $item = array();
261    
262    $items['nf create_json'] = array(    $items['nf create json'] = array(
263      'callback' => '_node_factory_create_node_json',      'callback' => '_node_factory_create_node_json',
264      'description' => 'Create a node from the commandline'      'description' => 'Create a node from the commandline'
265    );    );
266    
267    $items['nf create_php'] = array(    $items['nf create xml'] = array(
268        'callback' => '_node_factory_create_node_xml',
269        'description' => 'Not implemented yet. Create a node from based on a var_export structure'
270      );
271    
272      $items['nf create php'] = array(
273      'callback' => '_node_factory_create_node_php',      'callback' => '_node_factory_create_node_php',
274      'description' => 'Not implemented yet. Create a node from based on a var_export structure'      'description' => 'Not implemented yet. Create a node from based on a var_export structure'
275    );    );
# Line 272  function node_factory_drush_command() { Line 277  function node_factory_drush_command() {
277    return $items;    return $items;
278  }  }
279    
280  function _node_factory_create_node_php() {  function _node_factory_iterate( $type, $list) {
281    
282    return;    foreach( $list as $item) {
283        unset($node);
284        switch ($type) {
285            case 'json':
286              $node = json_decode($item, TRUE);
287              break;
288          case 'php':
289            _node_factory_create_php( $item);
290            break;
291          case 'xml':
292            _node_factory_create_xml( $item);
293            break;
294            default:
295            break;
296        }
297    
298        if( is_array($node)) {
299          _node_factory_create_and_save( $node);
300        }
301      }
302  }  }
303    
304  function _node_factory_create_node_json() {  function _node_factory_create_and_save( $node) {
   $nodes = func_get_args();  
   $node =  json_decode($nodes[0], TRUE);  
   
305    $type = $node['type'];    $type = $node['type'];
306    $edit = node_factory_create_node( $type);    $edit = node_factory_create_node( $type);
307    foreach( $node as $field => $value) {    foreach( $node as $field => $value) {
# Line 291  function _node_factory_create_node_json( Line 312  function _node_factory_create_node_json(
312    if( $nid) {    if( $nid) {
313      if( DRUSH_VERBOSE) {      if( DRUSH_VERBOSE) {
314        drush_verbose( t('Node !n of type !t created', array( '!n' => $nid, '!t' => $type)));        drush_verbose( t('Node !n of type !t created', array( '!n' => $nid, '!t' => $type)));
315          $node = node_load( array( 'nid'=>$nid));
316          var_export( $node);
317      }      }
318    }    }
319    else {    else {
320      print_r( 'ERROR');      drush_die( 'Node not saved.');
321    }    }
322    }
323    
324    function _node_factory_create_node_xml() {
325      // xml://path_to_file
326      drush_die( t('Not yet implemented'));
327      return;
328    }
329    
330    function _node_factory_create_node_php() {
331      // php://path_to_file/file_name
332      drush_die( t('Not yet implemented'));
333      return;
334    }
335    
336    function _node_factory_create_node_json() {
337      $nodes = func_get_args();
338      drush_verbose( t('Received @d', array( '@d' => count($nodes))));
339      _node_factory_iterate( 'json', $nodes);
340    
341  }  }

Legend:
Removed from v.1.1.2.18  
changed lines
  Added in v.1.1.2.19

  ViewVC Help
Powered by ViewVC 1.1.2