5 * This applies database files from
6 * a) OLD - {MODULE}/DataObjects/XXXX.{dbtype}.sql
8 * b) NEW - {MODULE}/sql/XXX.sql (SHARED or translable)
9 * and {MODULE}/{dbtype}/XXX.sql (SHARED or translable)
14 require_once 'Pman.php';
15 class Pman_Core_UpdateDatabase extends Pman
18 static $cli_desc = "Update SQL - Beta (it will run updateData of all modules)";
20 static $cli_opts = array(
23 'desc' => 'prefix for the password (eg. fred > xxx4fred - prefix is xxx4)',
30 'desc' => 'only run the updateData - do not run import the tables and procedures.',
37 'add-company' => array(
38 'desc' => 'add a company name of the company',
44 'add-company-with-type' => array(
45 'desc' => 'the type of company (default OWNER)',
52 'desc' => 'Initialize the database (pg only supported)',
58 'only-module-sql' => array(
59 'desc' => 'Only run sql import on this modules - eg. Core',
64 'skip-mysql-checks' => array(
65 'desc' => 'Skip mysql checks',
70 'procedures-only' => array(
71 'desc' => 'Only import procedures (not supported by most modules yet) - ignores sql directory',
77 'json-person' => array(
78 'desc' => 'Person JSON file',
85 'desc' => 'Debug the database',
94 static function cli_opts()
97 $ret = self::$cli_opts;
98 $ff = HTML_FlexyFramework::get();
100 $mods = $a->modulesList();
101 foreach($mods as $m) {
103 $fd = $ff->rootDir. "/Pman/$m/UpdateDatabase.php";
104 if (!file_exists($fd)) {
110 $cls = new ReflectionClass('Pman_'. $m . '_UpdateDatabase');
111 $ar = $cls->getStaticProperties();
112 if (isset($ar['cli_opts'])) {
114 $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
123 var $disabled = array();
128 var $local_base_url = false;
130 var $emailTemplates = array(
131 'EVENT_ERRORS_REPORT' => array(
132 'test_class' => 'Pman/Coba/DataObjects/Ext_data',
133 'to_group' => 'Administrators',
135 'description' => '9. System Error Messages'
142 $ff = HTML_FlexyFramework::get();
143 if (!empty($ff->cli)) {
148 parent::getAuth(); // load company!
149 $au = $this->getAuthUser();
150 if (!$au || $au->company()->comptype != 'OWNER') {
151 $this->jerr("Not authenticated", array('authFailure' => true));
153 $this->authUser = $au;
157 function get($args, $opts=array())
160 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
162 $this->checkSystem();
164 $this->verifyExtensions(array('curl'));
166 if (class_exists('PDO_DataObjects_Introspection')) {
167 PDO_DataObject_Introspection::$cache = array();
169 echo "Generate DB cache\n";
170 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
171 echo "Generated DB cache\n";
172 $ff = HTML_FlexyFramework::get();
174 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
175 die("Please setup Pman[local_base_url]\n");
178 $this->local_base_url = $ff->Pman['local_base_url'];
180 if(!empty($ff->Core_Notify)){
181 // require_once 'Pman/Core/NotifySmtpCheck.php';
182 // $x = new Pman_Core_NotifySmtpCheck();
186 $this->disabled = explode(',', $ff->disable);
188 //$this->fixSequencesPgsql();exit;
191 if (!empty($opts['debug'])) {
192 DB_DataObject::DebugLevel($opts['debug']);
195 // ask all the modules to verify the opts
196 echo "Checi options\n";
197 $this->checkOpts($opts);
201 // do this first, so the innodb change + utf8 fixes column max sizes
203 // this will trigger errors about freetext indexes - we will have to remove them manually.?
204 // otherwise we need to do an sql query to find them, then remove them (not really worth it as it only affects really old code..)
206 $this->runExtensions();
209 if (empty($opts['data-only'])) {
212 if (!empty($opts['only-module-sql'])) {
218 $this->runUpdateModulesData();
220 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
221 // make sure we have a good cache...?
223 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
226 $this->runExtensions();
228 $this->clearApacheDataobjectsCache();
230 $this->clearApacheAssetCache();
234 echo "\nUpdate Completed SUCCESS\n";
238 * imports SQL files from all DataObjects directories....
240 * except any matching /migrate/
245 // loop through all the modules, and see if they have a importSQL method?
248 $ff = HTML_Flexyframework::get();
250 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
252 //$this->{'import' . $url['scheme']}($url);
254 $dbtype = $dburl['scheme'];
257 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
262 $ar = $this->modulesList();
267 if(in_array($m, $this->disabled)){
268 echo "module $m is disabled \n";
272 echo "Importing SQL from module $m\n";
273 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
278 // check to see if the class has
282 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
283 if($m != 'Core' && file_exists($file)){
286 $class = "Pman_{$m}_UpdateDatabase";
288 if(method_exists($x, 'importModuleSQL')){
289 echo "Importing SQL from module $m using Module::importModuleSQL\n";
290 $x->opts = $this->opts;
291 $x->rootDir = $this->rootDir;
292 $x->importModuleSQL($dburl);
297 echo "Importing SQL from module $m\n";
300 // if init has been called
302 if (!empty($this->opts['init'])) {
303 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
309 $fd = $this->rootDir. "/Pman/$m/DataObjects";
311 $this->{$dirmethod}($dburl, $fd);
314 // new -- sql directory..
315 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
316 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
317 $dbdir = $dbtype == 'mysqli' ? 'mysql' : $dbtype;
319 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
320 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbdir}");
324 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
325 if (class_exists('PDO_DataObjects_Introspection')) {
326 PDO_DataObject_Introspection::$cache = array();
328 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
330 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
331 $this->{'fixSequences'. $dbtype}();
344 /** -------------- code to handle importing a whole directory of files into the database ------- **/
347 function importpgsqldir($url, $dir, $disable_triggers = false)
349 $ff = HTML_FlexyFramework::get();
351 require_once 'System.php';
352 $cat = System::which('cat');
353 $psql = System::which('psql');
356 if (!empty($url['pass'])) {
357 putenv("PGPASSWORD=". $url['pass']);
361 ' -h ' . $url['host'] .
362 ' -U' . escapeshellarg($url['user']) .
363 ' ' . basename($url['path']);
366 echo $psql_cmd . "\n" ;
367 echo "scan : $dir\n";
370 $files = array($dir);
375 $files = glob($dir.'/*.sql');
376 uksort($files, 'strcasecmp');
378 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
379 //usort($files, $lsort);
382 foreach($files as $bfn) {
385 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
388 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
389 && !preg_match('#\.pg\.sql#i', basename($bfn))
390 ) { // skip migration scripts at present..
395 if (!preg_match('/pgsql/', basename($dir) )) {
396 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
397 $fn = $this->convertToPG($bfn);
401 // files ending in .pg.sql are native postgres files.. ## depricated
404 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
406 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
422 * mysql - does not support conversions.
426 function importmysqlidir($dburl, $dir) {
427 return $this->importmysqldir($dburl, $dir);
430 function importmysqldir($dburl, $dir)
433 $this->fixMysqlInnodb(); /// run once
435 echo "Import MYSQL :: $dir\n";
438 require_once 'System.php';
439 $cat = System::which('cat');
440 $mysql = System::which('mysql');
444 $mysql_cmd = $mysql .
445 ' -h ' . $dburl['host'] .
446 ' -u' . escapeshellarg($dburl['user']) .
447 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
448 ' ' . basename($dburl['path']);
449 //echo $mysql_cmd . "\n" ;
451 $files = glob($dir.'/*.sql');
452 uksort($files, 'strcasecmp');
455 foreach($files as $fn) {
458 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
461 // .my.sql but not .pg.sql
462 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
463 && !preg_match('#\.my\.sql#i', basename($fn))
464 ) { // skip migration scripts at present..
467 if (!strlen(trim($fn))) {
471 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
473 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
476 $fp = popen($cmd, "r");
479 // send the current file part to the browser
480 $line = trim(fgets($fp, 1024));
485 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
486 echo " ---- {$line}\n"; flush();
490 switch($matches[1]) {
491 case 1017: // cause by renaming table -- old one does not exist..
492 case 1050: // create tables triggers this..
493 case 1060: // Duplicate column name
494 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
495 case 1091: // drop index -- name does not exist.. might hide errors..
497 case 1146: // drop a index on an unknown table.. - happens rarely...
498 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
504 echo " ---- {$line}\n"; flush();
508 // 1051: // Unknown table -- normally drop = add iff exists..
509 echo "File: $fn\n$line\n";
525 * simple regex based convert mysql to pgsql...
527 function convertToPG($src)
529 //echo "Convert $src\n";
531 $fn = $this->tempName('sql');
533 $ret = array( ); // pad it a bit.
534 $extra = array("", "" );
537 foreach(file($src) as $l) {
540 if (!strlen($l) || $l[0] == '#') {
544 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
547 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
548 $tbl = 'shop_' . strtolower($m[1]);
549 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
551 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
552 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
555 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
556 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
557 $extra[] = "create sequence {$tbl}_seq;";
561 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
562 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
565 // enum value -- use the text instead..
567 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
568 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
570 // ignore the alter enum
571 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
575 // UNIQUE KEY .. ignore
576 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
577 $last = array_pop($ret);
578 $ret[] = trim($last, ",");
582 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
586 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
590 // INDEX lookup ..ignore
591 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
592 $last = array_pop($ret);
593 $ret[] = trim($last, ",");
598 // CREATE INDEX ..ignore
599 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
600 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
605 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
607 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
608 $l = preg_replace('# blob#i', ' TEXT', $l);
609 $l = preg_replace('# longtext#i', ' TEXT', $l);
610 $l = preg_replace('# tinyint#i', ' INT', $l);
616 $ret = array_merge($extra,$ret);
617 // echo implode("\n", $ret); exit;
619 file_put_contents($fn, implode("\n", $ret));
625 function checkOpts($opts)
629 foreach($opts as $o=>$v) {
630 if (!preg_match('/^json-/', $o) || empty($v)) {
633 if (!file_exists($v)) {
634 die("File does not exist : OPTION --{$o} = {$v} \n");
638 $modules = array_reverse($this->modulesList());
640 // move 'project' one to the end...
642 foreach ($modules as $module){
643 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
644 if($module == 'Core' || !file_exists($file)){
648 $class = "Pman_{$module}_UpdateDatabase";
650 if(!method_exists($x, 'checkOpts')){
653 $x->checkOpts($opts);
657 static function jsonImportFromArray($opts)
659 foreach($opts as $o=>$v) {
660 if (!preg_match('/^json-/', $o) || empty($v)) {
663 $type = str_replace('_', '-', substr($o,5));
665 $data= json_decode(file_get_contents($v),true);
666 $pg = HTML_FlexyFramework::get()->page;
667 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
677 function runUpdateModulesData()
679 if (class_exists('PDO_DataObjects_Introspection')) {
680 PDO_DataObject_Introspection::$cache = array();
682 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
684 if(!in_array('Core', $this->disabled)){
685 echo "Running jsonImportFromArray\n";
686 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
689 echo "Running updateData on modules\n";
695 $modules = array_reverse($this->modulesList());
697 // move 'project' one to the end...
699 foreach ($modules as $module){
700 if(in_array($module, $this->disabled)){
703 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
704 if($module == 'Core' || !file_exists($file)){
709 $class = "Pman_{$module}_UpdateDatabase";
711 if(!method_exists($x, 'updateData')){
721 function updateDataEnums()
723 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
725 $enum = DB_DataObject::Factory('core_enum');
726 //DB_DAtaObject::debugLevel(1);
731 'name' => 'COMPTYPE',
732 'display_name' => 'Company Types',
733 'is_system_enum' => 1,
737 'display_name' => 'Owner',
738 'seqid' => 999, // last...
739 'is_system_enum' => 1,
746 'name' => 'HtmlEditor.font-family',
747 'display_name' => 'HTML Editor font families',
748 'is_system_enum' => 1,
751 'name' => 'Helvetica,Arial,sans-serif',
752 'display_name' => 'Helvetica',
757 'name' => 'Courier New',
758 'display_name' => 'Courier',
763 'display_name' => 'Tahoma',
767 'name' => 'Times New Roman,serif',
768 'display_name' => 'Times',
773 'display_name' => 'Verdana',
786 function updateDataGroups()
789 $groups = DB_DataObject::factory('core_group');
790 $groups->initGroups();
792 $groups->initDatabase($this,array(
794 'name' => 'bcc-email', // group who are bcc'ed on all requests.
795 'type' => 0, // system
798 'name' => 'system-email-from',
799 'type' => 0, // system
802 'name' => 'core-person-signup-bcc',
803 'type' => 0, // system
811 function updateDataCompanies()
814 // fix comptypes enums..
815 $c = DB_DataObject::Factory('core_company');
817 $c->selectAdd('distinct(comptype) as comptype');
818 $c->whereAdd("comptype != ''");
821 foreach($c->fetchAll('comptype') as $cts) {
825 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
828 $c = DB_DataObject::Factory('core_enum');
831 //DB_DataObject::debugLevel(1);
833 $c = DB_DataObject::Factory('core_company');
835 UPDATE {$c->tableName()}
837 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
851 function initEmails($templateDir, $emails, $mapping = false)
853 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
855 $pg = HTML_FlexyFramework::get()->page;
856 foreach($emails as $name=>$data) {
857 $cm = DB_DataObject::factory('core_email');
858 $update = $cm->get('name', $name);
861 if (empty($cm->bcc_group_id)) {
862 if (empty($data['bcc_group'])) {
863 $this->jerr("missing bcc_group for template $name");
865 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
868 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
871 if (!$g->members('email')) {
872 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
875 $cm->bcc_group_id = $g->id;
877 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
878 //if (empty($cm->test_class)) {
879 if (empty($data['test_class'])) {
880 $this->jerr("missing test_class for template $name");
883 $cm->test_class = $data['test_class'];
885 if(isset($cm->to_group_id)) {
890 !empty($data['to_group']) &&
891 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
893 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
895 if (empty($gp->id)) {
896 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
899 $cm->to_group_id = $gp->id;
903 isset($data['active']) && !isset($cm->active)
905 $cm->active = $data['active'];
908 if(!empty($data['description'])){
909 $cm->description = $cm->escape($data['description']);
912 require_once $cm->test_class . '.php';
914 $clsname = str_replace('/','_', $cm->test_class);
916 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
917 $got_it = $method->isStatic();
918 } catch(Exception $e) {
923 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
927 echo "email: {$name} - checked\n";
928 continue; /// we do not import the body content of templates that exist...
935 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
939 'file' => $templateDir. $name .'.html'
942 if (!empty($data['master'])) {
943 $opts['master'] = $templateDir . $master .'.html';
945 require_once 'Pman/Core/Import/Core_email.php';
946 $x = new Pman_Core_Import_Core_email();
948 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
950 echo "email: {$name} - CREATED\n";
955 function updateData()
958 if (class_exists('PDO_DataObjects_Introspection')) {
959 PDO_DataObject_Introspection::$cache = array();
961 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
964 $this->updateDataEnums();
965 $this->updateDataGroups();
966 $this->updateDataCompanies();
968 $c = DB_DataObject::Factory('I18n');
976 function fixMysqlInnodb()
979 static $done_check = false;
985 if (!empty($this->opts['skip-mysql-checks'])) {
988 // innodb in single files is far more efficient that MYD or one big innodb file.
989 // first check if database is using this format.
990 $db = DB_DataObject::factory('core_enum');
991 $db->query("show variables like 'innodb_file_per_table'");
993 if ($db->Value == 'OFF') {
994 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
997 $db = DB_DataObject::factory('core_enum');
998 $db->query("select version() as version");
1001 if (version_compare($db->version, '5.7', '>=' )) {
1003 $db = DB_DataObject::factory('core_enum');
1004 $db->query("show variables like 'sql_mode'");
1007 $modes = explode(",", $db->Value);
1009 // these are 'new' problems with mysql.
1011 in_array('NO_ZERO_IN_DATE', $modes) ||
1012 in_array('NO_ZERO_DATE', $modes) ||
1013 in_array('STRICT_TRANS_TABLES', $modes) ||
1014 !in_array('ALLOW_INVALID_DATES', $modes)
1016 die("Error: set sql_mode include 'ALLOW_INVALID_DATES', remove 'NO_ZERO_IN_DATE' AND 'STRICT_TRANS_TABLES' AND 'NO_ZERO_DATE' in my.cnf\n\n");
1020 $done_check = true;;
1031 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1033 function fixSequencesMysql()
1038 function fixSequencesPgsql()
1042 //DB_DataObject::debugLevel(1);
1043 $cs = DB_DataObject::factory('core_enum');
1047 CASE WHEN strpos(seq_name, '.') > 0 THEN
1050 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1053 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1054 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1058 n.nspname AS schema_name,
1059 c.relname AS table_name,
1060 a.attname AS column_name,
1061 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1063 JOIN pg_attribute a ON (c.oid=a.attrelid)
1064 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1065 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1066 WHERE has_schema_privilege(n.oid,'USAGE')
1067 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1068 AND has_table_privilege(c.oid,'SELECT')
1069 AND (NOT a.attisdropped)
1070 AND d.adsrc ~ '^nextval'
1074 CASE WHEN strpos(seq_name, '.') > 0 THEN
1075 substring(seq_name, 1,strpos(seq_name,'.')-1)
1080 GROUP BY seq_name HAVING count(*)=1
1083 while ($cs->fetch()) {
1086 foreach($cmds as $cmd) {
1087 $cs = DB_DataObject::factory('core_enum');
1091 $cs = DB_DataObject::factory('core_enum');
1093 SELECT 'SELECT SETVAL(' ||
1094 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1095 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1101 WHERE S.relkind = 'S'
1103 AND D.refobjid = T.oid
1104 AND D.refobjid = C.attrelid
1105 AND D.refobjsubid = C.attnum
1106 AND NS.oid = T.relnamespace
1110 while ($cs->fetch()) {
1113 foreach($cmds as $cmd) {
1114 $cs = DB_DataObject::factory('core_enum');
1121 var $extensions = array(
1126 function runExtensions()
1129 $ff = HTML_Flexyframework::get();
1131 $dburl = parse_url($ff->database);
1133 $dbtype = $dburl['scheme'];
1135 foreach($this->extensions as $ext) {
1137 $scls = ucfirst($dbtype). $ext;
1138 $cls = __CLASS__ . '_'. $scls;
1139 $fn = implode('/',explode('_', $cls)).'.php';
1140 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1151 function checkSystem($req = false, $pref = false)
1153 // most of these are from File_Convert...
1155 // these are required - and have simple dependancies.
1156 require_once 'System.php';
1157 $req = $req !== false ? $req : array(
1162 'rsvg-convert', //librsvg2-bin
1169 // these are prefered - but may have complicated depenacies
1170 $pref = $pref !== false ? $pref : array(
1174 'html2text', // not availabe in debian squeeze
1175 'pdftocairo', //poppler-utils - not available in debian squeeze.
1185 foreach($req as $r) {
1186 if (!System::which($r)) {
1192 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1194 foreach($pref as $r) {
1195 if (!System::which($r)) {
1201 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1208 function clearApacheDataobjectsCache()
1210 echo "Clearing Database Cache\n";
1211 // this needs to clear it's own cache along with remote one..
1214 $response = $this->curl("http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache");
1216 $json = json_decode($response, true);
1218 if(empty($json['data']) || $json['data'] != 'DONE'){
1219 echo $response. "\n";
1220 echo "Clear DataObjects Cache failed\n";
1227 function clearApacheAssetCache()
1229 echo "Clearing Asset Cache\n";
1230 $response = $this->curl(
1231 "http://localhost{$this->local_base_url}/Core/Asset",
1232 array( '_clear_cache' => 1 ,'returnHTML' => 'NO' ),
1235 $json = json_decode($response, true);
1237 if(empty($json['success']) || !$json['success']) {
1238 echo $response. "\n";
1239 echo "CURL Clear Asset cache failed\n";
1246 function curl($url, $request = array(), $method = 'GET')
1248 if($method == 'GET'){
1249 $request = http_build_query($request);
1250 $url = $url . "?" . $request;
1253 $ch = curl_init($url);
1255 if ($method == 'POST') {
1257 curl_setopt($ch, CURLOPT_POST, 1);
1258 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1261 curl_setopt($ch, CURLOPT_HTTPHEADER,
1262 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1266 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1268 curl_setopt($ch, CURLOPT_HEADER, false);
1269 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1270 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1271 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1273 $response = curl_exec($ch);
1280 static function verifyExtensions($extensions)
1284 foreach ($extensions as $e){
1286 if(extension_loaded($e)) {
1290 $error[] = "Error: Please install php extension: {$e}";
1296 $ff = HTML_FLexyFramework::get();
1298 $ff->page->jerr(implode('\n', $error));