eZ Publish  [trunk]
ezconvertdbcharset.php File Reference

Go to the source code of this file.

Classes

class  CommandLineArguments
 Class used to store some of the command line arguments. More...

Enumerations

enum  EZ_CONTENTCLASS_ATTRIBUTE_TMP_TABLE_NAME
enum  EZ_CREATE_CONTENTCLASS_ATTRIBUTE_TMP_TABLE_SQL_MYSQL
enum  EZ_CREATE_CONTENTCLASS_ATTRIBUTE_TMP_TABLE_SQL_ORACLE
enum  EZ_CREATE_CONTENTCLASS_ATTRIBUTE_TMP_TABLE_SQL_POSTGRESQL
enum  EZ_DROP_CONTENTCLASS_ATTRIBUTE_TMP_TABLE_SQL

Functions

 changeDBCharset ($charset, $collation)
 changeDBCharsetMYSQL ($charset, $collation)
 changeDBCharsetORACLE ($charset, $collation)
 NOTE: What if other data is also in the db? Either we do not convert it and have it most likely corrupted, or we convert it - and leave to the client for the other apps to set up NLS_LANG correctly to keep working.
 changeDBCharsetPOSTGRESQL ($charset, $collation)
 checkDBCharset ($iconvCharacterSet)
 checkDBDriver ()
 checkDBExtraConditions ()
 checkDBExtraConditionsORACLE ()
 convertArray ($array, $inCharset, $outCharset)
 convertCustomXMLData ($tableInfoList)
 convertSerializedData ($serializedDataInfo)
 convertXMLCustomDataProgress ($row)
 convertXMLData ($tableInfo, $xmlDataSelectSQLFunction, $xmlDataUpdateSQLFunction, $convertXMLProgressFunction)
 convertXMLDatatypeProgress ($row)
 convertXMLDatatypes ($tableInfoList)
 createBLOBColumnMYSQL ($tableInfo)
 createBLOBColumnORACLE ($tableInfo)
 createBLOBColumnPOSTGRESQL ($tableInfo)
 createContentClassAttributeTempTable ()
 dropBLOBColumn ($tableInfo)
 dropBLOBColumns ($serializedDataInfo)
 dropContentClassAttributeTempTable ()
 eZExecuteShellCommand ($command, $errMessage= '', $retry=true, $ignore=false)
 eZGetUserInput ($prompt)
 parseCustomSerializedDataOption ($serializedCustomDataOption)
 parseCustomXMLDataOption ($xmlCustomDataOption)
 parseXMLAttributesOption ($xmlAttributesOption)
 removeIllegalUTF8Characters ($text)
 For some reason, some utf8 encoded text stored in the db might contain illegal utf8 characters.
 restoreSerializedData ($serializedDataInfo)
 serializeContentClassAttributeNames ()
 serializeContentClassNames ()
 serializeNames ($selectSQL, $storeToTable)
 showError ($message, $addEOL=true, $bailOut=true)
 showMessage ($message, $addEOL=true)
 showMessage2 ($message, $addEOL=true)
 showMessage3 ($message, $addEOL=true)
 showNotice ($message, $addEOL=true)
 showWarning ($message, $addEOL=true)
 storeSerializedName ($serializedName, $id, $version, $table)
 unserializeContentClassAttributeNames ()
 xmlCustomDataSelectSQL ($dataTableInfo)
 xmlCustomDataUpdateSQL ($dataTableInfo, $row)
 xmlDatatypeSelectSQL ($dataTableInfo)
 xmlDatatypeUpdateSQL ($dataTableInfo, $row)

Variables

 $cli = eZCLI::instance()
 $collation = $options['collation'] ? $options['collation'] : 'utf8_general_ci'
 $db = eZDB::instance()
 $eZDir = getcwd()
