2012-10-17 17:21:35 -04:00
|
|
|
<?php
|
2018-02-01 13:06:32 +00:00
|
|
|
|
2012-10-17 17:21:35 -04:00
|
|
|
global $DB_ADAPTER;
|
|
|
|
|
global $DB_HOST;
|
|
|
|
|
global $DB_USER;
|
|
|
|
|
global $DB_PASS;
|
|
|
|
|
global $DB_NAME;
|
2018-02-01 13:06:32 +00:00
|
|
|
set_time_limit(0);
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
$id = '';
|
2018-02-01 13:06:32 +00:00
|
|
|
if (isset($_POST['id']))
|
2012-10-17 17:21:35 -04:00
|
|
|
$id = $_POST['id'];
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
$upgradeData = unserialize(file_get_contents(PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin"));
|
|
|
|
|
$workspaces = $upgradeData['workspaces'];
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
if (is_array($workspaces) && count($workspaces) > 0) {
|
|
|
|
|
$workspace = array_shift($upgradeData['workspaces']);
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
eval(getDatabaseCredentials(PATH_DB . $workspace . PATH_SEP . 'db.php'));
|
|
|
|
|
$database = new database($DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
|
|
|
|
|
$database->iFetchType = MYSQLI_NUM;
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
//processing .po file
|
2018-02-01 13:06:32 +00:00
|
|
|
if (!empty($upgradeData['sPoFile'])) {
|
2012-10-17 17:21:35 -04:00
|
|
|
$oLanguages = new languages();
|
2018-02-01 13:06:32 +00:00
|
|
|
$oLanguages->importLanguage($upgradeData['sPoFile'], $upgradeData['bForceXmlPoFile']);
|
|
|
|
|
$upgradeData['bForceXmlPoFile'] = false;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
if ($upgradeData['sSchemaFile'] != '')
|
|
|
|
|
processMasterSchemaFile($upgradeData['sSchemaFile']);
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
//draw a gauge control indicating the progress in workspaces
|
|
|
|
|
$gauge = intval((($upgradeData['wsQuantity'] - count($workspaces) + 1) / $upgradeData['wsQuantity']) * 301);
|
2012-10-17 17:21:35 -04:00
|
|
|
print "<table cellpadding=0><tr><td><img src='/images/ajax-loader.gif' border=0/></td><td>";
|
|
|
|
|
print "<div style='border-style:solid;border-width:1px; border-color: #A1C868; width:300px; height:19px;' >";
|
|
|
|
|
print "<div style='color:#FFF; height:16px; text-align:center; padding-top:3px; background-image: url(/skins/green/images/bm.jpg); background-repeat: repeat-x; width: {$gauge}px' ></div> </div>";
|
2018-02-01 13:06:32 +00:00
|
|
|
print "</td><td width='40%'><font color=black> Upgrading the workspace </font><b><font color=green>" . $filter->xssFilterHard($workspace) . "</font></b></td><td width=250 align=right>| " . $filter->xssFilterHard($id) . " Remaining</td></tr></table>";
|
|
|
|
|
file_put_contents(PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin", serialize($upgradeData));
|
2012-10-17 17:21:35 -04:00
|
|
|
} else {
|
|
|
|
|
print "<table cellpadding=0><tr><td> </td><td>";
|
|
|
|
|
print "<div style='border-style:solid;border-width:1px; border-color: #A1C868; width:300px; height:19px;' >";
|
|
|
|
|
print "<div style='color:#FFF; height:16px; text-align:center; padding-top:3px; background-image: url(/skins/green/images/bm.jpg); background-repeat: repeat-x; width: 301px' ></div> </div>";
|
|
|
|
|
print "</td><td> Finished! All workspaces were upgraded successfully.</td></tr></table>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
function getDatabaseCredentials($dbFile)
|
2012-10-17 17:21:35 -04:00
|
|
|
{
|
2018-02-01 13:06:32 +00:00
|
|
|
$sContent = file_get_contents($dbFile);
|
|
|
|
|
$sContent = str_replace('<?php', '', $sContent);
|
|
|
|
|
$sContent = str_replace('<?', '', $sContent);
|
|
|
|
|
$sContent = str_replace('?>', '', $sContent);
|
|
|
|
|
$sContent = str_replace('define', '', $sContent);
|
|
|
|
|
$sContent = str_replace("('", '$', $sContent);
|
|
|
|
|
$sContent = str_replace("',", '=', $sContent);
|
|
|
|
|
$sContent = str_replace(");", ';', $sContent);
|
2012-10-17 17:21:35 -04:00
|
|
|
return $sContent;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
function processMasterSchemaFile($schemaFile)
|
2012-10-17 17:21:35 -04:00
|
|
|
{
|
|
|
|
|
global $DB_ADAPTER;
|
|
|
|
|
global $DB_HOST;
|
|
|
|
|
global $DB_USER;
|
|
|
|
|
global $DB_PASS;
|
|
|
|
|
global $DB_NAME;
|
2018-02-01 13:06:32 +00:00
|
|
|
global $upgradeData;
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
//convert newSchema to array
|
2018-02-01 13:06:32 +00:00
|
|
|
if (isset($upgradeData['aNewSchema'])) {
|
|
|
|
|
$newSchema = $upgradeData['aNewSchema'];
|
2012-10-17 17:21:35 -04:00
|
|
|
} else {
|
2018-02-01 13:06:32 +00:00
|
|
|
$newSchema = schemaToArray($schemaFile);
|
|
|
|
|
$upgradeData['aNewSchema'] = $newSchema;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$oldSchema = processSchemaFile();
|
|
|
|
|
if (is_null($oldSchema)) {
|
2012-10-17 17:21:35 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$changes = obtainChanges($oldSchema, $newSchema);
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
$database = new database($DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
|
|
|
|
|
if (!$database->isConnected()) {
|
2012-10-17 17:21:35 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->iFetchType = MYSQLI_NUM;
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->logQuery(count($changes));
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($changes['tablesToAdd'] as $table => $columns) {
|
|
|
|
|
$database->executeQuery($database->generateCreateTableSQL($table, $columns));
|
|
|
|
|
if (isset($changes['tablesToAdd'][$table]['INDEXES'])) {
|
|
|
|
|
foreach ($changes['tablesToAdd'][$table]['INDEXES'] as $indexName => $attribute) {
|
|
|
|
|
$database->executeQuery($database->generateAddKeysSQL($table, $indexName, $attribute));
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($changes['tablesToAlter'] as $table => $actions) {
|
|
|
|
|
foreach ($actions as $key => $action) {
|
|
|
|
|
foreach ($action as $column => $data) {
|
|
|
|
|
switch ($key) {
|
2012-10-17 17:21:35 -04:00
|
|
|
case 'DROP':
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->executeQuery($database->generateDropColumnSQL($table, $data));
|
2012-10-17 17:21:35 -04:00
|
|
|
break;
|
|
|
|
|
case 'ADD':
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->executeQuery($database->generateAddColumnSQL($table, $column, $data));
|
2012-10-17 17:21:35 -04:00
|
|
|
break;
|
|
|
|
|
case 'CHANGE':
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->executeQuery($database->generateChangeColumnSQL($table, $column, $data));
|
2012-10-17 17:21:35 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($changes['tablesWithNewIndex'] as $table => $index) {
|
|
|
|
|
foreach ($index as $indexName => $indexFields) {
|
|
|
|
|
$database->executeQuery($database->generateAddKeysSQL($table, $indexName, $indexFields));
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($changes['tablesToAlterIndex'] as $table => $index) {
|
|
|
|
|
foreach ($index as $indexName => $indexFields) {
|
|
|
|
|
$database->executeQuery($database->generateDropKeySQL($table, $indexName));
|
|
|
|
|
$database->executeQuery($database->generateAddKeysSQL($table, $indexName, $indexFields));
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->close();
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
function processSchemaFile()
|
2012-10-17 17:21:35 -04:00
|
|
|
{
|
|
|
|
|
global $DB_ADAPTER;
|
|
|
|
|
global $DB_HOST;
|
|
|
|
|
global $DB_USER;
|
|
|
|
|
global $DB_PASS;
|
|
|
|
|
global $DB_NAME;
|
|
|
|
|
|
|
|
|
|
try {
|
2018-02-01 13:06:32 +00:00
|
|
|
$oldSchema = [];
|
|
|
|
|
$database = new database($DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
if (!$database->isConnected()) {
|
|
|
|
|
$database->logQuery(G::LoadTranslation('ID_DOES_NOT_EXIST_AVAILABLE_CONNECTION'));
|
2012-10-17 17:21:35 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->iFetchType = MYSQLI_NUM;
|
|
|
|
|
$result = $database->executeQuery($database->generateShowTablesSQL());
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->logQuery($e->getmessage());
|
2012-10-17 17:21:35 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//going thru all tables in current WF_ database
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($result as $table) {
|
|
|
|
|
$table = strtoupper($table);
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
//get description of each table, ( column and primary keys )
|
2018-02-01 13:06:32 +00:00
|
|
|
$database->iFetchType = MYSQLI_ASSOC;
|
|
|
|
|
$description = $database->executeQuery($database->generateDescTableSQL($table));
|
|
|
|
|
$oldSchema[$table] = [];
|
|
|
|
|
foreach ($description as $field) {
|
|
|
|
|
$oldSchema[$table][$field['Field']]['Field'] = $field['Field'];
|
|
|
|
|
$oldSchema[$table][$field['Field']]['Type'] = $field['Type'];
|
|
|
|
|
$oldSchema[$table][$field['Field']]['Null'] = $field['Null'];
|
|
|
|
|
$oldSchema[$table][$field['Field']]['Default'] = $field['Default'];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get indexes of each table SHOW INDEX FROM `ADDITIONAL_TABLES`; -- WHERE Key_name <> 'PRIMARY'
|
2018-02-01 13:06:32 +00:00
|
|
|
$description = $database->executeQuery($database->generateTableIndexSQL($table));
|
|
|
|
|
foreach ($description as $field) {
|
|
|
|
|
if (!isset($oldSchema[$table]['INDEXES'])) {
|
|
|
|
|
$oldSchema[$table]['INDEXES'] = [];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
if (!isset($oldSchema[$table]['INDEXES'][$field['Key_name']])) {
|
|
|
|
|
$oldSchema[$table]['INDEXES'][$field['Key_name']] = [];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$oldSchema[$table]['INDEXES'][$field['Key_name']][] = $field['Column_name'];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//finally return the array with old schema obtained from the Database
|
2018-02-01 13:06:32 +00:00
|
|
|
if (count($oldSchema) === 0) {
|
|
|
|
|
$oldSchema = null;
|
|
|
|
|
}
|
|
|
|
|
return $oldSchema;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//process the schema file in the patch file, and obtain an array
|
2018-02-01 13:06:32 +00:00
|
|
|
function schemaToArray($schemaFile)
|
2012-10-17 17:21:35 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2018-02-01 13:06:32 +00:00
|
|
|
$schema = [];
|
|
|
|
|
$xml = new DomDocument();
|
|
|
|
|
$xml->load($schemaFile);
|
|
|
|
|
$tables = $xml->getElementsByTagName('table');
|
|
|
|
|
foreach ($tables as $table) {
|
|
|
|
|
$primaryKeys = [];
|
|
|
|
|
$tableName = $table->getAttribute('name');
|
|
|
|
|
$schema[$tableName] = [];
|
|
|
|
|
$columns = $table->getElementsByTagName('column');
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
|
$columnName = $column->getAttribute('name');
|
|
|
|
|
$schema[$tableName][$columnName] = [];
|
|
|
|
|
$vendors = $column->getElementsByTagName('vendor');
|
|
|
|
|
foreach ($vendors as $vendor) {
|
|
|
|
|
if ($vendor->getAttribute('type') == config('connections.driver')) {
|
2012-10-17 17:21:35 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$parameters = $column->getElementsByTagName('parameter');
|
|
|
|
|
foreach ($parameters as $oParameter) {
|
|
|
|
|
$parameterName = ucwords($oParameter->getAttribute('name'));
|
|
|
|
|
if ($parameterName == 'Key' && strtoupper($oParameter->getAttribute('value')) == 'PRI') {
|
|
|
|
|
$primaryKeys[] = $column->getAttribute('name');
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
if (in_array($parameterName, ['Field', 'Type', 'Null', 'Default'])) {
|
|
|
|
|
$schema[$tableName][$columnName][$parameterName] = $oParameter->getAttribute('value');
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
if (is_array($primaryKeys) && count($primaryKeys) > 0) {
|
|
|
|
|
$schema[$tableName]['INDEXES']['PRIMARY'] = $primaryKeys;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$index = $table->getElementsByTagName('index');
|
|
|
|
|
foreach ($index as $fieldIndex) {
|
|
|
|
|
$attribute = [];
|
|
|
|
|
$aIndexesColumns = $fieldIndex->getElementsByTagName('index-column');
|
2012-10-17 17:21:35 -04:00
|
|
|
foreach ($aIndexesColumns as $oIndexColumn) {
|
2018-02-01 13:06:32 +00:00
|
|
|
$attribute[] = $oIndexColumn->getAttribute('name');
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$schema[$tableName]['INDEXES'][$fieldIndex->getAttribute('name')] = $attribute;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
return $schema;
|
2012-10-17 17:21:35 -04:00
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw $oError;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
function obtainChanges($oldSchema, $newSchema)
|
2012-10-17 17:21:35 -04:00
|
|
|
{
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
$changes = ['tablesToAdd' => [], 'tablesToAlter' => [], 'tablesWithNewIndex' => [], 'tablesToAlterIndex' => []];
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
//new tables to create and alter
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($newSchema as $tableName => $columns) {
|
|
|
|
|
if (!isset($oldSchema[$tableName])) {
|
|
|
|
|
$changes['tablesToAdd'][$tableName] = $columns;
|
2012-10-17 17:21:35 -04:00
|
|
|
} else {
|
|
|
|
|
//drop old columns
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($oldSchema[$tableName] as $columnName => $parameters) {
|
|
|
|
|
if (!isset($newSchema[$tableName][$columnName])) {
|
|
|
|
|
if (!isset($changes['tablesToAlter'][$tableName])) {
|
|
|
|
|
$changes['tablesToAlter'][$tableName] = ['DROP' => [], 'ADD' => [], 'CHANGE' => []];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$changes['tablesToAlter'][$tableName]['DROP'][$columnName] = $columnName;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//create new columns
|
2018-02-01 13:06:32 +00:00
|
|
|
foreach ($columns as $columnName => $parameters) {
|
|
|
|
|
if ($columnName != 'INDEXES') {
|
|
|
|
|
if (!isset($oldSchema[$tableName][$columnName])) { //this column doesnt exist in oldschema
|
|
|
|
|
if (!isset($changes['tablesToAlter'][$tableName])) {
|
|
|
|
|
$changes['tablesToAlter'][$tableName] = ['DROP' => [], 'ADD' => [], 'CHANGE' => []];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$changes['tablesToAlter'][$tableName]['ADD'][$columnName] = $parameters;
|
2012-10-17 17:21:35 -04:00
|
|
|
} else { //the column exists
|
2018-02-01 13:06:32 +00:00
|
|
|
$newField = $newSchema[$tableName][$columnName];
|
|
|
|
|
$oldField = $oldSchema[$tableName][$columnName];
|
2012-10-17 17:21:35 -04:00
|
|
|
//both are null, no change is required
|
2018-02-01 13:06:32 +00:00
|
|
|
if (!isset($newField['Default']) && !isset($oldField['Default']))
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = false;
|
2018-02-01 13:06:32 +00:00
|
|
|
//one of them is null, change IS required
|
|
|
|
|
if (!isset($newField['Default']) && isset($oldField['Default']) && $oldField['Default'] != '')
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = true;
|
2018-02-01 13:06:32 +00:00
|
|
|
if (isset($newField['Default']) && !isset($oldField['Default']))
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = true;
|
2018-02-01 13:06:32 +00:00
|
|
|
//both are defined and they are different.
|
|
|
|
|
if (isset($newField['Default']) && isset($oldField['Default'])) {
|
|
|
|
|
$changeDefaultAttr = false;
|
|
|
|
|
if ($newField['Default'] != $oldField['Default']) {
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = true;
|
2018-02-01 13:06:32 +00:00
|
|
|
}
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
//special cases
|
|
|
|
|
// BLOB and TEXT columns cannot have DEFAULT values. http://dev.mysql.com/doc/refman/5.0/en/blob.html
|
2018-02-01 13:06:32 +00:00
|
|
|
if (in_array(strtolower($newField['Type']), ['text', 'mediumtext']))
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = false;
|
|
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
//#1067 - Invalid default value for datetime field
|
|
|
|
|
if (in_array($newField['Type'], ['datetime']) && isset($newField['Default']) && $newField['Default'] == '') {
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = false;
|
2018-02-01 13:06:32 +00:00
|
|
|
}
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
//#1067 - Invalid default value for int field
|
|
|
|
|
if (substr($newField['Type'], 0, 3) && isset($newField['Default']) && $newField['Default'] == '') {
|
2012-10-17 17:21:35 -04:00
|
|
|
$changeDefaultAttr = false;
|
2018-02-01 13:06:32 +00:00
|
|
|
}
|
2012-10-17 17:21:35 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
//if any difference exists, then insert the difference in aChanges
|
2012-10-17 17:21:35 -04:00
|
|
|
if ($newField['Field'] != $oldField['Field'] || $newField['Type'] != $oldField['Type'] || $newField['Null'] != $oldField['Null'] || $changeDefaultAttr) {
|
2018-02-01 13:06:32 +00:00
|
|
|
if (!isset($changes['tablesToAlter'][$tableName])) {
|
|
|
|
|
$changes['tablesToAlter'][$tableName] = ['DROP' => [], 'ADD' => [], 'CHANGE' => []];
|
|
|
|
|
}
|
|
|
|
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Field'] = $newField['Field'];
|
|
|
|
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Type'] = $newField['Type'];
|
|
|
|
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Null'] = $newField['Null'];
|
|
|
|
|
if (isset($newField['Default'])) {
|
|
|
|
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Default'] = $newField['Default'];
|
|
|
|
|
} else {
|
|
|
|
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Default'] = null;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //only columns, no the indexes column
|
2018-02-01 13:06:32 +00:00
|
|
|
} //foreach $columns
|
2012-10-17 17:21:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//now check the indexes of table
|
2018-02-01 13:06:32 +00:00
|
|
|
if (isset($newSchema[$tableName]['INDEXES'])) {
|
|
|
|
|
foreach ($newSchema[$tableName]['INDEXES'] as $indexName => $indexFields) {
|
|
|
|
|
if (!isset($oldSchema[$tableName]['INDEXES'][$indexName])) {
|
|
|
|
|
if (!isset($changes['tablesWithNewIndex'][$tableName])) {
|
|
|
|
|
$changes['tablesWithNewIndex'][$tableName] = [];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$changes['tablesWithNewIndex'][$tableName][$indexName] = $indexFields;
|
2012-10-17 17:21:35 -04:00
|
|
|
} else {
|
2018-02-01 13:06:32 +00:00
|
|
|
if ($oldSchema[$tableName]['INDEXES'][$indexName] != $indexFields) {
|
|
|
|
|
if (!isset($changes['tablesToAlterIndex'][$tableName])) {
|
|
|
|
|
$changes['tablesToAlterIndex'][$tableName] = [];
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
$changes['tablesToAlterIndex'][$tableName][$indexName] = $indexFields;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //for-else table exists
|
|
|
|
|
} //for new schema
|
2018-02-01 13:06:32 +00:00
|
|
|
return $changes;
|
2012-10-17 17:21:35 -04:00
|
|
|
}
|
|
|
|
|
|