Skip to content

Commit

Permalink
Move redirect stuff outside the Converter class
Browse files Browse the repository at this point in the history
  • Loading branch information
daris committed Jan 30, 2012
1 parent 59c042a commit c915b15
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 46 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -5,9 +5,7 @@ branches:
language: php

php:
- 5.2
- 5.3
- 5.4

before_script:
- "mkdir fluxbb && cd fluxbb"
Expand Down
10 changes: 8 additions & 2 deletions converter.php
Expand Up @@ -107,7 +107,7 @@
if (defined('CONV_LOG') && file_exists(CONV_LOG))
@unlink(CONV_LOG);

conv_log('Running command line based converter for: '.$forum_config['type'].' ('.gmdate('Y-m-d').')');
conv_log('Running command line based converter for: '.$forum_config['type'].' ('.gmdate('Y-m-d H:i:s').')');
conv_log('PHP version: '.PHP_VERSION.', OS: '.PHP_OS);

// Create a wrapper for fluxbb (has easy functions for adding users etc.)
Expand All @@ -125,7 +125,13 @@
$converter = new Converter($fluxbb, $forum);

// Start the converter
$converter->convert();
$redirect = array(null);
while ($redirect !== false)
{
conv_message();
conv_log('-----------------'."\n");
$redirect = $converter->convert($redirect[0], isset($redirect[1]) ? $redirect[1] : 0);
}

// We're done
$alerts = array($lang_convert['Rebuild search index note']);
Expand Down
3 changes: 3 additions & 0 deletions forums/Merge_FluxBB.php
Expand Up @@ -44,6 +44,9 @@ function initialize()
{
$this->db->set_names('utf8');

if (!session_id())
session_start();

if (isset($_SESSION['converter']['last_id']))
$this->last_id = $_SESSION['converter']['last_id'];
else
Expand Down
48 changes: 26 additions & 22 deletions include/converter.class.php
Expand Up @@ -66,52 +66,56 @@ function convert($step = null, $start_at = 0)
// Validate only first time we run converter (check whether database configuration is valid)
$this->validate();

$_SESSION['fluxbb_converter']['count'] = array();
foreach ($this->forum->steps as $cur_step)
{
if (is_callable(array($this->forum, 'count_'.$cur_step)))
$_SESSION['fluxbb_converter']['count'][$cur_step] = call_user_func(array($this->forum, 'count_'.$cur_step));
}
print_r($_SESSION['fluxbb_converter']);

// Drop the FluxBB database tables (when there is no NO_DB_CLEANUP constant defined for forum)
if (!defined(get_class($this->forum).'::NO_DB_CLEANUP'))
$this->cleanup_database();

$step = $this->forum->steps[0];

return conv_redirect($step);
return array($step);
}

$start = get_microtime();
$redirect_to = false;
$redirect_to = null;

conv_message('Converting', $step);
if (is_callable(array($this->forum, 'convert_'.$step)))
$redirect_to = call_user_func(array($this->forum, 'convert_'.$step), $start_at);
else if (is_callable(array($this, $step)))
$redirect_to = call_user_func(array($this, $step));
else
conv_message('Not implemented', $step);

conv_message('Done in', round(get_microtime() - $start, 6));

// Process same step starting from the $start_at row
if ($redirect_to != false)
conv_redirect($step, $redirect_to);
// Process same step starting from $start_at
if ($redirect_to != null)
return array($step, $redirect_to);

// Are we done?
if ($step == 'finish')
conv_redirect('results');
else
{
$current_step = array_search($step, $this->forum->steps);
return false;

// Basically should never happen
if ($current_step === false)
return false;
$current_step = array_search($step, $this->forum->steps);

// No more tables to process?
if (!isset($this->forum->steps[++$current_step]))
conv_redirect('finish');
// Basically should never happen
if ($current_step === false)
return false;

else
{
// Redirect to the next step
$next_step = $this->forum->steps[$current_step];
conv_redirect($next_step);
}
}
// No more tables to process?
if (!isset($this->forum->steps[++$current_step]))
return array('finish');

// Redirect to the next step
return array($this->forum->steps[$current_step]);
}

/**
Expand Down
17 changes: 2 additions & 15 deletions include/functions_cli.php
Expand Up @@ -17,6 +17,8 @@ function conv_message()

$args = func_get_args();

conv_log($args[0].': '.implode(', ', array_slice($args, 1)));

// Do not show proccessing rows range
if (count($args) && $args[0] == 'Processing range')
$args[0] = 'Processing num';
Expand All @@ -29,7 +31,6 @@ function conv_message()

$output = vsprintf($message, $args);
echo $output."\n";
conv_log($output);
}

/**
Expand Down Expand Up @@ -60,17 +61,3 @@ function conv_error($message, $file = null, $line = null, $dberror = false)

exit(1);
}


/**
* Redirect to the next stage
*/
function conv_redirect($step, $start_at = 0, $time = 0)
{
global $converter;

conv_message();
conv_log('-----------------'."\n");

$converter->convert($step, $start_at);
}
8 changes: 5 additions & 3 deletions include/functions_web.php
Expand Up @@ -17,6 +17,8 @@ function conv_message()

$args = func_get_args();

conv_log($args[0].': '.implode(', ', array_slice($args, 1)));

// Translate message
if (count($args) && isset($lang_convert[$args[0]]))
$args[0] = $lang_convert[$args[0]];
Expand All @@ -25,7 +27,6 @@ function conv_message()

$output = vsprintf($message, $args);
echo $output."\n".'<br />';
conv_log($output);
}


Expand Down Expand Up @@ -67,13 +68,15 @@ function conv_redirect($step, $start_at = 0, $time = 0)

$contents = ob_get_clean();

$url = 'index.php?step='.htmlspecialchars($step).($start_at > 0 ? '&start_at='.$start_at : '');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="<?php echo $time ?>; url=index.php?step=<?php echo htmlspecialchars($step).($start_at > 0 ? '&start_at='.$start_at : '') ?>">
<meta http-equiv="refresh" content="<?php echo $time ?>; url=<?php echo $url ?>">
<title><?php echo sprintf($lang_convert['FluxBB converter'], CONV_VERSION) ?></title>
<link rel="stylesheet" type="text/css" href="../style/<?php echo $default_style ?>.css" />
</head>
Expand Down Expand Up @@ -111,5 +114,4 @@ function conv_redirect($step, $start_at = 0, $time = 0)
conv_log('-----------------');
conv_log('', false, true);
exit;

}
9 changes: 7 additions & 2 deletions index.php
Expand Up @@ -74,7 +74,7 @@
if (defined('CONV_LOG') && file_exists(CONV_LOG))
@unlink(CONV_LOG);

conv_log('Running web based converter for: '.$forum_config['type'].' ('.gmdate('Y-m-d').')');
conv_log('Running web based converter for: '.$forum_config['type'].' ('.gmdate('Y-m-d H:i:s').')');
conv_log('PHP version: '.PHP_VERSION.', OS: '.PHP_OS);
}

Expand Down Expand Up @@ -130,7 +130,12 @@
if (!isset($step) || $step != 'results')
{
// Start the converter. When it do its work, it redirects to the next page
$converter->convert($step, $start_at, true);
$redirect = $converter->convert($step, $start_at);

if ($redirect === false)
conv_redirect('results');
else
conv_redirect($redirect[0], isset($redirect[1]) ? $redirect[1] : 0);
}

if (empty($_SESSION['converter']['dupe_users']))
Expand Down

0 comments on commit c915b15

Please sign in to comment.