if(CommandLineArguments::logFilename()!==false$iconvCharacterSet = "iconv-character-set"] : false
if(!$db->isConnected()) if(!checkDBDriver()) $logFilename = $options['log-filename'] ? $options['log-filename'] : false
 $options
 $script
 $serializedCustomDataOption = $options['extra-serialized-data'] ? $options['extra-serialized-data'] : ''
 $serializedDataInfo = parseCustomSerializedDataOption( $serializedCustomDataOption )
 $skipClassTranslations = "skip-class-translations"]
 $xmlAttributesInfo = parseXMLAttributesOption( $xmlAttributesOption )
 $xmlAttributesOption = $options['extra-xml-attributes'] ? $options['extra-xml-attributes'] : ''
 $xmlCustomDataInfo = parseCustomXMLDataOption( $xmlCustomDataOption )
if($xmlAttributesInfo &&count($xmlAttributesInfo)==0) $xmlCustomDataOption = $options['extra-xml-data'] ? $options['extra-xml-data'] : ''
 for ($i=0;$i > 0;$i--)
$db InputTextCodec = null
$db OutputTextCodec = null

Enumeration Type Documentation


Function Documentation

changeDBCharset ( charset,
collation 
)

Definition at line 1136 of file ezconvertdbcharset.php.

changeDBCharsetMYSQL ( charset,
collation 
)

Definition at line 1152 of file ezconvertdbcharset.php.

changeDBCharsetORACLE ( charset,
collation 
)

NOTE: What if other data is also in the db? Either we do not convert it and have it most likely corrupted, or we convert it - and leave to the client for the other apps to set up NLS_LANG correctly to keep working.

We could use the csalter script iff we where sure that db version was > 9...

Oracle 9 exp exports data using the DB charset

From http://www.experts-exchange.com/Database/Oracle/Q_22836430.html

May be the best procedure is the following one: On PROD Database: 1. export full=y rows=n file=export_db_structure.dmp 2. export full=y file=export_db_date.dmp On TEST Database: 1. create tablespaces with the same name on PROD 2. import full=y file=export_db_structure.dmp ignore=y Now we have users of PROD, on TEST database. SYSTEM user is not imported, because already exists. 3. import fromuser=user1,user2,user3 touser=user1,user2,user3 file=export_db_data.dmp ignore=y now we have user1..3 data on their tables...

Unfortunately even if we do that, Oracle will nto let us convert a db from latin1 to utf8 charsets. The only way is to drop the db and creater it from scratch. Since we have no clue about db storage, we will let the admin take care of that part, and only do the export/import parts.

Todo:
oracle servers might use UTF8 charset instead of AL32UTF8: check before executing!
Todo:
using dbname as file name does not work with easy conection naming
Todo:
log somewhere results of imp, exp commands for better understanding of errors
Todo:
add a database logfile switch or checkpoint here? it would be nice...

Definition at line 1279 of file ezconvertdbcharset.php.

changeDBCharsetPOSTGRESQL ( charset,
collation 
)

Definition at line 1174 of file ezconvertdbcharset.php.

checkDBCharset ( iconvCharacterSet)

Check db charset

Definition at line 361 of file ezconvertdbcharset.php.

Check db driver

Definition at line 339 of file ezconvertdbcharset.php.

DB specific checks. A string is returned for error conditions (script halts after printing it)

Definition at line 391 of file ezconvertdbcharset.php.

Todo:

We should really check for exp_full, imp_full, (sysdba) privileges rather than DBA role...

add check for RAC - do not try anything in such a case

Definition at line 408 of file ezconvertdbcharset.php.

convertArray ( array,
inCharset,
outCharset 
)

Definition at line 805 of file ezconvertdbcharset.php.

Referenced by convertSerializedData().

convertCustomXMLData ( tableInfoList)

Definition at line 885 of file ezconvertdbcharset.php.

convertSerializedData ( serializedDataInfo)

Logic:

  • create binary column as temp storage to not loose data when table will be converted
  • get original data
  • unseiazlize
  • convert data to utf-8
  • serialize
  • store data in binary column

Definition at line 696 of file ezconvertdbcharset.php.

Definition at line 957 of file ezconvertdbcharset.php.

