2016-08-18 80 views
1

這裏是從的Joomla 1.5升級joomfish(的Joomla平移分量),以2.5的腳本:Joomfish遷移腳本返回錯誤

$db = new PDO("mysql:host=localhost;dbname=db;charset=UTF8", "root", "pass"); 

$stmt = $db->prepare("select distinct(jfc.reference_id),c.catid,jfc.language_id,c.modified,c.modified_by,c.version,c.modified_by ,c.ordering,c.created_by,c.metadesc ,c.created_by_alias from jos_jf_content jfc ,jos_content c where jfc.reference_id = c.id and jfc.reference_table = 'content' "); 
$stmt->execute(); 

$results = $stmt->fetchAll(PDO::FETCH_ASSOC); 

    foreach($results as $row) { 

     $count_row = $db->prepare("select * from jos_jf_content where reference_id = ? and language_id = ?"); 
     $count_row->bindValue(1, $row['reference_id']); 
     $count_row->bindValue(2, $row['language_id']); 

     $lang_code = $db->prepare("select lang_code from j25_languages where lang_id = ?"); 
     $lang_code->bindValue(1, $row['language_id']); 
     $lang_code->execute(); 
     $l_code = $lang_code->fetch(PDO::FETCH_OBJ); 
     $language_code = $l_code->lang_code; 

     $count_row->execute(); 

      $title =""; 
      $fulltext =""; 
      $introtext =""; 
      $alias =""; 
      $published =""; 

     while($col = $count_row->fetch(PDO :: FETCH_ASSOC)) 
     { 
      if($col['reference_field'] == "title") 
        { 
         $title = $col['value']; 
        } 
        if($col['reference_field'] == "fulltext") 
        { 
         $fulltext = $col['value']; 
        } 
        if($col['reference_field'] == "introtext") 
        { 
         $introtext = $col['value']; 
        } 
        if($col['reference_field'] == "alias") 
        { 
         $alias = $col['value']; 
        } 
        $published = $col['published']; 

     } 

    $exe = $db->prepare("insert into j25_content (`title`,`alias`,`introtext`,`fulltext`,`published`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`version`,`ordering`,`metadesc`,`language`) values(:title,:alias,:introtext,:fulltext,:published,:categoryid,:created,:created_by,:created_by_alias,:modified,:modified_by,:version,:ordering,:metadesc,:language_code)"); 

    $exe->execute(array(':title' => $title,':alias' => $alias,':introtext' => addslashes($introtext),':fulltext' => addslashes($fulltext),':published' => ".$published.",':categoryid' => $row['catid'],':created' => date("Y-m-d H:i:s"),':created_by' => $row['created_by'],':created_by_alias' => "".$row['created_by_alias']."",':modified' => date("Y-m-d H:i:s"),':modified_by' =>$row['modified_by'],':version' => $row['version'],':ordering' => $row['ordering'],':metadesc' => $row['metadesc'],':language_code' => $language_code)); 

    $i = $db->lastInsertId('id'); 

    $asst = $db->prepare("select asset_id from j25_categories where id = ? "); 
    $asst->bindValue(1, $row['catid']); 
    $asst->execute(); 
    $asst_id = $asst->fetch(PDO::FETCH_OBJ); 
    $cassetid = $asst_id->asset_id; 

    $sel = $db->prepare("select lft,rgt FROM `j25_assets` where id = (SELECT max(id) FROM `j25_assets`)"); 
    $sel->execute(); 
    $select = $sel->fetch(PDO::FETCH_OBJ); 
    $left = $select->lft; 
    $right = $select->rgt; 
    $left=$left+1; 
    $right = $right+1; 

    $stmt = $db->prepare("insert into j25_assets (`parent_id`,`lft`,`rgt`,`level`,`name`,`title`) values(:cassetid,:left,:right,:level,:name,:title)"); 
    $stmt->execute(array(':cassetid' => $cassetid,':left' => $left,':right' => $right,':level' => 4,':name' => "com_content.article.".$i,':title' => $title)); 

    $insertedId = $db->lastInsertId('id'); 

    $update = $db->prepare("update j25_content set asset_id = ? where id = ?"); 
    $update->bindValue(1, $insertedId); 
    $update->bindValue(2, $i); 
    $update->execute(); 

    $stmt = $db->prepare("insert into j25_jf_translationmap (language,reference_id,translation_id,reference_table) values (:language_code,:reference_id,:translation_id,:content)"); 
    $stmt->execute(array(':language_code' => $language_code,':reference_id' => $row['reference_id'],':translation_id' => $i,':content' => 'content')); 
} 

的代碼行:

$language_code = $l_code->lang_code; 

返回:

試圖獲取非物件的財產

我不是腳本的作者,也不擅長PHP,但我試過print_r($l_code->lang_code);,我從[lang_code] => en-GB得到預期結果en-GB。我需要在這段代碼中改變什麼?謝謝。

回答

1

該行$language_code = $l_code->lang_code > 0;$language_code設置爲布爾值。嘗試使用var_dump($l_code);var_dump($language_code);來調試您的結果。您還應該檢查$l_code實際上是否是一個對象,或者返回null。希望有所幫助。

+0

對不起,這是我的錯字,其實有$ l_code-> lang_code;不是$ l_code-> lang_code> 0;我已經在問題中改變了它。 – rocco

+0

但您的建議幫助了我,謝謝! – rocco

+0

@rocco很高興你能解決它... – jpaljasma