Permalink
Browse files

Added ExportModel::FormatValue() convenience function.

Added ExportModel::WriteBeginTable convenience function.
Added basic support for Vanilla 2 exports.
  • Loading branch information...
1 parent 6191cbf commit b8f29a475c4406707a79048999d50f3392ee41ee @tburry tburry committed Dec 20, 2010
Showing with 2,098 additions and 15 deletions.
  1. +57 −4 class.exportmodel.php
  2. +39 −3 class.vanilla2.php
  3. +6 −2 index.php
  4. +1,996 −6 vanilla2export.php
View
@@ -47,6 +47,9 @@ class ExportModel {
*/
public $Prefix = '';
+ /** @var string The path to the source of the export in the case where a file is being converted. */
+ public $SourcePath = '';
+
/**
* @var array Strucutes that define the format of the export tables.
*/
@@ -205,6 +208,8 @@ public function BeginExport($Path = '', $Source = '', $Header = array()) {
}
fwrite($fp, self::NEWLINE.self::NEWLINE);
$this->Comment('Export Started: '.date('Y-m-d H:i:s'));
+
+ return $fp;
}
/**
@@ -332,10 +337,6 @@ protected function _ExportTable($TableName, $Query, $Mappings = array()) {
$Value = NULL;
}
- if ($TableName == 'Permission') {
- $Foo = 'Bar';
- }
-
// Check to see if there is a callback filter.
if (isset($Filters[$Field])) {
$Callback = $Filters[$Field];
@@ -400,6 +401,32 @@ static function FormatElapsed($Start, $End = NULL) {
return $Result;
}
+ static function FormatValue($Value) {
+ static $EscapeSearch = NULL; if ($EscapeSearch === NULL) $EscapeSearch = array(self::ESCAPE, self::DELIM, self::NEWLINE, self::QUOTE); // escape must go first
+ static $EscapeReplace = NULL; if ($EscapeReplace === NULL) $EscapeReplace = array(self::ESCAPE.self::ESCAPE, self::ESCAPE.self::DELIM, self::ESCAPE.self::NEWLINE, self::ESCAPE.self::QUOTE);
+
+ // Format the value for writing.
+ if (is_null($Value)) {
+ $Value = self::NULL;
+ } elseif (is_numeric($Value)) {
+ // Do nothing, formats as is.
+ } elseif (is_string($Value)) {
+ if($Mb && mb_detect_encoding($Value) != 'UTF-8')
+ $Value = utf8_encode($Value);
+
+ $Value = str_replace(array("\r\n", "\r"), array(self::NEWLINE, self::NEWLINE), $Value);
+ $Value = self::QUOTE
+ .str_replace($EscapeSearch, $EscapeReplace, $Value)
+ .self::QUOTE;
+ } elseif (is_bool($Value)) {
+ $Value = $Value ? 1 : 0;
+ } else {
+ // Unknown format.
+ $Value = self::NULL;
+ }
+ return $Value;
+ }
+
public function GetCharacterSet($Table) {
// First get the collation for the database.
$Data = $this->Query("show table status like ':_{$Table}';");
@@ -756,5 +783,31 @@ public function VerifySource($RequiredTables) {
return 'Missing required database tables: '.$MissingTables;
}
}
+
+ public function WriteBeginTable($fp, $TableName, $Columns) {
+ $TableHeader = '';
+
+ foreach($Columns as $Key => $Value) {
+ if (is_numeric($Key)) {
+ $Column = $Value;
+ $Type = '';
+ } else {
+ $Column = $Key;
+ $Type = $Value;
+ }
+
+ if(strlen($TableHeader) > 0)
+ $TableHeader .= self::DELIM;
+
+ if ($Type)
+ $TableHeader .= $Column.':'.$Type;
+ else
+ $TableHeader .= $Column;
+ }
+
+ fwrite($fp, 'Table: '.$TableName.self::NEWLINE);
+ fwrite($fp, $TableHeader.self::NEWLINE);
+
+ }
}
?>
View
@@ -13,10 +13,46 @@ class Vanilla2 extends ExportController {
protected $_SourceTables = array();
/**
- * Forum-specific export format
+ * @param ExportModel $Ex
*/
protected function ForumExport($Ex) {
-
+ $Tables = array(
+ 'Activity',
+ 'Category',
+ 'Comment',
+ 'Conversation',
+ 'ConversationMessage',
+ 'Discussion',
+ 'Media',
+ 'Permission',
+ 'Role',
+ 'User',
+ 'UserConversation',
+ 'UserDiscussion',
+ 'UserMeta',
+ 'UserRole');
+
+ $Ex->BeginExport('', 'Vanilla 2.*', array('HashMethod' => 'Vanilla'));
+
+ foreach ($Tables as $TableName) {
+ $this->ExportTable($Ex, $TableName);
+ }
+
+ $Ex->EndExport();
+ }
+
+ /**
+ *
+ * @param ExportModel $Ex
+ * @param string $TableName
+ */
+ protected function ExportTable($Ex, $TableName) {
+ // Make sure the table exists.
+ if (!$Ex->Exists($TableName))
+ return;
+
+ $Ex->ExportTable($TableName, "select * from :_{$TableName}");
}
-}
+}
+?>
View
@@ -1,6 +1,6 @@
<?php
define('APPLICATION', 'Porter');
-define('APPLICATION_VERSION', '1.3.1');
+define('APPLICATION_VERSION', '1.4a');
/**
* Vanilla 2 Exporter
* This script exports other forum databases to the Vanilla 2 import format.
@@ -29,11 +29,13 @@
/** @var array Supported forum packages: classname => array(name, prefix) */
$Supported = array(
'vanilla1' => array('name'=> 'Vanilla 1.*', 'prefix'=>'LUM_'),
+ 'vanilla2' => array('name'=> 'Vanilla 2.*', 'prefix'=>'GDN_'),
'vbulletin' => array('name'=>'vBulletin 3.* and 4.*', 'prefix'=>'vb_'),
'phpbb2' => array('name'=>'phpBB 2.*', 'prefix' => 'phpbb_'),
'phpbb3' => array('name'=>'phpBB 3.*', 'prefix' => 'phpbb_'),
'bbPress' => array('name'=>'bbPress 1.*', 'prefix' => 'bb_'),
- 'SimplePress' => array('name'=>'SimpePress 1.*', 'prefix' => 'wp_')
+ 'SimplePress' => array('name'=>'SimpePress 1.*', 'prefix' => 'wp_'),
+ 'SMF' => array('name'=>'SMF (Simple Machines) 1.*', 'prefx' => 'smf_')
);
// Support Files
@@ -42,11 +44,13 @@
include('class.exportcontroller.php');
include('class.vanilla1.php');
+include('class.vanilla2.php');
include('class.vbulletin.php');
include('class.phpbb2.php');
include('class.phpbb3.php');
include('class.bbpress.php');
include('class.simplepress.php');
+include('class.smf.php');
// Make sure a default time zone is set
if (ini_get('date.timezone') == '')
Oops, something went wrong.

0 comments on commit b8f29a4

Please sign in to comment.