convertXMLData ( tableInfo,
xmlDataSelectSQLFunction,
xmlDataUpdateSQLFunction,
convertXMLProgressFunction 
)

Convert xml text to db's charset. However for optimization the xml processing instruction 'encoding' will be set to utf-8.

Definition at line 978 of file ezconvertdbcharset.php.

Definition at line 925 of file ezconvertdbcharset.php.

convertXMLDatatypes ( tableInfoList)

Definition at line 875 of file ezconvertdbcharset.php.

createBLOBColumnMYSQL ( tableInfo)

Definition at line 845 of file ezconvertdbcharset.php.

createBLOBColumnORACLE ( tableInfo)

Definition at line 858 of file ezconvertdbcharset.php.

createBLOBColumnPOSTGRESQL ( tableInfo)

Definition at line 852 of file ezconvertdbcharset.php.

dropBLOBColumn ( tableInfo)

Definition at line 865 of file ezconvertdbcharset.php.

dropBLOBColumns ( serializedDataInfo)

Definition at line 792 of file ezconvertdbcharset.php.

eZExecuteShellCommand ( command,
errMessage = '',
retry = true,
ignore = false 
)

Definition at line 142 of file ezconvertdbcharset.php.

Referenced by changeDBCharsetORACLE().

eZGetUserInput ( prompt)

prompt user to choose what to do next

Definition at line 132 of file ezconvertdbcharset.php.

Referenced by changeDBCharsetORACLE(), and checkDBExtraConditionsORACLE().

parseCustomSerializedDataOption ( serializedCustomDataOption)

process custom xml data info

Returns:
false or an array of table infos.

Definition at line 278 of file ezconvertdbcharset.php.

parseCustomXMLDataOption ( xmlCustomDataOption)

process custom xml data info false of an array of table infos.

Definition at line 242 of file ezconvertdbcharset.php.

parseXMLAttributesOption ( xmlAttributesOption)

process xml attributes info

Returns:
false or an array of table infos.

Definition at line 199 of file ezconvertdbcharset.php.

For some reason, some utf8 encoded text stored in the db might contain illegal utf8 characters.

This function will strip/replace such known characters

Definition at line 967 of file ezconvertdbcharset.php.

Referenced by convertXMLData().

restoreSerializedData ( serializedDataInfo)

Restore data from binary column

Definition at line 774 of file ezconvertdbcharset.php.

Definition at line 557 of file ezconvertdbcharset.php.

serializeNames ( selectSQL,
storeToTable 
)

Definition at line 580 of file ezconvertdbcharset.php.

showMessage ( message,
addEOL = true 
)

Definition at line 110 of file ezconvertdbcharset.php.

Referenced by downloadPackages(), and showPackageActions().

showMessage2 ( message,
addEOL = true 
)
showNotice ( message,
addEOL = true 
)

Definition at line 104 of file ezconvertdbcharset.php.

showWarning ( message,
addEOL = true 
)
storeSerializedName ( serializedName,
id,
version,
table 
)

Definition at line 667 of file ezconvertdbcharset.php.

xmlCustomDataSelectSQL ( dataTableInfo)

Definition at line 930 of file ezconvertdbcharset.php.

xmlCustomDataUpdateSQL ( dataTableInfo,
row 
)

Definition at line 943 of file ezconvertdbcharset.php.

xmlDatatypeSelectSQL ( dataTableInfo)

Definition at line 895 of file ezconvertdbcharset.php.

xmlDatatypeUpdateSQL ( dataTableInfo,
row 
)

Definition at line 910 of file ezconvertdbcharset.php.


Variable Documentation

$cli = eZCLI::instance()

Definition at line 1494 of file ezconvertdbcharset.php.

$collation = $options['collation'] ? $options['collation'] : 'utf8_general_ci'

Definition at line 1583 of file ezconvertdbcharset.php.

Referenced by changeDBCharset().

$db = eZDB::instance()

Definition at line 1529 of file ezconvertdbcharset.php.

$eZDir = getcwd()

