<?php
-
+/**
+ *
+ * This applies database files from
+ * a) OLD - {MODULE}/DataObjects/XXXX.{dbtype}.sql
+ *
+ * b) NEW - {MODULE}/sql/XXX.sql (SHARED or translable)
+ * and {MODULE}/{dbtype}/XXX.sql (SHARED or translable)
+ *
+ *
+ */
require_once 'Pman.php';
class Pman_Core_UpdateDatabase extends Pman
{
- static $cli_desc = "Update SQL - Beta";
+ static $cli_desc = "Update SQL - Beta (it will run updateData of all modules)";
-
+
var $cli = false;
function getAuth() {
function get()
{
$this->importSQL();
+ $this->runUpdateModulesData();
}
function output() {
$this->{'import' . $url['scheme']}($url);
}
+
+ /**
+ * mysql - does not support conversions.
+ *
+ *
+ */
+
+
+
function importmysql($url)
{
echo $mysql_cmd . "\n" ;
-
+ // old -- DAtaObjects/*.sql
foreach($ar as $m) {
if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
continue;
}
-
+ // .my.sql but not .pg.sql
+ if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
+ && !preg_match('#\.my\.sql#i', basename($fn))
+ ) { // skip migration scripts at present..
+ continue;
+ }
$cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
echo $cmd. ($this->cli ? "\n" : "<BR>\n");
}
+ // new -- sql directory..
+ // new style will not support migrate ... they have to go into mysql-migrate.... directories..
+ // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
+ $fd = $this->rootDir. "/Pman/$m/sql";
+
+ foreach(glob($fd.'/*.sql') as $fn) {
+ $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
+ echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+ passthru($cmd);
+ }
+ $fd = $this->rootDir. "/Pman/$m/mysql";
+
+ foreach(glob($fd.'/*.sql') as $fn) {
+ $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
+ echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+ passthru($cmd);
+ }
+
+
+
+
+
+
}
$fd = $this->rootDir. "/Pman/$m/DataObjects";
- foreach(glob($fd.'/*.sql') as $fn) {
+ foreach(glob($fd.'/*.sql') as $bfn) {
- if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
+ if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
continue;
}
- $fn = $this->convertToPG($fn);
+ if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
+ && !preg_match('#\.pg\.sql#i', basename($bfn))
+ ) { // skip migration scripts at present..
+ continue;
+ }
+ // files ending in .pg.sql are native postgres files..
+ $fn = preg_match('#\.pg\.sql$#', basename($bfn)) ? false : $this->convertToPG($bfn);
- $cmd = "$psql_cmd -f " . escapeshellarg($fn) ;
+ $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
- echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+ echo "$bfn: $cmd ". ($this->cli ? "\n" : "<BR>\n");
- $res = `$cmd`;
+ passthru($cmd);
+ if ($fn) {
+ unlink($fn);
+ }
+ }
+
+
- unlink($fn);
+ $fd = $this->rootDir. "/Pman/$m/sql";
+ // sql directory - we try to convert..
+ foreach(glob($fd.'/*.sql') as $bfn) {
+ $fn = $this->convertToPG($bfn);
+ $cmd = "$psql_cmd < " . escapeshellarg($fn) ;
+ echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+ passthru($cmd);
+ }
+
+ // postgres specific directory..
+
+ $fd = $this->rootDir. "/Pman/$m/pgsql";
+
+ foreach(glob($fd.'/*.sql') as $fn) {
+ $cmd = "$psql_cmd < " . escapeshellarg($fn) ;
+ echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+ passthru($cmd);
}
+
+
+
}
}
*/
function convertToPG($src)
{
- $fn = $this->tempName('.sql');
+ $fn = $this->tempName('sql');
$ret = array( ); // pad it a bit.
$extra = array("", "" );
}
$ret = array_merge($extra,$ret);
- echo implode("\n", $ret); //exit;
+ //echo implode("\n", $ret); //exit;
file_put_contents($fn, implode("\n", $ret));
return $fn;
}
+
+ function runUpdateModulesData()
+ {
+ $this->updateData();
+ $modules = $this->modulesList();
+ foreach ($modules as $module){
+ $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
+ if($module == 'Core' || !file_exists($file)){
+ continue;
+ }
+ require_once $file;
+ $class = "Pman_{$module}_UpdateDatabase";
+ $x = new $class;
+ if(!method_exists($x, 'updateData')){
+ continue;
+ };
+ $x->updateData();
+ }
+ }
+
+ function updateData()
+ {
+ // fill i18n data..
+
+ $enum = DB_DataObject::Factory('core_enum');
+ $enum->initEnums(
+ array(
+ 'etype' => '',
+ 'name' => 'COMPTYPE',
+ 'display_name' => 'Company Types',
+ 'cn' => array(
+ array(
+ 'name' => 'OWNER',
+ 'display_name' => 'Owner',
+ 'seqid' => 999, // last...
+ )
+
+ )
+ )
+ );
+ }
+
}
\ No newline at end of file