'min' => 1,
'max' => 1,
),
+ 'data-only' => array(
+ 'desc' => 'only run the updateData - do not run import the tables and procedures.',
+ 'short' => 'p',
+ 'default' => '',
+ 'min' => 1,
+ 'max' => 1,
+
+ ),
'add-company' => array(
'desc' => 'add a company name of the company',
'short' => 'n',
'add-company-with-type' => array(
'desc' => 'the type of company (default OWNER)',
'short' => 't',
- 'default' => '',
+ 'default' => 'OWNER',
'min' => 1,
'max' => 1,
),
'min' => 1,
'max' => 1,
),
-
+ 'only-module-sql' => array(
+ 'desc' => 'Only run sql import on this modules - eg. Core',
+ 'default' => '',
+ 'min' => 1,
+ 'max' => 1,
+ ),
+ 'procedures-only' => array(
+ 'desc' => 'Only import procedures (not supported by most modules yet) - ignores sql directory',
+ 'default' => '',
+ 'min' => 1,
+ 'max' => 1,
+ ),
+
+
'json-person' => array(
'desc' => 'Person JSON file',
'default' => '',
function get($args, $opts)
{
- $this->fixSequencesPgsql();exit;
+
+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
+
+
+ //$this->fixSequencesPgsql();exit;
$this->opts = $opts;
// ask all the modules to verify the opts
$this->checkOpts($opts);
- if (!empty($opts['add-company'])) {
- DB_DataObject::factory('companies')->initCompanies($this, $opts);
+
+ if (empty($opts['data-only'])) {
+ $this->importSQL();
+ }
+ if (!empty($opts['only-module-sql'])) {
+ return;
}
-
- $this->importSQL();
$this->runUpdateModulesData();
+
+
+ if (!empty($opts['add-company'])) {
+ // make sure we have a good cache...?
+
+ DB_DataObject::factory('companies')->initCompanies($this, $opts);
+ }
}
function output() {
(!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
' ' . basename($dburl['path']);
//echo $mysql_cmd . "\n" ;
+
+ $files = glob($dir.'/*.sql');
+ uksort($files, 'strcasecmp');
+
-
- foreach(glob($dir.'/*.sql') as $fn) {
+ foreach($files as $fn) {
if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
foreach($ar as $m) {
+ if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
+ continue;
+ }
+
$fd = $this->rootDir. "/Pman/$m/DataObjects";
$this->importmysqldir($dburl, $fd);
$ar = $this->modulesList();
+ print_R($ar);
foreach($ar as $m) {
-
+ echo "Importing SQL from module $m\n";
+ if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
+ continue;
+ }
+ echo "Importing SQL from module $m\n";
// if init has been called
// look in pgsql.ini
if (!empty($this->opts['init'])) {
echo $psql_cmd . "\n" ;
echo "scan : $dir\n";
- foreach(glob($dir.'/*.sql') as $bfn) {
+
+ $files = glob($dir.'/*.sql');
+ uksort($files, 'strcasecmp');
+ //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
+ //usort($files, $lsort);
+
+
+
+ foreach($files as $bfn) {
if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
if (!preg_match('/^json-/', $o) || empty($v)) {
continue;
}
- $type = str_replace('_', '-', substr($o,6));
- $data= json_decode(file_get_contents($file),true);
- DB_DataObject::factory($type)->importFromArray($this,$data,$opts);
+ $type = str_replace('_', '-', substr($o,5));
+
+ $data= json_decode(file_get_contents($v),true);
+ $pg = HTML_FlexyFramework::get()->page;
+ DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
}
function updateDataEnums()
{
+
$enum = DB_DataObject::Factory('core_enum');
+ //DB_DAtaObject::debugLevel(1);
$enum->initEnums(
array(
array(
function updateData()
{
// fill i18n data..
-
+ HTML_FlexyFramework::get()->generateDataobjectsCache(true);
$this->updateDataEnums();
$this->updateDataGroups();
$this->updateDataCompanies();
}
function fixSequencesPgsql()
{
+
+
//DB_DataObject::debugLevel(1);
$cs = DB_DataObject::factory('core_enum');
$cs->query("
- SELECT 'ALTER SEQUENCE '|| quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
+ SELECT
+ 'ALTER SEQUENCE '||
+ CASE WHEN strpos(seq_name, '.') > 0 THEN
+ min(seq_name)
+ ELSE
+ quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
+ END
+
||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
FROM (
n.nspname AS schema_name,
c.relname AS table_name,
a.attname AS column_name,
- regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\"]*', ''),E'[''\"]*::.*\$','') AS seq_name
+ regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
FROM pg_class c
JOIN pg_attribute a ON (c.oid=a.attrelid)
JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
AND d.adsrc ~ '^nextval'
) seq
+ WHERE
+ CASE WHEN strpos(seq_name, '.') > 0 THEN
+ substring(seq_name, 1,strpos(seq_name,'.')-1)
+ ELSE
+ schema_name
+ END = schema_name
+
GROUP BY seq_name HAVING count(*)=1
");
$cmds = array();
}
foreach($cmds as $cmd) {
$cs = DB_DataObject::factory('core_enum');
+ echo "$cmd\n";
$cs->query($cmd);
}
$cs = DB_DataObject::factory('core_enum');
$cs->query("
SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
- ', MAX(' || quote_ident(C.attname)|| ') ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
+ ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
FROM pg_class AS S,
pg_depend AS D,
pg_class AS T,
AND D.refobjid = C.attrelid
AND D.refobjsubid = C.attnum
AND NS.oid = T.relnamespace
- ORDER BY S.relname;
+ ORDER BY S.relname
");
$cmds = array();
while ($cs->fetch()) {
}
foreach($cmds as $cmd) {
$cs = DB_DataObject::factory('core_enum');
+ echo "$cmd\n";
$cs->query($cmd);
}