Definition at line 1492 of file ezconvertdbcharset.php.

Referenced by changeDBCharsetORACLE(), and showError().

if (CommandLineArguments::logFilename()!==false) $iconvCharacterSet = "iconv-character-set"] : false

Definition at line 1552 of file ezconvertdbcharset.php.

Referenced by checkDBCharset().

if (!$db->isConnected()) if (!checkDBDriver()) $logFilename = $options['log-filename'] ? $options['log-filename'] : false

Definition at line 1543 of file ezconvertdbcharset.php.

$options
Initial value:
 $script->getOptions( "[extra-xml-attributes:][extra-xml-data:][extra-serialized-data:][collation:][skip-class-translations][iconv-character-set:][log-filename:]",
                                "",
                                array( 'extra-xml-attributes' => "specify custom attributes which store its data in xml.\n" .
                                                                 "usage: <datatype_string>[.<table>.<field>][,<datatype_string>.<table>.<field>...].\n" .
                                                                 "default table is 'ezcontentobject_attribute', default data field is 'data_text'\n" .
                                                                 "note: your custom table must have 'id', 'version' and 'data_type_string' fields.",
                                       'extra-xml-data' => "specify custom xml data.\n" .
                                                            "usage: <table>.<field>[,<table>.<field>...].\n" .
                                                            "note: your custom table must have 'id' field.",
                                       'extra-serialized-data' => "specify custom serialized data.\n" .
                                                                  "usage: <table>.<field>;<key_field1>[.<key_field2>....][,<table>.<field>...].\n" .
                                                                  "ex: mytable.data_text;id.version,mytable2.data;id",

                                       'collation' => "specify collation for converted db. default is 'utf8_general_ci'",
                                       'skip-class-translations' => "Content class translations were added in eZ Publish 3.9. Use this options if upgrading from early version.",
                                       'iconv-character-set' => 'This setting is used when characters are converted by iconv(). This settings is typically needed when a character set is not called the same by the database and iconv. An example is "windows-1252" (iconv) and "iso-8859-1" (mysql 5)',
                                       'log-filename' => 'Specify a file where iconv conversions will be logged to' ),
                                false,
                                array( 'user' => true ) )

Definition at line 1503 of file ezconvertdbcharset.php.

Initial value:
 eZScript::instance( array( 'description' => ( "Changes your eZ Publish database tables to use UTF8" ),
                                      'use-session' => false,
                                      'use-modules' => false,
                                      'use-extensions' => true ) )

Definition at line 1496 of file ezconvertdbcharset.php.

$serializedCustomDataOption = $options['extra-serialized-data'] ? $options['extra-serialized-data'] : ''

Definition at line 1626 of file ezconvertdbcharset.php.

Referenced by parseCustomSerializedDataOption().

$serializedDataInfo = parseCustomSerializedDataOption( $serializedCustomDataOption )
$skipClassTranslations = "skip-class-translations"]

Definition at line 1582 of file ezconvertdbcharset.php.

$xmlAttributesInfo = parseXMLAttributesOption( $xmlAttributesOption )

Definition at line 1609 of file ezconvertdbcharset.php.

Referenced by parseXMLAttributesOption().

$xmlAttributesOption = $options['extra-xml-attributes'] ? $options['extra-xml-attributes'] : ''

Definition at line 1588 of file ezconvertdbcharset.php.

Referenced by parseXMLAttributesOption().

$xmlCustomDataInfo = parseCustomXMLDataOption( $xmlCustomDataOption )

Definition at line 1620 of file ezconvertdbcharset.php.

Referenced by parseCustomXMLDataOption().

if ($xmlAttributesInfo &&count($xmlAttributesInfo)==0) $xmlCustomDataOption = $options['extra-xml-data'] ? $options['extra-xml-data'] : ''

Definition at line 1619 of file ezconvertdbcharset.php.

Referenced by parseCustomXMLDataOption().

for($i=0;$i > 0;$i--)

Definition at line 1574 of file ezconvertdbcharset.php.