-
#!/usr/local/bin/php
-
<?php
-
/***************************************************************
-
* Copyright notice
-
*
-
* (c) 2006 Matthias Nott (mnott@mnsoft.org)
-
* All rights reserved
-
*
-
* This script is part of the Typo3 project. The Typo3 project is
-
* free software; you can redistribute it and/or modify
-
* it under the terms of the GNU General Public License as published by
-
* the Free Software Foundation; either version 2 of the License, or
-
* (at your option) any later version.
-
*
-
* The GNU General Public License can be found at
-
* http://www.gnu.org/copyleft/gpl.html.
-
* A copy is found in the textfile GPL.txt and important notices to the license
-
* from the author is found in LICENSE.txt distributed with these scripts.
-
*
-
*
-
* This script is distributed in the hope that it will be useful,
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
* GNU General Public License for more details.
-
*
-
* This copyright notice MUST APPEAR in all copies of the script!
-
***************************************************************/
-
-
// *******************************
-
// Set error reporting
-
// *******************************
-
-
-
-
// *******************************
-
// Script Classes
-
// *******************************
-
class Document {
-
var $hashVersion;
-
var $docid;
-
var $docobjects =
array();
-
var $cmslanguages;
-
var $doclanguages =
array();
-
var $container;
-
-
public function __construct($docid, $cmslanguages, $container, $hashVersion) {
-
$this->docid = $docid;
-
$this->cmslanguages = $cmslanguages;
-
$this->container = $container;
-
$this->hashVersion = $hashVersion;
-
}
-
-
public function getDocid() {
-
return $this->docid;
-
}
-
-
public function addContent($objectId, $languageId) {
-
$this->docobjects[$languageId][] = $objectId;
-
$this->doclanguages[$languageId] = null;
-
}
-
-
public function getLanguageContent($languageId) {
-
return $this->docobjects[$languageId];
-
}
-
-
-
public function to_string() {
-
-
}
-
-
public function getFlexml() {
-
ksort($this->
doclanguages);
-
$flexml = "";
-
$flexml .= "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"yes\" ?>\n";
-
$flexml .= "<T3FlexForms>\n";
-
$flexml .= " <data>\n";
-
$flexml .= " <sheet index=\"sDEF\">\n";
-
foreach($this->doclanguages as $key => $val) {
-
$flexml .= " <language index=\"l".$this->cmslanguages[$key]."\">\n";
-
$flexml .= " <field index=\"".$this->container."\">\n";
-
$flexml .=
" <value index=\"vDEF\">".
implode(',',
$this->
getLanguageContent($key)).
"</value>\n";
-
$flexml .= " </field>\n";
-
$flexml .= " </language>\n";
-
}
-
$flexml .= " </sheet>\n";
-
$flexml .= " </data>\n";
-
$flexml .= "</T3FlexForms>";
-
-
return $flexml;
-
}
-
-
/**
-
* Create the entries for the sys_refindex table
-
*/
-
public function getRefindexRows() {
-
-
foreach($this->doclanguages as $key => $val) {
-
$content = $this->getLanguageContent($key);
-
$sorting = 0;
-
foreach($content as $ref_uid) {
-
-
$row[] = "'".$this->createHash("pages", $this->docid, "tx_templavoila_flex", "sDEF/l".$this->cmslanguages[$key]."/".$this->container."/vDEF/", 0, "tt_content", $ref_uid, "", 0, "", "")."'";
-
$row[] = "'pages'";
-
$row[] = $this->docid;
-
$row[] = "'tx_templavoila_flex'";
-
$row[] = "'sDEF/l".$this->cmslanguages[$key]."/".$this->container."/vDEF/'";
-
$row[] = "''";
-
$row[] = "''";
-
$row[] = $sorting++;
-
$row[] = 0;
-
$row[] = "'tt_content'";
-
$row[] = $ref_uid;
-
$row[] = "''";
-
-
}
-
//$hash = $this->createHash('pages', 432, 'tx_templavoila_flex', 'sDEF/lDEF/field_content/vDEF/', 0, 'tt_content', 1237, '', 0, '', '');
-
}
-
return $result;
-
}
-
-
-
/**
-
* Create the hash value as used in the sys_refindex table.
-
*/
-
private function createHash($table,$uid,$field,$flexpointer,$deleted,$ref_table,$ref_uid,$ref_string='',$sort=-1,$softref_key='',$softref_id='') {
-
-
'tablename' => $table,
-
'recuid' => $uid,
-
'field' => $field,
-
'flexpointer' => $flexpointer,
-
'softref_key' => $softref_key,
-
'softref_id' => $softref_id,
-
'sorting' => $sort,
-
'deleted' => $deleted,
-
'ref_table' => $ref_table,
-
'ref_uid' => $ref_uid,
-
'ref_string' => $ref_string,
-
);
-
return md5(implode('///',
$arr).
'///'.
$this->
hashVersion);
-
}
-
-
/**
-
* Create the entries for the tx_templavoila_elementreference table
-
*/
-
public function getElementReferencesRows() {
-
-
foreach($this->doclanguages as $key => $val) {
-
$content = $this->getLanguageContent($key);
-
foreach($content as $uid) {
-
-
$row[] = $uid;
-
$row[] = $this->docid;
-
$row[] = "'sDEF'";
-
$row[] = "'l".$this->cmslanguages[$key]."'";
-
$row[] = "'vDEF'";
-
-
}
-
}
-
return $result;
-
}
-
}
-
-
-
class MigrateContent {
-
var $db_host;
-
var $db_schema;
-
var $db_user;
-
var $db_pass;
-
var $db_conn;
-
var $hashVersion;
-
var $container;
-
var $cmslanguages;
-
-
public function __construct($db_host, $db_schema, $db_user, $db_pass, $hashVersion, $container) {
-
$this->db_host = $db_host;
-
$this->db_schema = $db_schema;
-
$this->db_user = $db_user;
-
$this->db_pass = $db_pass;
-
$this->hashVersion = $hashVersion;
-
$this->container = $container;
-
}
-
-
/**
-
* Get the language strings that are currently used in our
-
* CMS. These are used later for insertions in the tables.
-
*/
-
private function getCMSLanguageStrings() {
-
$query = "select l.uid, s.lg_iso_2 from static_languages s, sys_language l where l.static_lang_isocode = s.uid";
-
-
-
-
-
-
-
$result[$row['uid']] = $row['lg_iso_2'];
-
}
-
$result[0] = 'DEF';
-
return $result;
-
}
-
-
-
/**
-
* Parse the document structure
-
*/
-
private function getDocument($docid) {
-
$query = "select uid, sys_language_uid from tt_content where pid = ".$docid." and deleted = 0 order by sorting";
-
-
-
-
$result = new Document($docid, $this->cmslanguages, $this->container, $this->hashVersion);
-
-
-
$result->addContent($row['uid'], $row['sys_language_uid']);
-
}
-
return $result;
-
}
-
-
/**
-
* Update the document in the database
-
*/
-
private function updateDocument($doc) {
-
/*
-
* update the pages table
-
*/
-
$query = "update pages set tx_templavoila_flex = '".$doc->getFlexml()."' where uid = ".$doc->getDocid();
-
-
-
/*
-
* delete existing references from sys_refindex
-
* and write new references to sys_refindex.
-
*/
-
$query = "delete from sys_refindex where recuid = ".$doc->getDocid();
-
-
-
$rows = $doc->getRefindexRows();
-
foreach ($rows as $row) {
-
$qres =
mysql_query("insert into sys_refindex values ($row)");
-
}
-
-
/*
-
* delete existing references from tx_templavoila_elementreferences
-
* and write new references to tx_templavoila_elementreferences
-
*/
-
$query = "delete from tx_templavoila_elementreferences where pid = ".$doc->getDocid();
-
-
-
$rows = $doc->getElementReferencesRows();
-
foreach ($rows as $row) {
-
$qres =
mysql_query("insert into tx_templavoila_elementreferences values ($row)");
-
}
-
-
}
-
-
-
/**
-
* The main function
-
*/
-
public function main($docid) {
-
-
/*
-
* Connect to the Database
-
*/
-
$dbh =
mysql_pconnect($this->
db_host,
$this->
db_user,
$this->
db_pass) or
die ("Could not connect to database");
-
-
-
-
/*
-
* Get the language strings that are used in our CMS.
-
*/
-
$this->cmslanguages = $this->getCMSLanguageStrings();
-
-
/*
-
* Get the document structure.
-
*/
-
-
$doc = $this->getDocument($docid);
-
-
/*
-
* Update the document structure in the database
-
*/
-
$this->updateDocument($doc);
-
-
/*
-
* Disconnect from the Database
-
*/
-
-
-
}
-
}
-
-
-
// *******************************
-
// Startup
-
// *******************************
-
-
if ($argc !=
8 ||
in_array($argv[1],
array('--help',
'-help',
'-h',
'-?'))) {
-
?>
-
This script migrates a document from pre-TemplaVoila to TemplaVoila.
-
-
Usage:
-
<?php echo $argv[0];
?> <db_host> <db_schema> <db_user> <db_pass> <hash_version> <container> <docid>
-
-
<db_host> is the hostname of your
mysql cms database.
-
<db_schema> is the database schema name for your cms database.
-
<db_user> is the database username.
-
<db_pass> is the database password.
-
<hash_version> is the hash version (use 1 or look into class.t3lib_refindex.php).
-
<container> is the name of the templavoila container where your default content goes (e.g. "field_content").
-
<docid> is the id of a document that you want to migrate.
-
-
With the --help, -help, -h,
-
or -? options, you can get this help.
-
<?php
-
}
-
-
$obj = new MigrateContent($argv[1], $argv[2], $argv[3], $argv[4], $argv[5], $argv[6]);
-
$obj->main($argv[7]);
-
?>
-