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',
86 static function cli_opts()
89 $ret = self::$cli_opts;
90 $ff = HTML_FlexyFramework::get();
92 $mods = $a->modulesList();
93 foreach($mods as $m) {
95 $fd = $ff->rootDir. "/Pman/$m/UpdateDatabase.php";
96 if (!file_exists($fd)) {
102 $cls = new ReflectionClass('Pman_'. $m . '_UpdateDatabase');
104 $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
113 var $disabled = array();
118 var $local_base_url = false;
123 $ff = HTML_FlexyFramework::get();
124 if (!empty($ff->cli)) {
129 parent::getAuth(); // load company!
130 $au = $this->getAuthUser();
131 if (!$au || $au->company()->comptype != 'OWNER') {
132 $this->jerr("Not authenticated", array('authFailure' => true));
134 $this->authUser = $au;
138 function get($args, $opts=array())
140 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
142 $this->checkSystem();
144 if (class_exists('PDO_DataObjects_Introspection')) {
145 PDO_DataObject_Introspection::$cache = array();
148 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
150 $ff = HTML_FlexyFramework::get();
152 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
153 die("Please setup Pman[local_base_url]\n");
156 $this->local_base_url = $ff->Pman['local_base_url'];
158 if(!empty($ff->Core_Notify)){
159 // require_once 'Pman/Core/NotifySmtpCheck.php';
160 // $x = new Pman_Core_NotifySmtpCheck();
164 $this->disabled = explode(',', $ff->disable);
166 //$this->fixSequencesPgsql();exit;
169 // ask all the modules to verify the opts
171 $this->checkOpts($opts);
174 // do this first, so the innodb change + utf8 fixes column max sizes
176 // this will trigger errors about freetext indexes - we will have to remove them manually.?
177 // 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..)
179 $this->runExtensions();
182 if (empty($opts['data-only'])) {
185 if (!empty($opts['only-module-sql'])) {
189 $this->runUpdateModulesData();
191 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
192 // make sure we have a good cache...?
194 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
197 $this->runExtensions();
199 $this->generateDataobjectsCache();
204 echo "\nUpdate Completed SUCCESS\n";
208 * imports SQL files from all DataObjects directories....
210 * except any matching /migrate/
215 // loop through all the modules, and see if they have a importSQL method?
218 $ff = HTML_Flexyframework::get();
220 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
222 //$this->{'import' . $url['scheme']}($url);
224 $dbtype = $dburl['scheme'];
227 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
232 $ar = $this->modulesList();
237 if(in_array($m, $this->disabled)){
238 echo "module $m is disabled \n";
242 echo "Importing SQL from module $m\n";
243 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
248 // check to see if the class has
252 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
253 if($m != 'Core' && file_exists($file)){
256 $class = "Pman_{$m}_UpdateDatabase";
258 if(method_exists($x, 'importModuleSQL')){
259 echo "Importing SQL from module $m using Module::importModuleSQL\n";
260 $x->opts = $this->opts;
261 $x->rootDir = $this->rootDir;
262 $x->importModuleSQL($dburl);
267 echo "Importing SQL from module $m\n";
270 // if init has been called
272 if (!empty($this->opts['init'])) {
273 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
279 $fd = $this->rootDir. "/Pman/$m/DataObjects";
281 $this->{$dirmethod}($dburl, $fd);
284 // new -- sql directory..
285 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
286 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
288 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
289 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
293 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
294 if (class_exists('PDO_DataObjects_Introspection')) {
295 PDO_DataObject_Introspection::$cache = array();
297 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
299 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
300 $this->{'fixSequences'. $dbtype}();
313 /** -------------- code to handle importing a whole directory of files into the database ------- **/
316 function importpgsqldir($url, $dir, $disable_triggers = false)
318 $ff = HTML_FlexyFramework::get();
320 require_once 'System.php';
321 $cat = System::which('cat');
322 $psql = System::which('psql');
325 if (!empty($url['pass'])) {
326 putenv("PGPASSWORD=". $url['pass']);
330 ' -h ' . $url['host'] .
331 ' -U' . escapeshellarg($url['user']) .
332 ' ' . basename($url['path']);
335 echo $psql_cmd . "\n" ;
336 echo "scan : $dir\n";
339 $files = array($dir);
344 $files = glob($dir.'/*.sql');
345 uksort($files, 'strcasecmp');
347 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
348 //usort($files, $lsort);
351 foreach($files as $bfn) {
354 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
357 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
358 && !preg_match('#\.pg\.sql#i', basename($bfn))
359 ) { // skip migration scripts at present..
364 if (!preg_match('/pgsql/', basename($dir) )) {
365 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
366 $fn = $this->convertToPG($bfn);
370 // files ending in .pg.sql are native postgres files.. ## depricated
373 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
375 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
391 * mysql - does not support conversions.
395 function importmysqlidir($dburl, $dir) {
396 return $this->importmysqldir($dburl, $dir);
399 function importmysqldir($dburl, $dir)
402 $this->fixMysqlInnodb(); /// run once
404 echo "Import MYSQL :: $dir\n";
407 require_once 'System.php';
408 $cat = System::which('cat');
409 $mysql = System::which('mysql');
413 $mysql_cmd = $mysql .
414 ' -h ' . $dburl['host'] .
415 ' -u' . escapeshellarg($dburl['user']) .
416 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
417 ' ' . basename($dburl['path']);
418 //echo $mysql_cmd . "\n" ;
420 $files = glob($dir.'/*.sql');
421 uksort($files, 'strcasecmp');
424 foreach($files as $fn) {
427 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
430 // .my.sql but not .pg.sql
431 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
432 && !preg_match('#\.my\.sql#i', basename($fn))
433 ) { // skip migration scripts at present..
436 if (!strlen(trim($fn))) {
440 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
442 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
445 $fp = popen($cmd, "r");
448 // send the current file part to the browser
449 $line = trim(fgets($fp, 1024));
454 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
455 echo " ---- {$line}\n"; flush();
459 switch($matches[1]) {
460 case 1017: // cause by renaming table -- old one does not exist..
461 case 1050: // create tables triggers this..
462 case 1060: // Duplicate column name
463 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
464 case 1091: // drop index -- name does not exist.. might hide errors..
466 case 1146: // drop a index on an unknown table.. - happens rarely...
467 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
473 echo " ---- {$line}\n"; flush();
477 // 1051: // Unknown table -- normally drop = add iff exists..
478 echo "File: $fn\n$line\n";
494 * simple regex based convert mysql to pgsql...
496 function convertToPG($src)
498 //echo "Convert $src\n";
500 $fn = $this->tempName('sql');
502 $ret = array( ); // pad it a bit.
503 $extra = array("", "" );
506 foreach(file($src) as $l) {
509 if (!strlen($l) || $l[0] == '#') {
513 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
516 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
517 $tbl = 'shop_' . strtolower($m[1]);
518 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
520 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
521 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
524 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
525 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
526 $extra[] = "create sequence {$tbl}_seq;";
530 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
531 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
534 // enum value -- use the text instead..
536 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
537 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
539 // ignore the alter enum
540 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
544 // UNIQUE KEY .. ignore
545 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
546 $last = array_pop($ret);
547 $ret[] = trim($last, ",");
551 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
555 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
559 // INDEX lookup ..ignore
560 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
561 $last = array_pop($ret);
562 $ret[] = trim($last, ",");
567 // CREATE INDEX ..ignore
568 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
569 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
574 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
576 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
577 $l = preg_replace('# blob#i', ' TEXT', $l);
578 $l = preg_replace('# longtext#i', ' TEXT', $l);
579 $l = preg_replace('# tinyint#i', ' INT', $l);
585 $ret = array_merge($extra,$ret);
586 // echo implode("\n", $ret); exit;
588 file_put_contents($fn, implode("\n", $ret));
594 function checkOpts($opts)
598 foreach($opts as $o=>$v) {
599 if (!preg_match('/^json-/', $o) || empty($v)) {
602 if (!file_exists($v)) {
603 die("File does not exist : OPTION --{$o} = {$v} \n");
607 $modules = array_reverse($this->modulesList());
609 // move 'project' one to the end...
611 foreach ($modules as $module){
612 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
613 if($module == 'Core' || !file_exists($file)){
617 $class = "Pman_{$module}_UpdateDatabase";
619 if(!method_exists($x, 'checkOpts')){
622 $x->checkOpts($opts);
626 static function jsonImportFromArray($opts)
628 foreach($opts as $o=>$v) {
629 if (!preg_match('/^json-/', $o) || empty($v)) {
632 $type = str_replace('_', '-', substr($o,5));
634 $data= json_decode(file_get_contents($v),true);
635 $pg = HTML_FlexyFramework::get()->page;
636 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
646 function runUpdateModulesData()
648 if (class_exists('PDO_DataObjects_Introspection')) {
649 PDO_DataObject_Introspection::$cache = array();
651 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
653 if(!in_array('Core', $this->disabled)){
654 echo "Running jsonImportFromArray\n";
655 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
658 echo "Running updateData on modules\n";
664 $modules = array_reverse($this->modulesList());
666 // move 'project' one to the end...
668 foreach ($modules as $module){
669 if(in_array($module, $this->disabled)){
672 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
673 if($module == 'Core' || !file_exists($file)){
678 $class = "Pman_{$module}_UpdateDatabase";
680 if(!method_exists($x, 'updateData')){
690 function updateDataEnums()
692 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
694 $enum = DB_DataObject::Factory('core_enum');
695 //DB_DAtaObject::debugLevel(1);
700 'name' => 'COMPTYPE',
701 'display_name' => 'Company Types',
702 'is_system_enum' => 1,
706 'display_name' => 'Owner',
707 'seqid' => 999, // last...
708 'is_system_enum' => 1,
715 'name' => 'HtmlEditor.font-family',
716 'display_name' => 'HTML Editor font families',
717 'is_system_enum' => 1,
720 'name' => 'Helvetica,Arial,sans-serif',
721 'display_name' => 'Helvetica',
726 'name' => 'Courier New',
727 'display_name' => 'Courier',
732 'display_name' => 'Tahoma',
736 'name' => 'Times New Roman,serif',
737 'display_name' => 'Times',
742 'display_name' => 'Verdana',
755 function updateDataGroups()
758 $groups = DB_DataObject::factory('core_group');
759 $groups->initGroups();
761 $groups->initDatabase($this,array(
763 'name' => 'bcc-email', // group who are bcc'ed on all requests.
764 'type' => 0, // system
767 'name' => 'system-email-from',
768 'type' => 0, // system
771 'name' => 'core-person-signup-bcc',
772 'type' => 0, // system
780 function updateDataCompanies()
783 // fix comptypes enums..
784 $c = DB_DataObject::Factory('core_company');
786 $c->selectAdd('distinct(comptype) as comptype');
787 $c->whereAdd("comptype != ''");
790 foreach($c->fetchAll('comptype') as $cts) {
794 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
797 $c = DB_DataObject::Factory('core_enum');
800 //DB_DataObject::debugLevel(1);
802 $c = DB_DataObject::Factory('core_company');
804 UPDATE {$c->tableName()}
806 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
820 function initEmails($templateDir, $emails, $mapping = false)
822 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
824 $pg = HTML_FlexyFramework::get()->page;
825 foreach($emails as $name=>$data) {
826 $cm = DB_DataObject::factory('core_email');
827 $update = $cm->get('name', $name);
830 if (empty($cm->bcc_group_id)) {
831 if (empty($data['bcc_group'])) {
832 $this->jerr("missing bcc_group for template $name");
834 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
837 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
840 if (!$g->members('email')) {
841 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
844 $cm->bcc_group_id = $g->id;
846 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
847 //if (empty($cm->test_class)) {
848 if (empty($data['test_class'])) {
849 $this->jerr("missing test_class for template $name");
851 $cm->test_class = $data['test_class'];
853 if(isset($cm->to_group_id)) {
858 !empty($data['to_group']) &&
859 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
861 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
863 if (empty($gp->id)) {
864 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
867 $cm->to_group_id = $gp->id;
871 isset($data['active']) && !isset($cm->active)
873 $cm->active = $data['active'];
876 require_once $cm->test_class . '.php';
878 $clsname = str_replace('/','_', $cm->test_class);
880 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
881 $got_it = $method->isStatic();
882 } catch(Exception $e) {
887 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
891 echo "email: {$name} - checked\n";
892 continue; /// we do not import the body content of templates that exist...
899 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
903 'file' => $templateDir. $name .'.html'
906 if (!empty($data['master'])) {
907 $opts['master'] = $templateDir . $master .'.html';
909 require_once 'Pman/Core/Import/Core_email.php';
910 $x = new Pman_Core_Import_Core_email();
912 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
914 echo "email: {$name} - CREATED\n";
919 function updateData()
922 if (class_exists('PDO_DataObjects_Introspection')) {
923 PDO_DataObject_Introspection::$cache = array();
925 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
926 $this->updateDataEnums();
927 $this->updateDataGroups();
928 $this->updateDataCompanies();
930 $c = DB_DataObject::Factory('I18n');
938 function fixMysqlInnodb()
941 static $done_check = false;
947 if (!empty($this->opts['skip-mysql-checks'])) {
950 // innodb in single files is far more efficient that MYD or one big innodb file.
951 // first check if database is using this format.
952 $db = DB_DataObject::factory('core_enum');
953 $db->query("show variables like 'innodb_file_per_table'");
955 if ($db->Value == 'OFF') {
956 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
959 $db = DB_DataObject::factory('core_enum');
960 $db->query("select version() as version");
963 if (version_compare($db->version, '5.7', '>=' )) {
965 $db = DB_DataObject::factory('core_enum');
966 $db->query("show variables like 'sql_mode'");
969 $modes = explode(",", $db->Value);
971 // these are 'new' problems with mysql.
973 in_array('NO_ZERO_IN_DATE', $modes) ||
974 in_array('NO_ZERO_DATE', $modes) ||
975 in_array('STRICT_TRANS_TABLES', $modes) ||
976 !in_array('ALLOW_INVALID_DATES', $modes)
978 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");
993 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
995 function fixSequencesMysql()
1000 function fixSequencesPgsql()
1004 //DB_DataObject::debugLevel(1);
1005 $cs = DB_DataObject::factory('core_enum');
1009 CASE WHEN strpos(seq_name, '.') > 0 THEN
1012 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1015 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1016 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1020 n.nspname AS schema_name,
1021 c.relname AS table_name,
1022 a.attname AS column_name,
1023 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1025 JOIN pg_attribute a ON (c.oid=a.attrelid)
1026 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1027 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1028 WHERE has_schema_privilege(n.oid,'USAGE')
1029 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1030 AND has_table_privilege(c.oid,'SELECT')
1031 AND (NOT a.attisdropped)
1032 AND d.adsrc ~ '^nextval'
1036 CASE WHEN strpos(seq_name, '.') > 0 THEN
1037 substring(seq_name, 1,strpos(seq_name,'.')-1)
1042 GROUP BY seq_name HAVING count(*)=1
1045 while ($cs->fetch()) {
1048 foreach($cmds as $cmd) {
1049 $cs = DB_DataObject::factory('core_enum');
1053 $cs = DB_DataObject::factory('core_enum');
1055 SELECT 'SELECT SETVAL(' ||
1056 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1057 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1063 WHERE S.relkind = 'S'
1065 AND D.refobjid = T.oid
1066 AND D.refobjid = C.attrelid
1067 AND D.refobjsubid = C.attnum
1068 AND NS.oid = T.relnamespace
1072 while ($cs->fetch()) {
1075 foreach($cmds as $cmd) {
1076 $cs = DB_DataObject::factory('core_enum');
1083 var $extensions = array(
1088 function runExtensions()
1091 $ff = HTML_Flexyframework::get();
1093 $dburl = parse_url($ff->database);
1095 $dbtype = $dburl['scheme'];
1097 foreach($this->extensions as $ext) {
1099 $scls = ucfirst($dbtype). $ext;
1100 $cls = __CLASS__ . '_'. $scls;
1101 $fn = implode('/',explode('_', $cls)).'.php';
1102 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1113 function checkSystem($req = false, $pref = false)
1115 // most of these are from File_Convert...
1117 // these are required - and have simple dependancies.
1118 require_once 'System.php';
1119 $req = $req !== false ? $req : array(
1124 'rsvg-convert', //librsvg2-bin
1131 // these are prefered - but may have complicated depenacies
1132 $pref = $pref !== false ? $pref : array(
1136 'html2text', // not availabe in debian squeeze
1137 'pdftocairo', //poppler-utils - not available in debian squeeze.
1147 foreach($req as $r) {
1148 if (!System::which($r)) {
1154 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1156 foreach($pref as $r) {
1157 if (!System::which($r)) {
1163 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1170 function generateDataobjectsCache()
1172 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1178 function curl($url, $request = array(), $method = 'GET')
1180 if($method == 'GET'){
1181 $request = http_build_query($request);
1182 $url = $url . "?" . $request;
1185 $ch = curl_init($url);
1187 if ($method == 'POST') {
1189 curl_setopt($ch, CURLOPT_POST, 1);
1190 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1194 curl_setopt($ch, CURLOPT_HTTPHEADER,
1195 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1199 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1201 curl_setopt($ch, CURLOPT_HEADER, false);
1202 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1203 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1204 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1206 $response = curl_exec($ch);