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);
182 // do this first, so the innodb change + utf8 fixes column max sizes
184 // this will trigger errors about freetext indexes - we will have to remove them manually.?
185 // 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..)
187 $this->runExtensions();
190 if (empty($opts['data-only'])) {
193 if (!empty($opts['only-module-sql'])) {
197 $this->runUpdateModulesData();
199 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
200 // make sure we have a good cache...?
202 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
205 $this->runExtensions();
207 $this->generateDataobjectsCache();
212 echo "\nUpdate Completed SUCCESS\n";
216 * imports SQL files from all DataObjects directories....
218 * except any matching /migrate/
223 // loop through all the modules, and see if they have a importSQL method?
226 $ff = HTML_Flexyframework::get();
228 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
230 //$this->{'import' . $url['scheme']}($url);
232 $dbtype = $dburl['scheme'];
235 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
240 $ar = $this->modulesList();
245 if(in_array($m, $this->disabled)){
246 echo "module $m is disabled \n";
250 echo "Importing SQL from module $m\n";
251 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
256 // check to see if the class has
260 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
261 if($m != 'Core' && file_exists($file)){
264 $class = "Pman_{$m}_UpdateDatabase";
266 if(method_exists($x, 'importModuleSQL')){
267 echo "Importing SQL from module $m using Module::importModuleSQL\n";
268 $x->opts = $this->opts;
269 $x->rootDir = $this->rootDir;
270 $x->importModuleSQL($dburl);
275 echo "Importing SQL from module $m\n";
278 // if init has been called
280 if (!empty($this->opts['init'])) {
281 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
287 $fd = $this->rootDir. "/Pman/$m/DataObjects";
289 $this->{$dirmethod}($dburl, $fd);
292 // new -- sql directory..
293 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
294 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
296 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
297 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
301 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
302 if (class_exists('PDO_DataObjects_Introspection')) {
303 PDO_DataObject_Introspection::$cache = array();
305 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
307 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
308 $this->{'fixSequences'. $dbtype}();
321 /** -------------- code to handle importing a whole directory of files into the database ------- **/
324 function importpgsqldir($url, $dir, $disable_triggers = false)
326 $ff = HTML_FlexyFramework::get();
328 require_once 'System.php';
329 $cat = System::which('cat');
330 $psql = System::which('psql');
333 if (!empty($url['pass'])) {
334 putenv("PGPASSWORD=". $url['pass']);
338 ' -h ' . $url['host'] .
339 ' -U' . escapeshellarg($url['user']) .
340 ' ' . basename($url['path']);
343 echo $psql_cmd . "\n" ;
344 echo "scan : $dir\n";
347 $files = array($dir);
352 $files = glob($dir.'/*.sql');
353 uksort($files, 'strcasecmp');
355 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
356 //usort($files, $lsort);
359 foreach($files as $bfn) {
362 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
365 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
366 && !preg_match('#\.pg\.sql#i', basename($bfn))
367 ) { // skip migration scripts at present..
372 if (!preg_match('/pgsql/', basename($dir) )) {
373 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
374 $fn = $this->convertToPG($bfn);
378 // files ending in .pg.sql are native postgres files.. ## depricated
381 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
383 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
399 * mysql - does not support conversions.
403 function importmysqlidir($dburl, $dir) {
404 return $this->importmysqldir($dburl, $dir);
407 function importmysqldir($dburl, $dir)
410 $this->fixMysqlInnodb(); /// run once
412 echo "Import MYSQL :: $dir\n";
415 require_once 'System.php';
416 $cat = System::which('cat');
417 $mysql = System::which('mysql');
421 $mysql_cmd = $mysql .
422 ' -h ' . $dburl['host'] .
423 ' -u' . escapeshellarg($dburl['user']) .
424 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
425 ' ' . basename($dburl['path']);
426 //echo $mysql_cmd . "\n" ;
428 $files = glob($dir.'/*.sql');
429 uksort($files, 'strcasecmp');
432 foreach($files as $fn) {
435 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
438 // .my.sql but not .pg.sql
439 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
440 && !preg_match('#\.my\.sql#i', basename($fn))
441 ) { // skip migration scripts at present..
444 if (!strlen(trim($fn))) {
448 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
450 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
453 $fp = popen($cmd, "r");
456 // send the current file part to the browser
457 $line = trim(fgets($fp, 1024));
462 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
463 echo " ---- {$line}\n"; flush();
467 switch($matches[1]) {
468 case 1017: // cause by renaming table -- old one does not exist..
469 case 1050: // create tables triggers this..
470 case 1060: // Duplicate column name
471 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
472 case 1091: // drop index -- name does not exist.. might hide errors..
474 case 1146: // drop a index on an unknown table.. - happens rarely...
475 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
481 echo " ---- {$line}\n"; flush();
485 // 1051: // Unknown table -- normally drop = add iff exists..
486 echo "File: $fn\n$line\n";
502 * simple regex based convert mysql to pgsql...
504 function convertToPG($src)
506 //echo "Convert $src\n";
508 $fn = $this->tempName('sql');
510 $ret = array( ); // pad it a bit.
511 $extra = array("", "" );
514 foreach(file($src) as $l) {
517 if (!strlen($l) || $l[0] == '#') {
521 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
524 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
525 $tbl = 'shop_' . strtolower($m[1]);
526 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
528 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
529 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
532 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
533 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
534 $extra[] = "create sequence {$tbl}_seq;";
538 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
539 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
542 // enum value -- use the text instead..
544 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
545 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
547 // ignore the alter enum
548 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
552 // UNIQUE KEY .. ignore
553 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
554 $last = array_pop($ret);
555 $ret[] = trim($last, ",");
559 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
563 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
567 // INDEX lookup ..ignore
568 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
569 $last = array_pop($ret);
570 $ret[] = trim($last, ",");
575 // CREATE INDEX ..ignore
576 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
577 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
582 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
584 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
585 $l = preg_replace('# blob#i', ' TEXT', $l);
586 $l = preg_replace('# longtext#i', ' TEXT', $l);
587 $l = preg_replace('# tinyint#i', ' INT', $l);
593 $ret = array_merge($extra,$ret);
594 // echo implode("\n", $ret); exit;
596 file_put_contents($fn, implode("\n", $ret));
602 function checkOpts($opts)
606 foreach($opts as $o=>$v) {
607 if (!preg_match('/^json-/', $o) || empty($v)) {
610 if (!file_exists($v)) {
611 die("File does not exist : OPTION --{$o} = {$v} \n");
615 $modules = array_reverse($this->modulesList());
617 // move 'project' one to the end...
619 foreach ($modules as $module){
620 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
621 if($module == 'Core' || !file_exists($file)){
625 $class = "Pman_{$module}_UpdateDatabase";
627 if(!method_exists($x, 'checkOpts')){
630 $x->checkOpts($opts);
634 static function jsonImportFromArray($opts)
636 foreach($opts as $o=>$v) {
637 if (!preg_match('/^json-/', $o) || empty($v)) {
640 $type = str_replace('_', '-', substr($o,5));
642 $data= json_decode(file_get_contents($v),true);
643 $pg = HTML_FlexyFramework::get()->page;
644 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
654 function runUpdateModulesData()
656 if (class_exists('PDO_DataObjects_Introspection')) {
657 PDO_DataObject_Introspection::$cache = array();
659 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
661 if(!in_array('Core', $this->disabled)){
662 echo "Running jsonImportFromArray\n";
663 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
666 echo "Running updateData on modules\n";
672 $modules = array_reverse($this->modulesList());
674 // move 'project' one to the end...
676 foreach ($modules as $module){
677 if(in_array($module, $this->disabled)){
680 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
681 if($module == 'Core' || !file_exists($file)){
686 $class = "Pman_{$module}_UpdateDatabase";
688 if(!method_exists($x, 'updateData')){
698 function updateDataEnums()
700 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
702 $enum = DB_DataObject::Factory('core_enum');
703 //DB_DAtaObject::debugLevel(1);
708 'name' => 'COMPTYPE',
709 'display_name' => 'Company Types',
710 'is_system_enum' => 1,
714 'display_name' => 'Owner',
715 'seqid' => 999, // last...
716 'is_system_enum' => 1,
723 'name' => 'HtmlEditor.font-family',
724 'display_name' => 'HTML Editor font families',
725 'is_system_enum' => 1,
728 'name' => 'Helvetica,Arial,sans-serif',
729 'display_name' => 'Helvetica',
734 'name' => 'Courier New',
735 'display_name' => 'Courier',
740 'display_name' => 'Tahoma',
744 'name' => 'Times New Roman,serif',
745 'display_name' => 'Times',
750 'display_name' => 'Verdana',
763 function updateDataGroups()
766 $groups = DB_DataObject::factory('core_group');
767 $groups->initGroups();
769 $groups->initDatabase($this,array(
771 'name' => 'bcc-email', // group who are bcc'ed on all requests.
772 'type' => 0, // system
775 'name' => 'system-email-from',
776 'type' => 0, // system
779 'name' => 'core-person-signup-bcc',
780 'type' => 0, // system
788 function updateDataCompanies()
791 // fix comptypes enums..
792 $c = DB_DataObject::Factory('core_company');
794 $c->selectAdd('distinct(comptype) as comptype');
795 $c->whereAdd("comptype != ''");
798 foreach($c->fetchAll('comptype') as $cts) {
802 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
805 $c = DB_DataObject::Factory('core_enum');
808 //DB_DataObject::debugLevel(1);
810 $c = DB_DataObject::Factory('core_company');
812 UPDATE {$c->tableName()}
814 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
828 function initEmails($templateDir, $emails, $mapping = false)
830 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
832 $pg = HTML_FlexyFramework::get()->page;
833 foreach($emails as $name=>$data) {
834 $cm = DB_DataObject::factory('core_email');
835 $update = $cm->get('name', $name);
838 if (empty($cm->bcc_group_id)) {
839 if (empty($data['bcc_group'])) {
840 $this->jerr("missing bcc_group for template $name");
842 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
845 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
848 if (!$g->members('email')) {
849 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
852 $cm->bcc_group_id = $g->id;
854 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
855 //if (empty($cm->test_class)) {
856 if (empty($data['test_class'])) {
857 $this->jerr("missing test_class for template $name");
859 $cm->test_class = $data['test_class'];
861 if(isset($cm->to_group_id)) {
866 !empty($data['to_group']) &&
867 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
869 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
871 if (empty($gp->id)) {
872 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
875 $cm->to_group_id = $gp->id;
879 isset($data['active']) && !isset($cm->active)
881 $cm->active = $data['active'];
884 require_once $cm->test_class . '.php';
886 $clsname = str_replace('/','_', $cm->test_class);
888 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
889 $got_it = $method->isStatic();
890 } catch(Exception $e) {
895 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
899 echo "email: {$name} - checked\n";
900 continue; /// we do not import the body content of templates that exist...
907 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
911 'file' => $templateDir. $name .'.html'
914 if (!empty($data['master'])) {
915 $opts['master'] = $templateDir . $master .'.html';
917 require_once 'Pman/Core/Import/Core_email.php';
918 $x = new Pman_Core_Import_Core_email();
920 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
922 echo "email: {$name} - CREATED\n";
927 function updateData()
930 if (class_exists('PDO_DataObjects_Introspection')) {
931 PDO_DataObject_Introspection::$cache = array();
933 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
934 $this->updateDataEnums();
935 $this->updateDataGroups();
936 $this->updateDataCompanies();
938 $c = DB_DataObject::Factory('I18n');
946 function fixMysqlInnodb()
949 static $done_check = false;
955 if (!empty($this->opts['skip-mysql-checks'])) {
958 // innodb in single files is far more efficient that MYD or one big innodb file.
959 // first check if database is using this format.
960 $db = DB_DataObject::factory('core_enum');
961 $db->query("show variables like 'innodb_file_per_table'");
963 if ($db->Value == 'OFF') {
964 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
967 $db = DB_DataObject::factory('core_enum');
968 $db->query("select version() as version");
971 if (version_compare($db->version, '5.7', '>=' )) {
973 $db = DB_DataObject::factory('core_enum');
974 $db->query("show variables like 'sql_mode'");
977 $modes = explode(",", $db->Value);
979 // these are 'new' problems with mysql.
981 in_array('NO_ZERO_IN_DATE', $modes) ||
982 in_array('NO_ZERO_DATE', $modes) ||
983 in_array('STRICT_TRANS_TABLES', $modes) ||
984 !in_array('ALLOW_INVALID_DATES', $modes)
986 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");
1001 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1003 function fixSequencesMysql()
1008 function fixSequencesPgsql()
1012 //DB_DataObject::debugLevel(1);
1013 $cs = DB_DataObject::factory('core_enum');
1017 CASE WHEN strpos(seq_name, '.') > 0 THEN
1020 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1023 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1024 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1028 n.nspname AS schema_name,
1029 c.relname AS table_name,
1030 a.attname AS column_name,
1031 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1033 JOIN pg_attribute a ON (c.oid=a.attrelid)
1034 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1035 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1036 WHERE has_schema_privilege(n.oid,'USAGE')
1037 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1038 AND has_table_privilege(c.oid,'SELECT')
1039 AND (NOT a.attisdropped)
1040 AND d.adsrc ~ '^nextval'
1044 CASE WHEN strpos(seq_name, '.') > 0 THEN
1045 substring(seq_name, 1,strpos(seq_name,'.')-1)
1050 GROUP BY seq_name HAVING count(*)=1
1053 while ($cs->fetch()) {
1056 foreach($cmds as $cmd) {
1057 $cs = DB_DataObject::factory('core_enum');
1061 $cs = DB_DataObject::factory('core_enum');
1063 SELECT 'SELECT SETVAL(' ||
1064 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1065 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1071 WHERE S.relkind = 'S'
1073 AND D.refobjid = T.oid
1074 AND D.refobjid = C.attrelid
1075 AND D.refobjsubid = C.attnum
1076 AND NS.oid = T.relnamespace
1080 while ($cs->fetch()) {
1083 foreach($cmds as $cmd) {
1084 $cs = DB_DataObject::factory('core_enum');
1091 var $extensions = array(
1096 function runExtensions()
1099 $ff = HTML_Flexyframework::get();
1101 $dburl = parse_url($ff->database);
1103 $dbtype = $dburl['scheme'];
1105 foreach($this->extensions as $ext) {
1107 $scls = ucfirst($dbtype). $ext;
1108 $cls = __CLASS__ . '_'. $scls;
1109 $fn = implode('/',explode('_', $cls)).'.php';
1110 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1121 function checkSystem($req = false, $pref = false)
1123 // most of these are from File_Convert...
1125 // these are required - and have simple dependancies.
1126 require_once 'System.php';
1127 $req = $req !== false ? $req : array(
1132 'rsvg-convert', //librsvg2-bin
1139 // these are prefered - but may have complicated depenacies
1140 $pref = $pref !== false ? $pref : array(
1144 'html2text', // not availabe in debian squeeze
1145 'pdftocairo', //poppler-utils - not available in debian squeeze.
1155 foreach($req as $r) {
1156 if (!System::which($r)) {
1162 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1164 foreach($pref as $r) {
1165 if (!System::which($r)) {
1171 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1178 function generateDataobjectsCache()
1180 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1186 function curl($url, $request = array(), $method = 'GET')
1188 if($method == 'GET'){
1189 $request = http_build_query($request);
1190 $url = $url . "?" . $request;
1193 $ch = curl_init($url);
1195 if ($method == 'POST') {
1197 curl_setopt($ch, CURLOPT_POST, 1);
1198 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1202 curl_setopt($ch, CURLOPT_HTTPHEADER,
1203 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1207 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1209 curl_setopt($ch, CURLOPT_HEADER, false);
1210 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1211 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1212 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1214 $response = curl_exec($ch);