Created
September 23, 2013 15:20
-
-
Save soyuka/6672060 to your computer and use it in GitHub Desktop.
Update Joomfish 1.5 datas to Jommfish 2.5 datas, previous update done with JUpgrade, just launch this script by providing the prefix of the old DB and the new one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //Script founded here : | |
| //http://joomlastuffs.blogspot.fr/2013/03/how-to-migrate-joomfish-menu-from.html | |
| $prefix_15 = 'ass_'; | |
| $prefix_25 = 'aas_2'; | |
| $dbname = 'mondassu_insurance'; | |
| /*NOTE*/ | |
| /*----*/ | |
| /*SCRIPT WILL WORK AFTER MIGRATING DATA FROM JOOMLA 1.5 TO JOOMLA 2.5.X. MAKE SURE DATABASE REQUIRED TABLES ARE AVAIL*/ | |
| /*SCRIPT TO MIGRATE ARTICLE CONTENT DATA FROM JOOMFISH FOR JOOMLA 1.5 TO JOOMLA 2.5.X*/ | |
| //DB CONNECTION | |
| $db = new PDO("mysql:host=localhost;dbname=".$dbname.";charset=UTF-8", "root", ""); | |
| //".$prefix_15."jf_content table have a reference to original content from ".$prefix_15."content and reference_table = 'content' denotes ARTICLE's table, with distinguish ".$prefix_25."content TABLE | |
| //MASTER QUERY TO GET NUMBER OF ARTICLES FROM OLD ".$prefix_15."jf_content TABLE RELATED TO PARTICULAR LANGUAGE.--->1 | |
| $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 from ".$prefix_15."jf_content jfc ,".$prefix_15."content c where jfc.reference_id = c.id and jfc.reference_table = 'content' "); | |
| $stmt->execute(); | |
| //CREATE FETCHING OBJECT FOR THE MASTER QUERY. | |
| $results = $stmt->fetchAll(PDO::FETCH_ASSOC); | |
| //LOOP's THE OBJECT TO FETCH VALUE. | |
| foreach($results as $row) { | |
| //IDENTIFY EACH ARTICLE FROM REFERENCE ID AND LANGUAGE ID DERIVED FROM MASTER QUERY.--->2 | |
| $count_row = $db->prepare("select * from ".$prefix_15."jf_content where reference_id = ? and language_id = ?"); | |
| $count_row->bindValue(1, $row['reference_id']); | |
| $count_row->bindValue(2, $row['language_id']); | |
| //DERIVE LANGUAGE CODE FROM LANGUAGE ID.--->3 | |
| $lang_code = $db->prepare("select lang_code from ".$prefix_25."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; | |
| //EXECUTE --->2 | |
| $count_row->execute(); | |
| //LOOPING DATA AND STORES IN VARIABLE. | |
| $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']; | |
| } | |
| //INSERT COLLECTED DATA INTO content TABLE.--->5 | |
| $exe = $db->prepare("insert into ".$prefix_25."content (`title`,`alias`,`introtext`,`fulltext`,`state`,`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)); | |
| //LAST INSERT ID,NEEDS TO BE MAP WITH ".$prefix_25."assests TABLE and ".$prefix_25."jf_translationmap TABLE. | |
| $i = $db->lastInsertId('id'); | |
| //GET ASSET ID FOR CATEGORY ID, DERIVED.--->6 | |
| $ass = $db->prepare("select asset_id from ".$prefix_25."categories where id = ? "); | |
| $ass->bindValue(1, $row['catid']); | |
| $ass->execute(); | |
| $".$prefix_15."id = $ass->fetch(PDO::FETCH_OBJ); | |
| $cassetid = $".$prefix_15."id->asset_id; | |
| //SELECT MAX lft and rgt from ".$prefix_25."assests FOR ORDERING.--->7 | |
| $sel = $db->prepare("select lft,rgt FROM `".$prefix_25."assets` where id = (SELECT max(id) FROM `".$prefix_25."assets`)"); | |
| $sel->execute(); | |
| $select = $sel->fetch(PDO::FETCH_OBJ); | |
| $left = $select->lft; | |
| $right = $select->rgt; | |
| $left=$left+1; | |
| $right = $right+1; | |
| //INSERT DATA FETCHED FROM 5,6,7 IN ".$prefix_25."assests TABLE.--->8 | |
| $stmt = $db->prepare("insert into ".$prefix_25."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)); | |
| //LAST INSERT ID,NEEDS TO BE MAP WITH ".$prefix_25."content TABLE.--->9 | |
| $insertedId = $db->lastInsertId('id'); | |
| //UPDATE asset_id FIELD IN ".$prefix_25."content TABLE WITH $insertedId.--->10 | |
| $update = $db->prepare("update ".$prefix_25."content set asset_id = ? where id = ?"); | |
| $update->bindValue(1, $insertedId); | |
| $update->bindValue(2, $i); | |
| $update->execute(); | |
| //INSERT DATA INTO ".$prefix_25."jf_translationmap FOR MAPPING BETWEEN ".$prefix_25."content,".$prefix_25."languages,".$prefix_25."jf_translationmap TO MAKE JOOMFISH ENTRIES.--->11 | |
| $stmt = $db->prepare("insert into ".$prefix_25."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')); | |
| } | |
| echo 'Done.'; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment