'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('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
- }else{
- if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m)) {
- $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $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|\W]+\))#i', $l, $m)) {
- $extra[] = "CREATE TYPE {$tbl}_{$m[1]}_enum AS {$m[2]};";
- 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);
- }
+ 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;
}
// UNIQUE KEY .. ignore
}
// CREATE INDEX ..ignore
- if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+([^(]+)(.*)$#i', $l, $m)) {
+ 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;
}
}
$ret = array_merge($extra,$ret);
- echo implode("\n", $ret); exit;
+// echo implode("\n", $ret); exit;
file_put_contents($fn, implode("\n", $ret));
$this->updateDataGroups();
$this->updateDataCompanies();
-
+ $c = DB_DataObject::Factory('I18n');
+ $c->buildDB();