<?php
$contents = '
/******************************************************************************/
--- Preparing for categories conversion...
/******************************************************************************/
TRUNCATE {$to_prefix}categories;
---{
// Add a tempID column.
$knownKeys = array();
$knownColumns = array(
\'tempID\' => "ADD COLUMN tempID mediumint(8) NOT NULL default 0",
\'tempID2\' => "ADD COLUMN tempID mediumint(8) NOT NULL default 0",
\'tempID3\' => "ADD COLUMN tempID mediumint(8) NOT NULL default 0"
);
alterTable(\'categories\', $knownKeys, $knownColumns);
';
// Find all arrays.
preg_match_all('/^\s*\$(\S+)\s*=\s*(array\(.*?\);)/ms',
$contents,
$matches);
// Loop through our matches.
foreach ($matches[2] as $key => $data)
{
// Get the keys and values of those arrays.
preg_match("~'([a-zA-Z0-9]+)' => \"(.+?)\"(,)~",
$data,
$line);
// The variable name.
$variable = $matches[1][$key];
// Empty array? Just forget it.
continue;
// If it is for known columns, we do something different.
if ($variable == 'knownColumns')
{
// Bring out the value.
preg_match('~"([add|edit|drop]+ column)\s([a-zA-Z0-9]+)\s([a-zA-Z0-9]+)\((\d)\)+\s(not null|null)\s(default ([\d|\s\"\']+))"~',
$string,
$values);
$result[$variable][$key] =
array( 'key' => $key,
'variable' => $variable,
'action' =>
trim($values[1]),
'name' =>
trim($values[2]),
'type' =>
trim($values[3]),
'size' =>
trim($values[4]),
'not_null' =>
trim($values[5]) ==
'not null' ?
true :
false,
'default' =>
strpos(trim($values[6]),
'default') !==
false ?
trim($values[7]) :
null,
);
}
// For this we will do different things.
elseif ($variable == 'knownKeys')
{
}
}
$shouldbe = "
/******************************************************************************/
--- Preparing for categories conversion...
/******************************************************************************/
TRUNCATE {\$to_prefix}categories;
---{
// Add a temp_id column.
alterDatabase('categories', 'add column', array(
'name' => 'temp_id',
'type' => 'mediumint',
'size' => 8,
'default' => 0));
---}
";
?>