'default' => '',
'min' => 1,
'max' => 1,
- )
+ ),
+ 'init' => array(
+ 'desc' => 'Initialize the database (pg only supported)',
+ 'short' => 'i',
+ 'default' => '',
+ 'min' => 1,
+ 'max' => 1,
+ ),
+
);
+ var $cli_options = false;
+
var $cli = false;
function getAuth() {
function get($args, $opt)
{
+
+ $this->cli_options = $opt;
+
if($args == 'Person'){
if(empty($opt['source']) || empty($opt['prefix'])){
die("Missing Source directory for person json files or prefix for the passwrod! Try -f [JSON file path] -p [prefix] \n");
die("DONE! \n");
}
+
+
if($args == 'Company'){
if(empty($opt['name']) || empty($opt['comptype'])){
die("Missing company name or type! Try --name=[the name of company] -- comptype=[the type of company] \n");
/**
* postgresql import..
*/
- function importpgsql($url)
+ function importpgsql($dburl)
{
// hide stuff for web..
$ar = $this->modulesList();
- foreach($ar as $m) {
+ foreach($ar as $m) {
+
+ // if init has been called
+ // look in pgsql.ini
+ if (!empty($this->cli_options['init'])) {
+ $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql.init");
+ $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql.initdata");
+ }
+
+
$fd = $this->rootDir. "/Pman/$m/DataObjects";
}
- function importpgsqldir($url, $dir)
+ function importpgsqldir($url, $dir, $disable_triggers = false)
{
require_once 'System.php';
$cat = System::which('cat');
' -h ' . $url['host'] .
' -U' . escapeshellarg($url['user']) .
' ' . basename($url['path']);
+
+
echo $psql_cmd . "\n" ;
+ echo "scan : $dir\n";
foreach(glob($dir.'/*.sql') as $bfn) {
}
$fn = false;
- if (basename($dir) != 'pgsql') {
+ if (!preg_match('/pgsql/', basename($dir) )) {
if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
$fn = $this->convertToPG($bfn);
}
}
if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
$tbl = 'shop_' . strtolower($m[1]);
- $l = preg_replace('#\`{0,1}([a-z0-9_]+)\`{0,1}#i', "{$tbl}", $l);
- }else{
- if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m)) {
- $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
- }
- }
-
+ $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
+ }
+ if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
+ $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
+ }
// autoinc
if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
$l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
}
- // enum value
- if ($tbl && preg_match('#alter\s+table\s+#i', $l, $m)) {
-
- if ($tbl && preg_match('#([\w]+)\s+(enum\([\w]+\))#i', $l, $m)) {
- print_r($m);exit;
- $name = explode(" ", $m[0]);
- $name = $name[0];
- }
- if ($tbl && preg_match('#enum\([\w|\W]+\)#i', $l, $m)) {
- $extra[] = "CREATE TYPE {$tbl}_enum AS {$m[0]};";
- }
+ if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
+ $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
+ }
+
+ // enum value -- use the text instead..
+
+ if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
+ $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
+ }
+ // ignore the alter enum
+ if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
continue;
-
- }else{
-
- if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
- $l = preg_replace('#enum\([\w|\W]+\)#i', "{$tbl}_{$m[1]}_enum", $l);
- print_r($l);exit;
- }
}
// UNIQUE KEY .. ignore
if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
-// preg_match('#UNIQUE\s+KEY\s+([\w]+)\s+([\w|\W]+)#i', $l, $m);
-//
-// $unique[] = 'CREATE UNIQUE INDEX ' . $m[1] . '_idx ON "' . $tbl . '" USING btree ' . $m[2] . ';';
$last = array_pop($ret);
$ret[] = trim($last, ",");
continue;
}
+ if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
+ continue;
+ }
+
+ if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
+ continue;
+ }
+
// INDEX lookup ..ignore
if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
-// $unique[] = 'CREATE INDEX lookup_idx ON "' . $tbl . '" USING btree ' . $m[1] . ';';
$last = array_pop($ret);
$ret[] = trim($last, ",");
continue;
}
- $m = array();
- if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+([^(]+)(.*)$#i', $l, $m)) {
- $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
+ // CREATE INDEX ..ignore
+ if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
+// $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
+ continue;
}
- // ALTER TABLE core_event_audit ADD INDEX looku
- // CREATE INDEX
-
+
// basic types..
$l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
$l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
$l = preg_replace('# blob#i', ' TEXT', $l);
$l = preg_replace('# longtext#i', ' TEXT', $l);
- $l = preg_replace('# tinyint#i', ' BOOLEAN', $l);
-
- // keyword handle...
- if(preg_match('#([\w]+)\s+([\w|\W]+)#i', $l, $m) && !preg_match('#CREATE|PRIMARY|ALERT#i', $l)){
- if($m[1] == 'group'){
- $m[1] = 'group_name';
- }
-
- $l = "{$m[1]} {$m[2]}";
- }
-
+ $l = preg_replace('# tinyint#i', ' INT', $l);
$ret[] = $l;
}
+
$ret = array_merge($extra,$ret);
// echo implode("\n", $ret); exit;
$this->updateDataGroups();
$this->updateDataCompanies();
-
+ $c = DB_DataObject::Factory('I18n');
+ $c->buildDB();