2011-07-28 6 views
3

현재의 html 사이트를 drupal로 마이그레이션하려고합니다. 나는 이주해야하는 80,000 페이지가 넘었으므로 나는 50 년 동안 컴퓨터의 infront에 앉아서 모듈을 만들 것이라고 생각했다. 나는 각 디렉토리에서 html을 추출하는 스크립트를 만들 수 있었고 지금은 노드를 생성해야하는 도로 블록에 도착했다. node_save()를 사용하여 새 노드를 만들려고하는데 node_save가 실행될 때 내가 시도한 모든 것과 PDOException 오류가 발생합니다. 저는 $ node를 전달할 것입니다.이 배열은 객체로 형변환됩니다.node_save를 사용하여 노드를 만드는 방법은 무엇입니까?

PDOException: in field_sql_storage_field_storage_write() (line 424 of /srv/www/htdocs/modules/field/modules/field_sql_storage/field_sql_storage.module).

이것은 우리가 현재 노드를 작성하는 방법이지만, 오류 발생 :

$node= array(
    'uid' => $user->uid, 
    'name' => $user->name, 
    'type' => 'page', 
    'language' => LANGUAGE_NONE, 
    'title' => $html['title'], 
    'status' => 1, 
    'promote' => 0, 
    'sticky' => 0, 
    'created' => (int)REQUEST_TIME, 
    'revision' => 0, 
    'comment' => '1', 
    'menu' => array(
     'enabled' => 0, 
     'mlid' => 0, 
     'module' => 'menu', 
     'hidden' => 0, 
     'has_children' => 0, 
     'customized' => 0, 
     'options' => array(), 
     'expanded' => 0, 
     'parent_depth_limit' => 8, 
     'link_title' => '', 
     'description' => '', 
     'parent' => 'main-menu:0', 
     'weight' => '0', 
     'plid' => '0', 
     'menu_name' => 'main-menu', 
    ), 
    'path' => array(
     'alias' => '', 
     'pid' => null, 
     'source' => null, 
     'language' => LANGUAGE_NONE, 
     'pathauto' => 1, 
    ), 
    'nid' => null, 
    'vid' => null, 
    'changed' => '', 
    'additional_settings__active_tab' => 'edit-menu', 
    'log' => '', 
    'date' => '', 
    'submit' => 'Save', 
    'preview' => 'Preview', 
    'private' => 0, 
    'op' => 'Save', 
    'body' => array(LANGUAGE_NONE => array(
     array(
      'value' => $html['html'], 
      'summary' => $link, 
      'format' => 'full_html', 
     ), 
    )), 
     'validated' => true, 
); 

node_save((object)$node); 

// Small hack to link revisions to our test user. 
db_update('node_revision') 
    ->fields(array('uid' => $node->uid)) 
    ->condition('vid', $node->vid) 
    ->execute(); 

답변

2

보통 이런 종류의 일을하기 위해 문서 루트에 bulkimport.php 스크립트를 만듭니다. field_sql_storage_field_storage_write에서() - 등

I : - PDOException

<?php 

define('DRUPAL_ROOT', getcwd()); 

include_once './includes/bootstrap.inc'; 
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 



function _create_node($title="", $body="", $language="und") { 

    $node = (object)array(); 

    $node->uid  = '1'; 
    $node->name  = 'admin'; 

    $node->type  = 'page'; 

    $node->status = 1; 
    $node->promote = 0; 
    $node->sticky = 0; 
    $node->revision = 1; 
    $node->language = $language; 

    $node->title = $title; 
    $node->body[$language][0] = array(
    'value' => $body, 
    'format' => 'full_html', 
    ); 

    $node->teaser = ''; 
    $node->log  = 'Auto Imported Node'; 

    node_submit($node); 
    node_save($node); 

    return $node; 

    } ### function _create_node 

$sith = array(
    'Darth Vader' => 'Master: Darth Sidious', 
    'Darth Sidious' => 'Master: Darth Plagous', 
    'Darth Maul'  => 'Master: Darth Sidious', 
    'Darth Tyranous' => 'Master: Darth Sidious', 
); 

foreach($sith as $title=>$body) { 
    print "Creating Node. Title:[".$title."] \tBody:[".$body."] "; 
    $node = _create_node($title, $body); 
    print "\t... Created Node ID: [".$node->nid."]\n"; 
    #print_r($node); 
    } ### foreach 
0

는 일부 CMS 엔진을 사용하는지, 또는 웹 사이트를 맞춤 작성? 첫 번째 경우는 여기를보십시오 http://drupal.org/documentation/migrate 주어진 모듈을 살펴 보는 것이 좋습니다. 도움을 받아야합니다. 또한 옵션으로 DB를 마이그레이션 할 수 있습니다.

0

빈 필드가 많이 필요하지 않습니다. 또한 객체로 변환 된 배열이 아닌 객체로 노드를 형변환 할 수 있습니다.

귀하의 코드는이 훨씬 짧은 조각으로 수행 할 수 있어야한다 : 또한

$node = new stdClass(); 
    $node->title = $html['title']; 
    $node->type = 'page'; 
    $node->body['und'][0]['value'] = $html['html']; 
    node_save($node); 

, 드루팔로 대량 수입 노드에 개발 된 많은 방법이있다 - 나는의 팬이다 피드 모듈 (http://drupal.org/project/feeds). 이를 위해서는 기존 콘텐츠를 중간 형식 (CSV 또는 XML)으로 내보내는 방법을 작성해야하지만 안정적으로 작동하며 필요한 경우 노드를 다시 가져와 콘텐츠를 업데이트 할 수 있습니다.

1
내가 원래 게시물과 같은 오류 정확하게 얻고 있었다

: 여기

내가 드루팔 7에 사용하는 코드입니다 위의 주석에 표시된 stdClass 코드 스타일을 이미 사용하고있었습니다.

Body 필드에 할당 한 문자열에 문제가 파운드 기호와 악센트 부호가있는 것으로 판명되었습니다. 문자열은 Windows 텍스트 파일에서 왔습니다. 드루팔 대상 인코딩 (UTF-8)로 문자열을 변환

나를 위해 일한 :이 사람을 도움이

$cleaned_string = mb_convert_encoding($html['html'], "UTF-8", "Windows-1252"); 
$node->body[LANGUAGE_NONE][0]['value'] = $cleaned_string; 
$node->body[LANGUAGE_NONE][0]['format'] = 'plain_text'; 
node_save($node); 

희망을.

+0

이 문제를 해결했습니다. –

관련 문제