Skip to content

Instantly share code, notes, and snippets.

@jaromirnyklicek
Last active December 14, 2015 21:19
Show Gist options
  • Save jaromirnyklicek/5150600 to your computer and use it in GitHub Desktop.
Save jaromirnyklicek/5150600 to your computer and use it in GitHub Desktop.
<?php
require_once dirname(__FILE__) . '/nette.min.php';
require_once dirname(__FILE__) . '/dibi.min.php';
if(!isset($_GET['lang'])) {
die('Do parametru adresy "lang" vloz zkratku pridavaneho jazyka.');
} else {
$lang = $_GET['lang'];
}
Debug::enable();
$config = clone Config::fromFile(dirname(__FILE__) . '/../../app/config.ini');
$db = $config->development->database;
$db->database = $db->db;
$newDb = new DibiConnection($db, 'new');
$arr = $newDb->fetchPairs('SHOW TABLES');
foreach($arr as $item) {
$carr = $newDb->fetchAll('SELECT * FROM INFORMATION_SCHEMA.columns
WHERE TABLE_SCHEMA = "' . $db->db . '" AND TABLE_NAME = "' . $item . '"');
foreach($carr as $column) {
// vyhledava podle vychoziho jazyka - cestiny
if(preg_match("#(.*)_cs$#", $column->COLUMN_NAME, $m)) {
$name = $m[1];
$name .= '_' . $lang;
$sql = 'ALTER TABLE ' . $column->TABLE_NAME . ' ADD COLUMN ' . $name . ' ' . $column->COLUMN_TYPE . ' ' . ($column->IS_NULLABLE == 'NO' ? 'NOT NULL' : '') . ' ' . ($column->COLUMN_DEFAULT === null ? '' : ' DEFAULT \'' . $column->COLUMN_DEFAULT . '\'');
$newDb->query($sql);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment