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');
111 $ar = $cls->getStaticProperties();
112 if (isset($ar['cli_opts'])) {
114 $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
123 var $disabled = array();
128 var $local_base_url = false;
133 $ff = HTML_FlexyFramework::get();
134 if (!empty($ff->cli)) {
139 parent::getAuth(); // load company!
140 $au = $this->getAuthUser();
141 if (!$au || $au->company()->comptype != 'OWNER') {
142 $this->jerr("Not authenticated", array('authFailure' => true));
144 $this->authUser = $au;
148 function get($args, $opts=array())
151 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
153 $this->checkSystem();
155 if (class_exists('PDO_DataObjects_Introspection')) {
156 PDO_DataObject_Introspection::$cache = array();
159 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
161 $ff = HTML_FlexyFramework::get();
163 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
164 die("Please setup Pman[local_base_url]\n");
167 $this->local_base_url = $ff->Pman['local_base_url'];
169 if(!empty($ff->Core_Notify)){
170 // require_once 'Pman/Core/NotifySmtpCheck.php';
171 // $x = new Pman_Core_NotifySmtpCheck();
175 $this->disabled = explode(',', $ff->disable);
177 //$this->fixSequencesPgsql();exit;
180 if (!empty($opts['debug'])) {
181 DB_DataObject::DebugLevel($opts['debug']);
185 // ask all the modules to verify the opts
187 $this->checkOpts($opts);
191 // do this first, so the innodb change + utf8 fixes column max sizes
193 // this will trigger errors about freetext indexes - we will have to remove them manually.?
194 // 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..)
196 $this->runExtensions();
199 if (empty($opts['data-only'])) {
202 if (!empty($opts['only-module-sql'])) {
205 if (!empty($opts['debug'])) {
206 DB_DataObject::DebugLevel($opts['debug']);
209 $this->runUpdateModulesData();
211 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
212 // make sure we have a good cache...?
214 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
217 $this->runExtensions();
219 $this->generateDataobjectsCache();
224 echo "\nUpdate Completed SUCCESS\n";
228 * imports SQL files from all DataObjects directories....
230 * except any matching /migrate/
235 // loop through all the modules, and see if they have a importSQL method?
238 $ff = HTML_Flexyframework::get();
240 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
242 //$this->{'import' . $url['scheme']}($url);
244 $dbtype = $dburl['scheme'];
247 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
252 $ar = $this->modulesList();
257 if(in_array($m, $this->disabled)){
258 echo "module $m is disabled \n";
262 echo "Importing SQL from module $m\n";
263 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
268 // check to see if the class has
272 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
273 if($m != 'Core' && file_exists($file)){
276 $class = "Pman_{$m}_UpdateDatabase";
278 if(method_exists($x, 'importModuleSQL')){
279 echo "Importing SQL from module $m using Module::importModuleSQL\n";
280 $x->opts = $this->opts;
281 $x->rootDir = $this->rootDir;
282 $x->importModuleSQL($dburl);
287 echo "Importing SQL from module $m\n";
290 // if init has been called
292 if (!empty($this->opts['init'])) {
293 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
299 $fd = $this->rootDir. "/Pman/$m/DataObjects";
301 $this->{$dirmethod}($dburl, $fd);
304 // new -- sql directory..
305 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
306 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
308 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
309 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
313 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
314 if (class_exists('PDO_DataObjects_Introspection')) {
315 PDO_DataObject_Introspection::$cache = array();
317 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
319 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
320 $this->{'fixSequences'. $dbtype}();
333 /** -------------- code to handle importing a whole directory of files into the database ------- **/
336 function importpgsqldir($url, $dir, $disable_triggers = false)
338 $ff = HTML_FlexyFramework::get();
340 require_once 'System.php';
341 $cat = System::which('cat');
342 $psql = System::which('psql');
345 if (!empty($url['pass'])) {
346 putenv("PGPASSWORD=". $url['pass']);
350 ' -h ' . $url['host'] .
351 ' -U' . escapeshellarg($url['user']) .
352 ' ' . basename($url['path']);
355 echo $psql_cmd . "\n" ;
356 echo "scan : $dir\n";
359 $files = array($dir);
364 $files = glob($dir.'/*.sql');
365 uksort($files, 'strcasecmp');
367 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
368 //usort($files, $lsort);
371 foreach($files as $bfn) {
374 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
377 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
378 && !preg_match('#\.pg\.sql#i', basename($bfn))
379 ) { // skip migration scripts at present..
384 if (!preg_match('/pgsql/', basename($dir) )) {
385 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
386 $fn = $this->convertToPG($bfn);
390 // files ending in .pg.sql are native postgres files.. ## depricated
393 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
395 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
411 * mysql - does not support conversions.
415 function importmysqlidir($dburl, $dir) {
416 return $this->importmysqldir($dburl, $dir);
419 function importmysqldir($dburl, $dir)
422 $this->fixMysqlInnodb(); /// run once
424 echo "Import MYSQL :: $dir\n";
427 require_once 'System.php';
428 $cat = System::which('cat');
429 $mysql = System::which('mysql');
433 $mysql_cmd = $mysql .
434 ' -h ' . $dburl['host'] .
435 ' -u' . escapeshellarg($dburl['user']) .
436 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
437 ' ' . basename($dburl['path']);
438 //echo $mysql_cmd . "\n" ;
440 $files = glob($dir.'/*.sql');
441 uksort($files, 'strcasecmp');
444 foreach($files as $fn) {
447 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
450 // .my.sql but not .pg.sql
451 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
452 && !preg_match('#\.my\.sql#i', basename($fn))
453 ) { // skip migration scripts at present..
456 if (!strlen(trim($fn))) {
460 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
462 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
465 $fp = popen($cmd, "r");
468 // send the current file part to the browser
469 $line = trim(fgets($fp, 1024));
474 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
475 echo " ---- {$line}\n"; flush();
479 switch($matches[1]) {
480 case 1017: // cause by renaming table -- old one does not exist..
481 case 1050: // create tables triggers this..
482 case 1060: // Duplicate column name
483 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
484 case 1091: // drop index -- name does not exist.. might hide errors..
486 case 1146: // drop a index on an unknown table.. - happens rarely...
487 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
493 echo " ---- {$line}\n"; flush();
497 // 1051: // Unknown table -- normally drop = add iff exists..
498 echo "File: $fn\n$line\n";
514 * simple regex based convert mysql to pgsql...
516 function convertToPG($src)
518 //echo "Convert $src\n";
520 $fn = $this->tempName('sql');
522 $ret = array( ); // pad it a bit.
523 $extra = array("", "" );
526 foreach(file($src) as $l) {
529 if (!strlen($l) || $l[0] == '#') {
533 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
536 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
537 $tbl = 'shop_' . strtolower($m[1]);
538 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
540 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
541 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
544 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
545 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
546 $extra[] = "create sequence {$tbl}_seq;";
550 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
551 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
554 // enum value -- use the text instead..
556 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
557 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
559 // ignore the alter enum
560 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
564 // UNIQUE KEY .. ignore
565 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
566 $last = array_pop($ret);
567 $ret[] = trim($last, ",");
571 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
575 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
579 // INDEX lookup ..ignore
580 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
581 $last = array_pop($ret);
582 $ret[] = trim($last, ",");
587 // CREATE INDEX ..ignore
588 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
589 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
594 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
596 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
597 $l = preg_replace('# blob#i', ' TEXT', $l);
598 $l = preg_replace('# longtext#i', ' TEXT', $l);
599 $l = preg_replace('# tinyint#i', ' INT', $l);
605 $ret = array_merge($extra,$ret);
606 // echo implode("\n", $ret); exit;
608 file_put_contents($fn, implode("\n", $ret));
614 function checkOpts($opts)
618 foreach($opts as $o=>$v) {
619 if (!preg_match('/^json-/', $o) || empty($v)) {
622 if (!file_exists($v)) {
623 die("File does not exist : OPTION --{$o} = {$v} \n");
627 $modules = array_reverse($this->modulesList());
629 // move 'project' one to the end...
631 foreach ($modules as $module){
632 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
633 if($module == 'Core' || !file_exists($file)){
637 $class = "Pman_{$module}_UpdateDatabase";
639 if(!method_exists($x, 'checkOpts')){
642 $x->checkOpts($opts);
646 static function jsonImportFromArray($opts)
648 foreach($opts as $o=>$v) {
649 if (!preg_match('/^json-/', $o) || empty($v)) {
652 $type = str_replace('_', '-', substr($o,5));
654 $data= json_decode(file_get_contents($v),true);
655 $pg = HTML_FlexyFramework::get()->page;
656 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
666 function runUpdateModulesData()
668 if (class_exists('PDO_DataObjects_Introspection')) {
669 PDO_DataObject_Introspection::$cache = array();
671 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
673 if(!in_array('Core', $this->disabled)){
674 echo "Running jsonImportFromArray\n";
675 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
678 echo "Running updateData on modules\n";
684 $modules = array_reverse($this->modulesList());
686 // move 'project' one to the end...
688 foreach ($modules as $module){
689 if(in_array($module, $this->disabled)){
692 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
693 if($module == 'Core' || !file_exists($file)){
698 $class = "Pman_{$module}_UpdateDatabase";
700 if(!method_exists($x, 'updateData')){
710 function updateDataEnums()
712 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
714 $enum = DB_DataObject::Factory('core_enum');
715 //DB_DAtaObject::debugLevel(1);
720 'name' => 'COMPTYPE',
721 'display_name' => 'Company Types',
722 'is_system_enum' => 1,
726 'display_name' => 'Owner',
727 'seqid' => 999, // last...
728 'is_system_enum' => 1,
735 'name' => 'HtmlEditor.font-family',
736 'display_name' => 'HTML Editor font families',
737 'is_system_enum' => 1,
740 'name' => 'Helvetica,Arial,sans-serif',
741 'display_name' => 'Helvetica',
746 'name' => 'Courier New',
747 'display_name' => 'Courier',
752 'display_name' => 'Tahoma',
756 'name' => 'Times New Roman,serif',
757 'display_name' => 'Times',
762 'display_name' => 'Verdana',
775 function updateDataGroups()
778 $groups = DB_DataObject::factory('core_group');
779 $groups->initGroups();
781 $groups->initDatabase($this,array(
783 'name' => 'bcc-email', // group who are bcc'ed on all requests.
784 'type' => 0, // system
787 'name' => 'system-email-from',
788 'type' => 0, // system
791 'name' => 'core-person-signup-bcc',
792 'type' => 0, // system
800 function updateDataCompanies()
803 // fix comptypes enums..
804 $c = DB_DataObject::Factory('core_company');
806 $c->selectAdd('distinct(comptype) as comptype');
807 $c->whereAdd("comptype != ''");
810 foreach($c->fetchAll('comptype') as $cts) {
814 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
817 $c = DB_DataObject::Factory('core_enum');
820 //DB_DataObject::debugLevel(1);
822 $c = DB_DataObject::Factory('core_company');
824 UPDATE {$c->tableName()}
826 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
840 function initEmails($templateDir, $emails, $mapping = false)
842 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
844 $pg = HTML_FlexyFramework::get()->page;
845 foreach($emails as $name=>$data) {
846 $cm = DB_DataObject::factory('core_email');
847 $update = $cm->get('name', $name);
850 if (empty($cm->bcc_group_id)) {
851 if (empty($data['bcc_group'])) {
852 $this->jerr("missing bcc_group for template $name");
854 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
857 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
860 if (!$g->members('email')) {
861 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
864 $cm->bcc_group_id = $g->id;
866 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
867 //if (empty($cm->test_class)) {
868 if (empty($data['test_class'])) {
869 $this->jerr("missing test_class for template $name");
871 $cm->test_class = $data['test_class'];
873 if(isset($cm->to_group_id)) {
878 !empty($data['to_group']) &&
879 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
881 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
883 if (empty($gp->id)) {
884 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
887 $cm->to_group_id = $gp->id;
891 isset($data['active']) && !isset($cm->active)
893 $cm->active = $data['active'];
896 require_once $cm->test_class . '.php';
898 $clsname = str_replace('/','_', $cm->test_class);
900 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
901 $got_it = $method->isStatic();
902 } catch(Exception $e) {
907 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
911 echo "email: {$name} - checked\n";
912 continue; /// we do not import the body content of templates that exist...
919 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
923 'file' => $templateDir. $name .'.html'
926 if (!empty($data['master'])) {
927 $opts['master'] = $templateDir . $master .'.html';
929 require_once 'Pman/Core/Import/Core_email.php';
930 $x = new Pman_Core_Import_Core_email();
932 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
934 echo "email: {$name} - CREATED\n";
939 function updateData()
942 if (class_exists('PDO_DataObjects_Introspection')) {
943 PDO_DataObject_Introspection::$cache = array();
945 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
946 $this->updateDataEnums();
947 $this->updateDataGroups();
948 $this->updateDataCompanies();
950 $c = DB_DataObject::Factory('I18n');
958 function fixMysqlInnodb()
961 static $done_check = false;
967 if (!empty($this->opts['skip-mysql-checks'])) {
970 // innodb in single files is far more efficient that MYD or one big innodb file.
971 // first check if database is using this format.
972 $db = DB_DataObject::factory('core_enum');
973 $db->query("show variables like 'innodb_file_per_table'");
975 if ($db->Value == 'OFF') {
976 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
979 $db = DB_DataObject::factory('core_enum');
980 $db->query("select version() as version");
983 if (version_compare($db->version, '5.7', '>=' )) {
985 $db = DB_DataObject::factory('core_enum');
986 $db->query("show variables like 'sql_mode'");
989 $modes = explode(",", $db->Value);
991 // these are 'new' problems with mysql.
993 in_array('NO_ZERO_IN_DATE', $modes) ||
994 in_array('NO_ZERO_DATE', $modes) ||
995 in_array('STRICT_TRANS_TABLES', $modes) ||
996 !in_array('ALLOW_INVALID_DATES', $modes)
998 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");
1002 $done_check = true;;
1013 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1015 function fixSequencesMysql()
1020 function fixSequencesPgsql()
1024 //DB_DataObject::debugLevel(1);
1025 $cs = DB_DataObject::factory('core_enum');
1029 CASE WHEN strpos(seq_name, '.') > 0 THEN
1032 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1035 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1036 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1040 n.nspname AS schema_name,
1041 c.relname AS table_name,
1042 a.attname AS column_name,
1043 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1045 JOIN pg_attribute a ON (c.oid=a.attrelid)
1046 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1047 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1048 WHERE has_schema_privilege(n.oid,'USAGE')
1049 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1050 AND has_table_privilege(c.oid,'SELECT')
1051 AND (NOT a.attisdropped)
1052 AND d.adsrc ~ '^nextval'
1056 CASE WHEN strpos(seq_name, '.') > 0 THEN
1057 substring(seq_name, 1,strpos(seq_name,'.')-1)
1062 GROUP BY seq_name HAVING count(*)=1
1065 while ($cs->fetch()) {
1068 foreach($cmds as $cmd) {
1069 $cs = DB_DataObject::factory('core_enum');
1073 $cs = DB_DataObject::factory('core_enum');
1075 SELECT 'SELECT SETVAL(' ||
1076 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1077 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1083 WHERE S.relkind = 'S'
1085 AND D.refobjid = T.oid
1086 AND D.refobjid = C.attrelid
1087 AND D.refobjsubid = C.attnum
1088 AND NS.oid = T.relnamespace
1092 while ($cs->fetch()) {
1095 foreach($cmds as $cmd) {
1096 $cs = DB_DataObject::factory('core_enum');
1103 var $extensions = array(
1108 function runExtensions()
1111 $ff = HTML_Flexyframework::get();
1113 $dburl = parse_url($ff->database);
1115 $dbtype = $dburl['scheme'];
1117 foreach($this->extensions as $ext) {
1119 $scls = ucfirst($dbtype). $ext;
1120 $cls = __CLASS__ . '_'. $scls;
1121 $fn = implode('/',explode('_', $cls)).'.php';
1122 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1133 function checkSystem($req = false, $pref = false)
1135 // most of these are from File_Convert...
1137 // these are required - and have simple dependancies.
1138 require_once 'System.php';
1139 $req = $req !== false ? $req : array(
1144 'rsvg-convert', //librsvg2-bin
1151 // these are prefered - but may have complicated depenacies
1152 $pref = $pref !== false ? $pref : array(
1156 'html2text', // not availabe in debian squeeze
1157 'pdftocairo', //poppler-utils - not available in debian squeeze.
1167 foreach($req as $r) {
1168 if (!System::which($r)) {
1174 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1176 foreach($pref as $r) {
1177 if (!System::which($r)) {
1183 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1190 function generateDataobjectsCache()
1192 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1198 function curl($url, $request = array(), $method = 'GET')
1200 if($method == 'GET'){
1201 $request = http_build_query($request);
1202 $url = $url . "?" . $request;
1205 $ch = curl_init($url);
1207 if ($method == 'POST') {
1209 curl_setopt($ch, CURLOPT_POST, 1);
1210 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1214 curl_setopt($ch, CURLOPT_HTTPHEADER,
1215 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1219 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1221 curl_setopt($ch, CURLOPT_HEADER, false);
1222 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1223 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1224 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1226 $response = curl_exec($ch);