A
A
Albert Tobacco2014-10-23 17:34:29
Drupal
Albert Tobacco, 2014-10-23 17:34:29

When saving a node programmatically pathouto(). What could be the problem?

I am writing a module for parsing rss. Everything works, and the CNC link is obtained but gives two warnings.

Warning: Illegal offset type in isset or empty in pathauto_cleanstring() (line 180 of /home/dev/public_html/sites/all/modules/pathauto/pathauto.inc).
Warning: Illegal offset type in pathauto_cleanstring() (line 223 of /home/dev/public_html/sites/all/modules/pathauto/pathauto.inc).

here is the node save function
function _wfp_rssparse_savenode($data){

    $node = new stdClass();
 	$node->type = 'wbf_rssparse';
 	$node->language = LANGUAGE_NONE;
 	
 	node_object_prepare($node);
 	
 	$node->title = (empty($data['title'])?'title':$data['title']);
 	$node->status = 1;
 	$node->comment = 0;
 	$node->promote = 0;
 	$node->moderate = 0;
 	$node->sticky = 0;
 	$node->uid = 1;
 	$node->path['pathauto'] = true; 	
  $node->field_link_rss['und'][0]['value']= $data['link'];
  $node->body['und'][0]['format'] = 'full_html';
 	$node->body['und'][0]['value'] = $data['body'];
  // save image		
  if(isset($data['img_src'])){
    $file_path = $data['img_src'];
    $basename = basename($file_path); 

    if (strrpos($basename, '.')!==false ) { 
      $file_extension = substr($basename, strrpos($basename, '.')+1);
    } else {
      $file_extension = '';
    }
    //take directory, if it doesn't exist then create one
    $real_url = file_destination("public://images/test.txt", FILE_EXISTS_REPLACE);
    $real_dir=drupal_dirname($real_url); 
    if(!is_dir($real_dir)){
      if(mkdir($real_dir,0777)){
        drupal_set_message(t("Folder '!name' create",array('!name'=>$real_dir)));
      }else{
        drupal_set_message(t("Error create folder: ").$real_dir, 'error');
      }
    }
    //declare filepath and filename
    $destination = 'public://images/logo_'. str_replace('-', ' ', $node->title) .'.'.$file_extension;
    
    $file_temp = file_get_contents($file_path);
      $file = file_save_data($file_temp, $destination);
      if ($file) {
        $node->field_image_rss[LANGUAGE_NONE][] = (array)$file;
      }
    }
 	node_submit($node);
 	node_save($node);
}

Has anyone experienced this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Albert Tobacco, 2014-10-24
@bighoc

The problem was the following. an $data['title']object came in instead of a string. The solution turned out to be the simplest.

$node->title = (empty($data['title'])?'title': (sting)$data['title']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question