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 DB_DataObject::DebugLevel(1);
186 // do this first, so the innodb change + utf8 fixes column max sizes
188 // this will trigger errors about freetext indexes - we will have to remove them manually.?
189 // 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..)
191 $this->runExtensions();
194 if (empty($opts['data-only'])) {
197 if (!empty($opts['only-module-sql'])) {
201 $this->runUpdateModulesData();
203 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
204 // make sure we have a good cache...?
206 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
209 $this->runExtensions();
211 $this->generateDataobjectsCache();
216 echo "\nUpdate Completed SUCCESS\n";
220 * imports SQL files from all DataObjects directories....
222 * except any matching /migrate/
227 // loop through all the modules, and see if they have a importSQL method?
230 $ff = HTML_Flexyframework::get();
232 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
234 //$this->{'import' . $url['scheme']}($url);
236 $dbtype = $dburl['scheme'];
239 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
244 $ar = $this->modulesList();
249 if(in_array($m, $this->disabled)){
250 echo "module $m is disabled \n";
254 echo "Importing SQL from module $m\n";
255 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
260 // check to see if the class has
264 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
265 if($m != 'Core' && file_exists($file)){
268 $class = "Pman_{$m}_UpdateDatabase";
270 if(method_exists($x, 'importModuleSQL')){
271 echo "Importing SQL from module $m using Module::importModuleSQL\n";
272 $x->opts = $this->opts;
273 $x->rootDir = $this->rootDir;
274 $x->importModuleSQL($dburl);
279 echo "Importing SQL from module $m\n";
282 // if init has been called
284 if (!empty($this->opts['init'])) {
285 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
291 $fd = $this->rootDir. "/Pman/$m/DataObjects";
293 $this->{$dirmethod}($dburl, $fd);
296 // new -- sql directory..
297 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
298 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
300 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
301 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
305 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
306 if (class_exists('PDO_DataObjects_Introspection')) {
307 PDO_DataObject_Introspection::$cache = array();
309 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
311 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
312 $this->{'fixSequences'. $dbtype}();
325 /** -------------- code to handle importing a whole directory of files into the database ------- **/
328 function importpgsqldir($url, $dir, $disable_triggers = false)
330 $ff = HTML_FlexyFramework::get();
332 require_once 'System.php';
333 $cat = System::which('cat');
334 $psql = System::which('psql');
337 if (!empty($url['pass'])) {
338 putenv("PGPASSWORD=". $url['pass']);
342 ' -h ' . $url['host'] .
343 ' -U' . escapeshellarg($url['user']) .
344 ' ' . basename($url['path']);
347 echo $psql_cmd . "\n" ;
348 echo "scan : $dir\n";
351 $files = array($dir);
356 $files = glob($dir.'/*.sql');
357 uksort($files, 'strcasecmp');
359 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
360 //usort($files, $lsort);
363 foreach($files as $bfn) {
366 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
369 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
370 && !preg_match('#\.pg\.sql#i', basename($bfn))
371 ) { // skip migration scripts at present..
376 if (!preg_match('/pgsql/', basename($dir) )) {
377 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
378 $fn = $this->convertToPG($bfn);
382 // files ending in .pg.sql are native postgres files.. ## depricated
385 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
387 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
403 * mysql - does not support conversions.
407 function importmysqlidir($dburl, $dir) {
408 return $this->importmysqldir($dburl, $dir);
411 function importmysqldir($dburl, $dir)
414 $this->fixMysqlInnodb(); /// run once
416 echo "Import MYSQL :: $dir\n";
419 require_once 'System.php';
420 $cat = System::which('cat');
421 $mysql = System::which('mysql');
425 $mysql_cmd = $mysql .
426 ' -h ' . $dburl['host'] .
427 ' -u' . escapeshellarg($dburl['user']) .
428 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
429 ' ' . basename($dburl['path']);
430 //echo $mysql_cmd . "\n" ;
432 $files = glob($dir.'/*.sql');
433 uksort($files, 'strcasecmp');
436 foreach($files as $fn) {
439 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
442 // .my.sql but not .pg.sql
443 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
444 && !preg_match('#\.my\.sql#i', basename($fn))
445 ) { // skip migration scripts at present..
448 if (!strlen(trim($fn))) {
452 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
454 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
457 $fp = popen($cmd, "r");
460 // send the current file part to the browser
461 $line = trim(fgets($fp, 1024));
466 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
467 echo " ---- {$line}\n"; flush();
471 switch($matches[1]) {
472 case 1017: // cause by renaming table -- old one does not exist..
473 case 1050: // create tables triggers this..
474 case 1060: // Duplicate column name
475 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
476 case 1091: // drop index -- name does not exist.. might hide errors..
478 case 1146: // drop a index on an unknown table.. - happens rarely...
479 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
485 echo " ---- {$line}\n"; flush();
489 // 1051: // Unknown table -- normally drop = add iff exists..
490 echo "File: $fn\n$line\n";
506 * simple regex based convert mysql to pgsql...
508 function convertToPG($src)
510 //echo "Convert $src\n";
512 $fn = $this->tempName('sql');
514 $ret = array( ); // pad it a bit.
515 $extra = array("", "" );
518 foreach(file($src) as $l) {
521 if (!strlen($l) || $l[0] == '#') {
525 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
528 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
529 $tbl = 'shop_' . strtolower($m[1]);
530 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
532 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
533 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
536 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
537 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
538 $extra[] = "create sequence {$tbl}_seq;";
542 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
543 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
546 // enum value -- use the text instead..
548 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
549 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
551 // ignore the alter enum
552 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
556 // UNIQUE KEY .. ignore
557 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
558 $last = array_pop($ret);
559 $ret[] = trim($last, ",");
563 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
567 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
571 // INDEX lookup ..ignore
572 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
573 $last = array_pop($ret);
574 $ret[] = trim($last, ",");
579 // CREATE INDEX ..ignore
580 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
581 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
586 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
588 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
589 $l = preg_replace('# blob#i', ' TEXT', $l);
590 $l = preg_replace('# longtext#i', ' TEXT', $l);
591 $l = preg_replace('# tinyint#i', ' INT', $l);
597 $ret = array_merge($extra,$ret);
598 // echo implode("\n", $ret); exit;
600 file_put_contents($fn, implode("\n", $ret));
606 function checkOpts($opts)
610 foreach($opts as $o=>$v) {
611 if (!preg_match('/^json-/', $o) || empty($v)) {
614 if (!file_exists($v)) {
615 die("File does not exist : OPTION --{$o} = {$v} \n");
619 $modules = array_reverse($this->modulesList());
621 // move 'project' one to the end...
623 foreach ($modules as $module){
624 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
625 if($module == 'Core' || !file_exists($file)){
629 $class = "Pman_{$module}_UpdateDatabase";
631 if(!method_exists($x, 'checkOpts')){
634 $x->checkOpts($opts);
638 static function jsonImportFromArray($opts)
640 foreach($opts as $o=>$v) {
641 if (!preg_match('/^json-/', $o) || empty($v)) {
644 $type = str_replace('_', '-', substr($o,5));
646 $data= json_decode(file_get_contents($v),true);
647 $pg = HTML_FlexyFramework::get()->page;
648 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
658 function runUpdateModulesData()
660 if (class_exists('PDO_DataObjects_Introspection')) {
661 PDO_DataObject_Introspection::$cache = array();
663 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
665 if(!in_array('Core', $this->disabled)){
666 echo "Running jsonImportFromArray\n";
667 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
670 echo "Running updateData on modules\n";
676 $modules = array_reverse($this->modulesList());
678 // move 'project' one to the end...
680 foreach ($modules as $module){
681 if(in_array($module, $this->disabled)){
684 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
685 if($module == 'Core' || !file_exists($file)){
690 $class = "Pman_{$module}_UpdateDatabase";
692 if(!method_exists($x, 'updateData')){
702 function updateDataEnums()
704 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
706 $enum = DB_DataObject::Factory('core_enum');
707 //DB_DAtaObject::debugLevel(1);
712 'name' => 'COMPTYPE',
713 'display_name' => 'Company Types',
714 'is_system_enum' => 1,
718 'display_name' => 'Owner',
719 'seqid' => 999, // last...
720 'is_system_enum' => 1,
727 'name' => 'HtmlEditor.font-family',
728 'display_name' => 'HTML Editor font families',
729 'is_system_enum' => 1,
732 'name' => 'Helvetica,Arial,sans-serif',
733 'display_name' => 'Helvetica',
738 'name' => 'Courier New',
739 'display_name' => 'Courier',
744 'display_name' => 'Tahoma',
748 'name' => 'Times New Roman,serif',
749 'display_name' => 'Times',
754 'display_name' => 'Verdana',
767 function updateDataGroups()
770 $groups = DB_DataObject::factory('core_group');
771 $groups->initGroups();
773 $groups->initDatabase($this,array(
775 'name' => 'bcc-email', // group who are bcc'ed on all requests.
776 'type' => 0, // system
779 'name' => 'system-email-from',
780 'type' => 0, // system
783 'name' => 'core-person-signup-bcc',
784 'type' => 0, // system
792 function updateDataCompanies()
795 // fix comptypes enums..
796 $c = DB_DataObject::Factory('core_company');
798 $c->selectAdd('distinct(comptype) as comptype');
799 $c->whereAdd("comptype != ''");
802 foreach($c->fetchAll('comptype') as $cts) {
806 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
809 $c = DB_DataObject::Factory('core_enum');
812 //DB_DataObject::debugLevel(1);
814 $c = DB_DataObject::Factory('core_company');
816 UPDATE {$c->tableName()}
818 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
832 function initEmails($templateDir, $emails, $mapping = false)
834 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
836 $pg = HTML_FlexyFramework::get()->page;
837 foreach($emails as $name=>$data) {
838 $cm = DB_DataObject::factory('core_email');
839 $update = $cm->get('name', $name);
842 if (empty($cm->bcc_group_id)) {
843 if (empty($data['bcc_group'])) {
844 $this->jerr("missing bcc_group for template $name");
846 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
849 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
852 if (!$g->members('email')) {
853 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
856 $cm->bcc_group_id = $g->id;
858 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
859 //if (empty($cm->test_class)) {
860 if (empty($data['test_class'])) {
861 $this->jerr("missing test_class for template $name");
863 $cm->test_class = $data['test_class'];
865 if(isset($cm->to_group_id)) {
870 !empty($data['to_group']) &&
871 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
873 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
875 if (empty($gp->id)) {
876 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
879 $cm->to_group_id = $gp->id;
883 isset($data['active']) && !isset($cm->active)
885 $cm->active = $data['active'];
888 require_once $cm->test_class . '.php';
890 $clsname = str_replace('/','_', $cm->test_class);
892 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
893 $got_it = $method->isStatic();
894 } catch(Exception $e) {
899 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
903 echo "email: {$name} - checked\n";
904 continue; /// we do not import the body content of templates that exist...
911 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
915 'file' => $templateDir. $name .'.html'
918 if (!empty($data['master'])) {
919 $opts['master'] = $templateDir . $master .'.html';
921 require_once 'Pman/Core/Import/Core_email.php';
922 $x = new Pman_Core_Import_Core_email();
924 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
926 echo "email: {$name} - CREATED\n";
931 function updateData()
934 if (class_exists('PDO_DataObjects_Introspection')) {
935 PDO_DataObject_Introspection::$cache = array();
937 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
938 $this->updateDataEnums();
939 $this->updateDataGroups();
940 $this->updateDataCompanies();
942 $c = DB_DataObject::Factory('I18n');
950 function fixMysqlInnodb()
953 static $done_check = false;
959 if (!empty($this->opts['skip-mysql-checks'])) {
962 // innodb in single files is far more efficient that MYD or one big innodb file.
963 // first check if database is using this format.
964 $db = DB_DataObject::factory('core_enum');
965 $db->query("show variables like 'innodb_file_per_table'");
967 if ($db->Value == 'OFF') {
968 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
971 $db = DB_DataObject::factory('core_enum');
972 $db->query("select version() as version");
975 if (version_compare($db->version, '5.7', '>=' )) {
977 $db = DB_DataObject::factory('core_enum');
978 $db->query("show variables like 'sql_mode'");
981 $modes = explode(",", $db->Value);
983 // these are 'new' problems with mysql.
985 in_array('NO_ZERO_IN_DATE', $modes) ||
986 in_array('NO_ZERO_DATE', $modes) ||
987 in_array('STRICT_TRANS_TABLES', $modes) ||
988 !in_array('ALLOW_INVALID_DATES', $modes)
990 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");
1005 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1007 function fixSequencesMysql()
1012 function fixSequencesPgsql()
1016 //DB_DataObject::debugLevel(1);
1017 $cs = DB_DataObject::factory('core_enum');
1021 CASE WHEN strpos(seq_name, '.') > 0 THEN
1024 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1027 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1028 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1032 n.nspname AS schema_name,
1033 c.relname AS table_name,
1034 a.attname AS column_name,
1035 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1037 JOIN pg_attribute a ON (c.oid=a.attrelid)
1038 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1039 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1040 WHERE has_schema_privilege(n.oid,'USAGE')
1041 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1042 AND has_table_privilege(c.oid,'SELECT')
1043 AND (NOT a.attisdropped)
1044 AND d.adsrc ~ '^nextval'
1048 CASE WHEN strpos(seq_name, '.') > 0 THEN
1049 substring(seq_name, 1,strpos(seq_name,'.')-1)
1054 GROUP BY seq_name HAVING count(*)=1
1057 while ($cs->fetch()) {
1060 foreach($cmds as $cmd) {
1061 $cs = DB_DataObject::factory('core_enum');
1065 $cs = DB_DataObject::factory('core_enum');
1067 SELECT 'SELECT SETVAL(' ||
1068 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1069 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1075 WHERE S.relkind = 'S'
1077 AND D.refobjid = T.oid
1078 AND D.refobjid = C.attrelid
1079 AND D.refobjsubid = C.attnum
1080 AND NS.oid = T.relnamespace
1084 while ($cs->fetch()) {
1087 foreach($cmds as $cmd) {
1088 $cs = DB_DataObject::factory('core_enum');
1095 var $extensions = array(
1100 function runExtensions()
1103 $ff = HTML_Flexyframework::get();
1105 $dburl = parse_url($ff->database);
1107 $dbtype = $dburl['scheme'];
1109 foreach($this->extensions as $ext) {
1111 $scls = ucfirst($dbtype). $ext;
1112 $cls = __CLASS__ . '_'. $scls;
1113 $fn = implode('/',explode('_', $cls)).'.php';
1114 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1125 function checkSystem($req = false, $pref = false)
1127 // most of these are from File_Convert...
1129 // these are required - and have simple dependancies.
1130 require_once 'System.php';
1131 $req = $req !== false ? $req : array(
1136 'rsvg-convert', //librsvg2-bin
1143 // these are prefered - but may have complicated depenacies
1144 $pref = $pref !== false ? $pref : array(
1148 'html2text', // not availabe in debian squeeze
1149 'pdftocairo', //poppler-utils - not available in debian squeeze.
1159 foreach($req as $r) {
1160 if (!System::which($r)) {
1166 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1168 foreach($pref as $r) {
1169 if (!System::which($r)) {
1175 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1182 function generateDataobjectsCache()
1184 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1190 function curl($url, $request = array(), $method = 'GET')
1192 if($method == 'GET'){
1193 $request = http_build_query($request);
1194 $url = $url . "?" . $request;
1197 $ch = curl_init($url);
1199 if ($method == 'POST') {
1201 curl_setopt($ch, CURLOPT_POST, 1);
1202 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1206 curl_setopt($ch, CURLOPT_HTTPHEADER,
1207 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1211 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1213 curl_setopt($ch, CURLOPT_HEADER, false);
1214 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1215 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1216 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1218 $response = curl_exec($ch);