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())
150 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
152 $this->checkSystem();
154 if (class_exists('PDO_DataObjects_Introspection')) {
155 PDO_DataObject_Introspection::$cache = array();
158 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
160 $ff = HTML_FlexyFramework::get();
162 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
163 die("Please setup Pman[local_base_url]\n");
166 $this->local_base_url = $ff->Pman['local_base_url'];
168 if(!empty($ff->Core_Notify)){
169 // require_once 'Pman/Core/NotifySmtpCheck.php';
170 // $x = new Pman_Core_NotifySmtpCheck();
174 $this->disabled = explode(',', $ff->disable);
176 //$this->fixSequencesPgsql();exit;
179 // ask all the modules to verify the opts
181 $this->checkOpts($opts);
183 if (!empty($opts['debug'])) {
184 echo "Setting debug Level : {$opts['debug']}\n";
185 DB_DataObject::DebugLevel($opts['debug']);
189 // do this first, so the innodb change + utf8 fixes column max sizes
191 // this will trigger errors about freetext indexes - we will have to remove them manually.?
192 // 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..)
194 $this->runExtensions();
197 if (empty($opts['data-only'])) {
200 if (!empty($opts['only-module-sql'])) {
204 $this->runUpdateModulesData();
206 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
207 // make sure we have a good cache...?
209 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
212 $this->runExtensions();
214 $this->generateDataobjectsCache();
219 echo "\nUpdate Completed SUCCESS\n";
223 * imports SQL files from all DataObjects directories....
225 * except any matching /migrate/
230 // loop through all the modules, and see if they have a importSQL method?
233 $ff = HTML_Flexyframework::get();
235 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
237 //$this->{'import' . $url['scheme']}($url);
239 $dbtype = $dburl['scheme'];
242 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
247 $ar = $this->modulesList();
252 if(in_array($m, $this->disabled)){
253 echo "module $m is disabled \n";
257 echo "Importing SQL from module $m\n";
258 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
263 // check to see if the class has
267 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
268 if($m != 'Core' && file_exists($file)){
271 $class = "Pman_{$m}_UpdateDatabase";
273 if(method_exists($x, 'importModuleSQL')){
274 echo "Importing SQL from module $m using Module::importModuleSQL\n";
275 $x->opts = $this->opts;
276 $x->rootDir = $this->rootDir;
277 $x->importModuleSQL($dburl);
282 echo "Importing SQL from module $m\n";
285 // if init has been called
287 if (!empty($this->opts['init'])) {
288 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
294 $fd = $this->rootDir. "/Pman/$m/DataObjects";
296 $this->{$dirmethod}($dburl, $fd);
299 // new -- sql directory..
300 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
301 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
303 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
304 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
308 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
309 if (class_exists('PDO_DataObjects_Introspection')) {
310 PDO_DataObject_Introspection::$cache = array();
312 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
314 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
315 $this->{'fixSequences'. $dbtype}();
328 /** -------------- code to handle importing a whole directory of files into the database ------- **/
331 function importpgsqldir($url, $dir, $disable_triggers = false)
333 $ff = HTML_FlexyFramework::get();
335 require_once 'System.php';
336 $cat = System::which('cat');
337 $psql = System::which('psql');
340 if (!empty($url['pass'])) {
341 putenv("PGPASSWORD=". $url['pass']);
345 ' -h ' . $url['host'] .
346 ' -U' . escapeshellarg($url['user']) .
347 ' ' . basename($url['path']);
350 echo $psql_cmd . "\n" ;
351 echo "scan : $dir\n";
354 $files = array($dir);
359 $files = glob($dir.'/*.sql');
360 uksort($files, 'strcasecmp');
362 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
363 //usort($files, $lsort);
366 foreach($files as $bfn) {
369 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
372 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
373 && !preg_match('#\.pg\.sql#i', basename($bfn))
374 ) { // skip migration scripts at present..
379 if (!preg_match('/pgsql/', basename($dir) )) {
380 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
381 $fn = $this->convertToPG($bfn);
385 // files ending in .pg.sql are native postgres files.. ## depricated
388 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
390 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
406 * mysql - does not support conversions.
410 function importmysqlidir($dburl, $dir) {
411 return $this->importmysqldir($dburl, $dir);
414 function importmysqldir($dburl, $dir)
417 $this->fixMysqlInnodb(); /// run once
419 echo "Import MYSQL :: $dir\n";
422 require_once 'System.php';
423 $cat = System::which('cat');
424 $mysql = System::which('mysql');
428 $mysql_cmd = $mysql .
429 ' -h ' . $dburl['host'] .
430 ' -u' . escapeshellarg($dburl['user']) .
431 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
432 ' ' . basename($dburl['path']);
433 //echo $mysql_cmd . "\n" ;
435 $files = glob($dir.'/*.sql');
436 uksort($files, 'strcasecmp');
439 foreach($files as $fn) {
442 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
445 // .my.sql but not .pg.sql
446 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
447 && !preg_match('#\.my\.sql#i', basename($fn))
448 ) { // skip migration scripts at present..
451 if (!strlen(trim($fn))) {
455 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
457 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
460 $fp = popen($cmd, "r");
463 // send the current file part to the browser
464 $line = trim(fgets($fp, 1024));
469 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
470 echo " ---- {$line}\n"; flush();
474 switch($matches[1]) {
475 case 1017: // cause by renaming table -- old one does not exist..
476 case 1050: // create tables triggers this..
477 case 1060: // Duplicate column name
478 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
479 case 1091: // drop index -- name does not exist.. might hide errors..
481 case 1146: // drop a index on an unknown table.. - happens rarely...
482 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
488 echo " ---- {$line}\n"; flush();
492 // 1051: // Unknown table -- normally drop = add iff exists..
493 echo "File: $fn\n$line\n";
509 * simple regex based convert mysql to pgsql...
511 function convertToPG($src)
513 //echo "Convert $src\n";
515 $fn = $this->tempName('sql');
517 $ret = array( ); // pad it a bit.
518 $extra = array("", "" );
521 foreach(file($src) as $l) {
524 if (!strlen($l) || $l[0] == '#') {
528 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
531 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
532 $tbl = 'shop_' . strtolower($m[1]);
533 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
535 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
536 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
539 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
540 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
541 $extra[] = "create sequence {$tbl}_seq;";
545 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
546 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
549 // enum value -- use the text instead..
551 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
552 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
554 // ignore the alter enum
555 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
559 // UNIQUE KEY .. ignore
560 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
561 $last = array_pop($ret);
562 $ret[] = trim($last, ",");
566 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
570 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
574 // INDEX lookup ..ignore
575 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
576 $last = array_pop($ret);
577 $ret[] = trim($last, ",");
582 // CREATE INDEX ..ignore
583 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
584 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
589 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
591 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
592 $l = preg_replace('# blob#i', ' TEXT', $l);
593 $l = preg_replace('# longtext#i', ' TEXT', $l);
594 $l = preg_replace('# tinyint#i', ' INT', $l);
600 $ret = array_merge($extra,$ret);
601 // echo implode("\n", $ret); exit;
603 file_put_contents($fn, implode("\n", $ret));
609 function checkOpts($opts)
613 foreach($opts as $o=>$v) {
614 if (!preg_match('/^json-/', $o) || empty($v)) {
617 if (!file_exists($v)) {
618 die("File does not exist : OPTION --{$o} = {$v} \n");
622 $modules = array_reverse($this->modulesList());
624 // move 'project' one to the end...
626 foreach ($modules as $module){
627 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
628 if($module == 'Core' || !file_exists($file)){
632 $class = "Pman_{$module}_UpdateDatabase";
634 if(!method_exists($x, 'checkOpts')){
637 $x->checkOpts($opts);
641 static function jsonImportFromArray($opts)
643 foreach($opts as $o=>$v) {
644 if (!preg_match('/^json-/', $o) || empty($v)) {
647 $type = str_replace('_', '-', substr($o,5));
649 $data= json_decode(file_get_contents($v),true);
650 $pg = HTML_FlexyFramework::get()->page;
651 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
661 function runUpdateModulesData()
663 if (class_exists('PDO_DataObjects_Introspection')) {
664 PDO_DataObject_Introspection::$cache = array();
666 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
668 if(!in_array('Core', $this->disabled)){
669 echo "Running jsonImportFromArray\n";
670 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
673 echo "Running updateData on modules\n";
679 $modules = array_reverse($this->modulesList());
681 // move 'project' one to the end...
683 foreach ($modules as $module){
684 if(in_array($module, $this->disabled)){
687 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
688 if($module == 'Core' || !file_exists($file)){
693 $class = "Pman_{$module}_UpdateDatabase";
695 if(!method_exists($x, 'updateData')){
705 function updateDataEnums()
707 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
709 $enum = DB_DataObject::Factory('core_enum');
710 //DB_DAtaObject::debugLevel(1);
715 'name' => 'COMPTYPE',
716 'display_name' => 'Company Types',
717 'is_system_enum' => 1,
721 'display_name' => 'Owner',
722 'seqid' => 999, // last...
723 'is_system_enum' => 1,
730 'name' => 'HtmlEditor.font-family',
731 'display_name' => 'HTML Editor font families',
732 'is_system_enum' => 1,
735 'name' => 'Helvetica,Arial,sans-serif',
736 'display_name' => 'Helvetica',
741 'name' => 'Courier New',
742 'display_name' => 'Courier',
747 'display_name' => 'Tahoma',
751 'name' => 'Times New Roman,serif',
752 'display_name' => 'Times',
757 'display_name' => 'Verdana',
770 function updateDataGroups()
773 $groups = DB_DataObject::factory('core_group');
774 $groups->initGroups();
776 $groups->initDatabase($this,array(
778 'name' => 'bcc-email', // group who are bcc'ed on all requests.
779 'type' => 0, // system
782 'name' => 'system-email-from',
783 'type' => 0, // system
786 'name' => 'core-person-signup-bcc',
787 'type' => 0, // system
795 function updateDataCompanies()
798 // fix comptypes enums..
799 $c = DB_DataObject::Factory('core_company');
801 $c->selectAdd('distinct(comptype) as comptype');
802 $c->whereAdd("comptype != ''");
805 foreach($c->fetchAll('comptype') as $cts) {
809 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
812 $c = DB_DataObject::Factory('core_enum');
815 //DB_DataObject::debugLevel(1);
817 $c = DB_DataObject::Factory('core_company');
819 UPDATE {$c->tableName()}
821 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
835 function initEmails($templateDir, $emails, $mapping = false)
837 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
839 $pg = HTML_FlexyFramework::get()->page;
840 foreach($emails as $name=>$data) {
841 $cm = DB_DataObject::factory('core_email');
842 $update = $cm->get('name', $name);
845 if (empty($cm->bcc_group_id)) {
846 if (empty($data['bcc_group'])) {
847 $this->jerr("missing bcc_group for template $name");
849 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
852 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
855 if (!$g->members('email')) {
856 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
859 $cm->bcc_group_id = $g->id;
861 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
862 //if (empty($cm->test_class)) {
863 if (empty($data['test_class'])) {
864 $this->jerr("missing test_class for template $name");
866 $cm->test_class = $data['test_class'];
868 if(isset($cm->to_group_id)) {
873 !empty($data['to_group']) &&
874 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
876 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
878 if (empty($gp->id)) {
879 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
882 $cm->to_group_id = $gp->id;
886 isset($data['active']) && !isset($cm->active)
888 $cm->active = $data['active'];
891 require_once $cm->test_class . '.php';
893 $clsname = str_replace('/','_', $cm->test_class);
895 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
896 $got_it = $method->isStatic();
897 } catch(Exception $e) {
902 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
906 echo "email: {$name} - checked\n";
907 continue; /// we do not import the body content of templates that exist...
914 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
918 'file' => $templateDir. $name .'.html'
921 if (!empty($data['master'])) {
922 $opts['master'] = $templateDir . $master .'.html';
924 require_once 'Pman/Core/Import/Core_email.php';
925 $x = new Pman_Core_Import_Core_email();
927 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
929 echo "email: {$name} - CREATED\n";
934 function updateData()
937 if (class_exists('PDO_DataObjects_Introspection')) {
938 PDO_DataObject_Introspection::$cache = array();
940 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
941 $this->updateDataEnums();
942 $this->updateDataGroups();
943 $this->updateDataCompanies();
945 $c = DB_DataObject::Factory('I18n');
953 function fixMysqlInnodb()
956 static $done_check = false;
962 if (!empty($this->opts['skip-mysql-checks'])) {
965 // innodb in single files is far more efficient that MYD or one big innodb file.
966 // first check if database is using this format.
967 $db = DB_DataObject::factory('core_enum');
968 $db->query("show variables like 'innodb_file_per_table'");
970 if ($db->Value == 'OFF') {
971 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
974 $db = DB_DataObject::factory('core_enum');
975 $db->query("select version() as version");
978 if (version_compare($db->version, '5.7', '>=' )) {
980 $db = DB_DataObject::factory('core_enum');
981 $db->query("show variables like 'sql_mode'");
984 $modes = explode(",", $db->Value);
986 // these are 'new' problems with mysql.
988 in_array('NO_ZERO_IN_DATE', $modes) ||
989 in_array('NO_ZERO_DATE', $modes) ||
990 in_array('STRICT_TRANS_TABLES', $modes) ||
991 !in_array('ALLOW_INVALID_DATES', $modes)
993 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");
1008 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1010 function fixSequencesMysql()
1015 function fixSequencesPgsql()
1019 //DB_DataObject::debugLevel(1);
1020 $cs = DB_DataObject::factory('core_enum');
1024 CASE WHEN strpos(seq_name, '.') > 0 THEN
1027 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1030 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1031 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1035 n.nspname AS schema_name,
1036 c.relname AS table_name,
1037 a.attname AS column_name,
1038 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1040 JOIN pg_attribute a ON (c.oid=a.attrelid)
1041 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1042 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1043 WHERE has_schema_privilege(n.oid,'USAGE')
1044 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1045 AND has_table_privilege(c.oid,'SELECT')
1046 AND (NOT a.attisdropped)
1047 AND d.adsrc ~ '^nextval'
1051 CASE WHEN strpos(seq_name, '.') > 0 THEN
1052 substring(seq_name, 1,strpos(seq_name,'.')-1)
1057 GROUP BY seq_name HAVING count(*)=1
1060 while ($cs->fetch()) {
1063 foreach($cmds as $cmd) {
1064 $cs = DB_DataObject::factory('core_enum');
1068 $cs = DB_DataObject::factory('core_enum');
1070 SELECT 'SELECT SETVAL(' ||
1071 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1072 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1078 WHERE S.relkind = 'S'
1080 AND D.refobjid = T.oid
1081 AND D.refobjid = C.attrelid
1082 AND D.refobjsubid = C.attnum
1083 AND NS.oid = T.relnamespace
1087 while ($cs->fetch()) {
1090 foreach($cmds as $cmd) {
1091 $cs = DB_DataObject::factory('core_enum');
1098 var $extensions = array(
1103 function runExtensions()
1106 $ff = HTML_Flexyframework::get();
1108 $dburl = parse_url($ff->database);
1110 $dbtype = $dburl['scheme'];
1112 foreach($this->extensions as $ext) {
1114 $scls = ucfirst($dbtype). $ext;
1115 $cls = __CLASS__ . '_'. $scls;
1116 $fn = implode('/',explode('_', $cls)).'.php';
1117 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1128 function checkSystem($req = false, $pref = false)
1130 // most of these are from File_Convert...
1132 // these are required - and have simple dependancies.
1133 require_once 'System.php';
1134 $req = $req !== false ? $req : array(
1139 'rsvg-convert', //librsvg2-bin
1146 // these are prefered - but may have complicated depenacies
1147 $pref = $pref !== false ? $pref : array(
1151 'html2text', // not availabe in debian squeeze
1152 'pdftocairo', //poppler-utils - not available in debian squeeze.
1162 foreach($req as $r) {
1163 if (!System::which($r)) {
1169 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1171 foreach($pref as $r) {
1172 if (!System::which($r)) {
1178 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1185 function generateDataobjectsCache()
1187 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1193 function curl($url, $request = array(), $method = 'GET')
1195 if($method == 'GET'){
1196 $request = http_build_query($request);
1197 $url = $url . "?" . $request;
1200 $ch = curl_init($url);
1202 if ($method == 'POST') {
1204 curl_setopt($ch, CURLOPT_POST, 1);
1205 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1209 curl_setopt($ch, CURLOPT_HTTPHEADER,
1210 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1214 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1216 curl_setopt($ch, CURLOPT_HEADER, false);
1217 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1218 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1219 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1221 $response = curl_exec($ch);