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');
112 $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
121 var $disabled = array();
126 var $local_base_url = false;
131 $ff = HTML_FlexyFramework::get();
132 if (!empty($ff->cli)) {
137 parent::getAuth(); // load company!
138 $au = $this->getAuthUser();
139 if (!$au || $au->company()->comptype != 'OWNER') {
140 $this->jerr("Not authenticated", array('authFailure' => true));
142 $this->authUser = $au;
146 function get($args, $opts=array())
148 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
150 $this->checkSystem();
152 if (class_exists('PDO_DataObjects_Introspection')) {
153 PDO_DataObject_Introspection::$cache = array();
156 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
158 $ff = HTML_FlexyFramework::get();
160 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
161 die("Please setup Pman[local_base_url]\n");
164 $this->local_base_url = $ff->Pman['local_base_url'];
166 if(!empty($ff->Core_Notify)){
167 // require_once 'Pman/Core/NotifySmtpCheck.php';
168 // $x = new Pman_Core_NotifySmtpCheck();
172 $this->disabled = explode(',', $ff->disable);
174 //$this->fixSequencesPgsql();exit;
177 // ask all the modules to verify the opts
179 $this->checkOpts($opts);
181 if (!empty($opts['debug'])) {
182 echo "Setting debug Level : {$opts['debug']}\n";
183 DB_DataObject::DebugLevel($opts['debug']);
187 // do this first, so the innodb change + utf8 fixes column max sizes
189 // this will trigger errors about freetext indexes - we will have to remove them manually.?
190 // 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..)
192 $this->runExtensions();
195 if (empty($opts['data-only'])) {
198 if (!empty($opts['only-module-sql'])) {
202 $this->runUpdateModulesData();
204 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
205 // make sure we have a good cache...?
207 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
210 $this->runExtensions();
212 $this->generateDataobjectsCache();
217 echo "\nUpdate Completed SUCCESS\n";
221 * imports SQL files from all DataObjects directories....
223 * except any matching /migrate/
228 // loop through all the modules, and see if they have a importSQL method?
231 $ff = HTML_Flexyframework::get();
233 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
235 //$this->{'import' . $url['scheme']}($url);
237 $dbtype = $dburl['scheme'];
240 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
245 $ar = $this->modulesList();
250 if(in_array($m, $this->disabled)){
251 echo "module $m is disabled \n";
255 echo "Importing SQL from module $m\n";
256 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
261 // check to see if the class has
265 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
266 if($m != 'Core' && file_exists($file)){
269 $class = "Pman_{$m}_UpdateDatabase";
271 if(method_exists($x, 'importModuleSQL')){
272 echo "Importing SQL from module $m using Module::importModuleSQL\n";
273 $x->opts = $this->opts;
274 $x->rootDir = $this->rootDir;
275 $x->importModuleSQL($dburl);
280 echo "Importing SQL from module $m\n";
283 // if init has been called
285 if (!empty($this->opts['init'])) {
286 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
292 $fd = $this->rootDir. "/Pman/$m/DataObjects";
294 $this->{$dirmethod}($dburl, $fd);
297 // new -- sql directory..
298 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
299 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
301 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
302 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
306 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
307 if (class_exists('PDO_DataObjects_Introspection')) {
308 PDO_DataObject_Introspection::$cache = array();
310 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
312 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
313 $this->{'fixSequences'. $dbtype}();
326 /** -------------- code to handle importing a whole directory of files into the database ------- **/
329 function importpgsqldir($url, $dir, $disable_triggers = false)
331 $ff = HTML_FlexyFramework::get();
333 require_once 'System.php';
334 $cat = System::which('cat');
335 $psql = System::which('psql');
338 if (!empty($url['pass'])) {
339 putenv("PGPASSWORD=". $url['pass']);
343 ' -h ' . $url['host'] .
344 ' -U' . escapeshellarg($url['user']) .
345 ' ' . basename($url['path']);
348 echo $psql_cmd . "\n" ;
349 echo "scan : $dir\n";
352 $files = array($dir);
357 $files = glob($dir.'/*.sql');
358 uksort($files, 'strcasecmp');
360 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
361 //usort($files, $lsort);
364 foreach($files as $bfn) {
367 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
370 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
371 && !preg_match('#\.pg\.sql#i', basename($bfn))
372 ) { // skip migration scripts at present..
377 if (!preg_match('/pgsql/', basename($dir) )) {
378 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
379 $fn = $this->convertToPG($bfn);
383 // files ending in .pg.sql are native postgres files.. ## depricated
386 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
388 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
404 * mysql - does not support conversions.
408 function importmysqlidir($dburl, $dir) {
409 return $this->importmysqldir($dburl, $dir);
412 function importmysqldir($dburl, $dir)
415 $this->fixMysqlInnodb(); /// run once
417 echo "Import MYSQL :: $dir\n";
420 require_once 'System.php';
421 $cat = System::which('cat');
422 $mysql = System::which('mysql');
426 $mysql_cmd = $mysql .
427 ' -h ' . $dburl['host'] .
428 ' -u' . escapeshellarg($dburl['user']) .
429 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
430 ' ' . basename($dburl['path']);
431 //echo $mysql_cmd . "\n" ;
433 $files = glob($dir.'/*.sql');
434 uksort($files, 'strcasecmp');
437 foreach($files as $fn) {
440 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
443 // .my.sql but not .pg.sql
444 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
445 && !preg_match('#\.my\.sql#i', basename($fn))
446 ) { // skip migration scripts at present..
449 if (!strlen(trim($fn))) {
453 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
455 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
458 $fp = popen($cmd, "r");
461 // send the current file part to the browser
462 $line = trim(fgets($fp, 1024));
467 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
468 echo " ---- {$line}\n"; flush();
472 switch($matches[1]) {
473 case 1017: // cause by renaming table -- old one does not exist..
474 case 1050: // create tables triggers this..
475 case 1060: // Duplicate column name
476 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
477 case 1091: // drop index -- name does not exist.. might hide errors..
479 case 1146: // drop a index on an unknown table.. - happens rarely...
480 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
486 echo " ---- {$line}\n"; flush();
490 // 1051: // Unknown table -- normally drop = add iff exists..
491 echo "File: $fn\n$line\n";
507 * simple regex based convert mysql to pgsql...
509 function convertToPG($src)
511 //echo "Convert $src\n";
513 $fn = $this->tempName('sql');
515 $ret = array( ); // pad it a bit.
516 $extra = array("", "" );
519 foreach(file($src) as $l) {
522 if (!strlen($l) || $l[0] == '#') {
526 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
529 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
530 $tbl = 'shop_' . strtolower($m[1]);
531 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
533 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
534 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
537 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
538 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
539 $extra[] = "create sequence {$tbl}_seq;";
543 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
544 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
547 // enum value -- use the text instead..
549 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
550 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
552 // ignore the alter enum
553 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
557 // UNIQUE KEY .. ignore
558 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
559 $last = array_pop($ret);
560 $ret[] = trim($last, ",");
564 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
568 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
572 // INDEX lookup ..ignore
573 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
574 $last = array_pop($ret);
575 $ret[] = trim($last, ",");
580 // CREATE INDEX ..ignore
581 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
582 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
587 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
589 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
590 $l = preg_replace('# blob#i', ' TEXT', $l);
591 $l = preg_replace('# longtext#i', ' TEXT', $l);
592 $l = preg_replace('# tinyint#i', ' INT', $l);
598 $ret = array_merge($extra,$ret);
599 // echo implode("\n", $ret); exit;
601 file_put_contents($fn, implode("\n", $ret));
607 function checkOpts($opts)
611 foreach($opts as $o=>$v) {
612 if (!preg_match('/^json-/', $o) || empty($v)) {
615 if (!file_exists($v)) {
616 die("File does not exist : OPTION --{$o} = {$v} \n");
620 $modules = array_reverse($this->modulesList());
622 // move 'project' one to the end...
624 foreach ($modules as $module){
625 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
626 if($module == 'Core' || !file_exists($file)){
630 $class = "Pman_{$module}_UpdateDatabase";
632 if(!method_exists($x, 'checkOpts')){
635 $x->checkOpts($opts);
639 static function jsonImportFromArray($opts)
641 foreach($opts as $o=>$v) {
642 if (!preg_match('/^json-/', $o) || empty($v)) {
645 $type = str_replace('_', '-', substr($o,5));
647 $data= json_decode(file_get_contents($v),true);
648 $pg = HTML_FlexyFramework::get()->page;
649 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
659 function runUpdateModulesData()
661 if (class_exists('PDO_DataObjects_Introspection')) {
662 PDO_DataObject_Introspection::$cache = array();
664 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
666 if(!in_array('Core', $this->disabled)){
667 echo "Running jsonImportFromArray\n";
668 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
671 echo "Running updateData on modules\n";
677 $modules = array_reverse($this->modulesList());
679 // move 'project' one to the end...
681 foreach ($modules as $module){
682 if(in_array($module, $this->disabled)){
685 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
686 if($module == 'Core' || !file_exists($file)){
691 $class = "Pman_{$module}_UpdateDatabase";
693 if(!method_exists($x, 'updateData')){
703 function updateDataEnums()
705 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
707 $enum = DB_DataObject::Factory('core_enum');
708 //DB_DAtaObject::debugLevel(1);
713 'name' => 'COMPTYPE',
714 'display_name' => 'Company Types',
715 'is_system_enum' => 1,
719 'display_name' => 'Owner',
720 'seqid' => 999, // last...
721 'is_system_enum' => 1,
728 'name' => 'HtmlEditor.font-family',
729 'display_name' => 'HTML Editor font families',
730 'is_system_enum' => 1,
733 'name' => 'Helvetica,Arial,sans-serif',
734 'display_name' => 'Helvetica',
739 'name' => 'Courier New',
740 'display_name' => 'Courier',
745 'display_name' => 'Tahoma',
749 'name' => 'Times New Roman,serif',
750 'display_name' => 'Times',
755 'display_name' => 'Verdana',
768 function updateDataGroups()
771 $groups = DB_DataObject::factory('core_group');
772 $groups->initGroups();
774 $groups->initDatabase($this,array(
776 'name' => 'bcc-email', // group who are bcc'ed on all requests.
777 'type' => 0, // system
780 'name' => 'system-email-from',
781 'type' => 0, // system
784 'name' => 'core-person-signup-bcc',
785 'type' => 0, // system
793 function updateDataCompanies()
796 // fix comptypes enums..
797 $c = DB_DataObject::Factory('core_company');
799 $c->selectAdd('distinct(comptype) as comptype');
800 $c->whereAdd("comptype != ''");
803 foreach($c->fetchAll('comptype') as $cts) {
807 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
810 $c = DB_DataObject::Factory('core_enum');
813 //DB_DataObject::debugLevel(1);
815 $c = DB_DataObject::Factory('core_company');
817 UPDATE {$c->tableName()}
819 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
833 function initEmails($templateDir, $emails, $mapping = false)
835 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
837 $pg = HTML_FlexyFramework::get()->page;
838 foreach($emails as $name=>$data) {
839 $cm = DB_DataObject::factory('core_email');
840 $update = $cm->get('name', $name);
843 if (empty($cm->bcc_group_id)) {
844 if (empty($data['bcc_group'])) {
845 $this->jerr("missing bcc_group for template $name");
847 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
850 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
853 if (!$g->members('email')) {
854 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
857 $cm->bcc_group_id = $g->id;
859 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
860 //if (empty($cm->test_class)) {
861 if (empty($data['test_class'])) {
862 $this->jerr("missing test_class for template $name");
864 $cm->test_class = $data['test_class'];
866 if(isset($cm->to_group_id)) {
871 !empty($data['to_group']) &&
872 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
874 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
876 if (empty($gp->id)) {
877 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
880 $cm->to_group_id = $gp->id;
884 isset($data['active']) && !isset($cm->active)
886 $cm->active = $data['active'];
889 require_once $cm->test_class . '.php';
891 $clsname = str_replace('/','_', $cm->test_class);
893 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
894 $got_it = $method->isStatic();
895 } catch(Exception $e) {
900 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
904 echo "email: {$name} - checked\n";
905 continue; /// we do not import the body content of templates that exist...
912 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
916 'file' => $templateDir. $name .'.html'
919 if (!empty($data['master'])) {
920 $opts['master'] = $templateDir . $master .'.html';
922 require_once 'Pman/Core/Import/Core_email.php';
923 $x = new Pman_Core_Import_Core_email();
925 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
927 echo "email: {$name} - CREATED\n";
932 function updateData()
935 if (class_exists('PDO_DataObjects_Introspection')) {
936 PDO_DataObject_Introspection::$cache = array();
938 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
939 $this->updateDataEnums();
940 $this->updateDataGroups();
941 $this->updateDataCompanies();
943 $c = DB_DataObject::Factory('I18n');
951 function fixMysqlInnodb()
954 static $done_check = false;
960 if (!empty($this->opts['skip-mysql-checks'])) {
963 // innodb in single files is far more efficient that MYD or one big innodb file.
964 // first check if database is using this format.
965 $db = DB_DataObject::factory('core_enum');
966 $db->query("show variables like 'innodb_file_per_table'");
968 if ($db->Value == 'OFF') {
969 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
972 $db = DB_DataObject::factory('core_enum');
973 $db->query("select version() as version");
976 if (version_compare($db->version, '5.7', '>=' )) {
978 $db = DB_DataObject::factory('core_enum');
979 $db->query("show variables like 'sql_mode'");
982 $modes = explode(",", $db->Value);
984 // these are 'new' problems with mysql.
986 in_array('NO_ZERO_IN_DATE', $modes) ||
987 in_array('NO_ZERO_DATE', $modes) ||
988 in_array('STRICT_TRANS_TABLES', $modes) ||
989 !in_array('ALLOW_INVALID_DATES', $modes)
991 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");
1006 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1008 function fixSequencesMysql()
1013 function fixSequencesPgsql()
1017 //DB_DataObject::debugLevel(1);
1018 $cs = DB_DataObject::factory('core_enum');
1022 CASE WHEN strpos(seq_name, '.') > 0 THEN
1025 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1028 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1029 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1033 n.nspname AS schema_name,
1034 c.relname AS table_name,
1035 a.attname AS column_name,
1036 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1038 JOIN pg_attribute a ON (c.oid=a.attrelid)
1039 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1040 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1041 WHERE has_schema_privilege(n.oid,'USAGE')
1042 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1043 AND has_table_privilege(c.oid,'SELECT')
1044 AND (NOT a.attisdropped)
1045 AND d.adsrc ~ '^nextval'
1049 CASE WHEN strpos(seq_name, '.') > 0 THEN
1050 substring(seq_name, 1,strpos(seq_name,'.')-1)
1055 GROUP BY seq_name HAVING count(*)=1
1058 while ($cs->fetch()) {
1061 foreach($cmds as $cmd) {
1062 $cs = DB_DataObject::factory('core_enum');
1066 $cs = DB_DataObject::factory('core_enum');
1068 SELECT 'SELECT SETVAL(' ||
1069 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1070 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1076 WHERE S.relkind = 'S'
1078 AND D.refobjid = T.oid
1079 AND D.refobjid = C.attrelid
1080 AND D.refobjsubid = C.attnum
1081 AND NS.oid = T.relnamespace
1085 while ($cs->fetch()) {
1088 foreach($cmds as $cmd) {
1089 $cs = DB_DataObject::factory('core_enum');
1096 var $extensions = array(
1101 function runExtensions()
1104 $ff = HTML_Flexyframework::get();
1106 $dburl = parse_url($ff->database);
1108 $dbtype = $dburl['scheme'];
1110 foreach($this->extensions as $ext) {
1112 $scls = ucfirst($dbtype). $ext;
1113 $cls = __CLASS__ . '_'. $scls;
1114 $fn = implode('/',explode('_', $cls)).'.php';
1115 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1126 function checkSystem($req = false, $pref = false)
1128 // most of these are from File_Convert...
1130 // these are required - and have simple dependancies.
1131 require_once 'System.php';
1132 $req = $req !== false ? $req : array(
1137 'rsvg-convert', //librsvg2-bin
1144 // these are prefered - but may have complicated depenacies
1145 $pref = $pref !== false ? $pref : array(
1149 'html2text', // not availabe in debian squeeze
1150 'pdftocairo', //poppler-utils - not available in debian squeeze.
1160 foreach($req as $r) {
1161 if (!System::which($r)) {
1167 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1169 foreach($pref as $r) {
1170 if (!System::which($r)) {
1176 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1183 function generateDataobjectsCache()
1185 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1191 function curl($url, $request = array(), $method = 'GET')
1193 if($method == 'GET'){
1194 $request = http_build_query($request);
1195 $url = $url . "?" . $request;
1198 $ch = curl_init($url);
1200 if ($method == 'POST') {
1202 curl_setopt($ch, CURLOPT_POST, 1);
1203 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1207 curl_setopt($ch, CURLOPT_HTTPHEADER,
1208 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1212 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1214 curl_setopt($ch, CURLOPT_HEADER, false);
1215 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1216 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1217 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1219 $response = curl_exec($ch);