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();
158 echo "Generate DB cache\n";
159 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
160 echo "Generated DB cache\n";
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']);
184 // ask all the modules to verify the opts
185 echo "Checi options\n";
186 $this->checkOpts($opts);
190 // do this first, so the innodb change + utf8 fixes column max sizes
192 // this will trigger errors about freetext indexes - we will have to remove them manually.?
193 // 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..)
195 $this->runExtensions();
198 if (empty($opts['data-only'])) {
201 if (!empty($opts['only-module-sql'])) {
207 $this->runUpdateModulesData();
209 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
210 // make sure we have a good cache...?
212 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
215 $this->runExtensions();
217 $this->clearApacheDataobjectsCache();
221 echo "\nUpdate Completed SUCCESS\n";
225 * imports SQL files from all DataObjects directories....
227 * except any matching /migrate/
232 // loop through all the modules, and see if they have a importSQL method?
235 $ff = HTML_Flexyframework::get();
237 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
239 //$this->{'import' . $url['scheme']}($url);
241 $dbtype = $dburl['scheme'];
244 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
249 $ar = $this->modulesList();
254 if(in_array($m, $this->disabled)){
255 echo "module $m is disabled \n";
259 echo "Importing SQL from module $m\n";
260 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
265 // check to see if the class has
269 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
270 if($m != 'Core' && file_exists($file)){
273 $class = "Pman_{$m}_UpdateDatabase";
275 if(method_exists($x, 'importModuleSQL')){
276 echo "Importing SQL from module $m using Module::importModuleSQL\n";
277 $x->opts = $this->opts;
278 $x->rootDir = $this->rootDir;
279 $x->importModuleSQL($dburl);
284 echo "Importing SQL from module $m\n";
287 // if init has been called
289 if (!empty($this->opts['init'])) {
290 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
296 $fd = $this->rootDir. "/Pman/$m/DataObjects";
298 $this->{$dirmethod}($dburl, $fd);
301 // new -- sql directory..
302 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
303 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
305 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
306 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
310 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
311 if (class_exists('PDO_DataObjects_Introspection')) {
312 PDO_DataObject_Introspection::$cache = array();
314 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
316 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
317 $this->{'fixSequences'. $dbtype}();
330 /** -------------- code to handle importing a whole directory of files into the database ------- **/
333 function importpgsqldir($url, $dir, $disable_triggers = false)
335 $ff = HTML_FlexyFramework::get();
337 require_once 'System.php';
338 $cat = System::which('cat');
339 $psql = System::which('psql');
342 if (!empty($url['pass'])) {
343 putenv("PGPASSWORD=". $url['pass']);
347 ' -h ' . $url['host'] .
348 ' -U' . escapeshellarg($url['user']) .
349 ' ' . basename($url['path']);
352 echo $psql_cmd . "\n" ;
353 echo "scan : $dir\n";
356 $files = array($dir);
361 $files = glob($dir.'/*.sql');
362 uksort($files, 'strcasecmp');
364 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
365 //usort($files, $lsort);
368 foreach($files as $bfn) {
371 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
374 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
375 && !preg_match('#\.pg\.sql#i', basename($bfn))
376 ) { // skip migration scripts at present..
381 if (!preg_match('/pgsql/', basename($dir) )) {
382 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
383 $fn = $this->convertToPG($bfn);
387 // files ending in .pg.sql are native postgres files.. ## depricated
390 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
392 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
408 * mysql - does not support conversions.
412 function importmysqlidir($dburl, $dir) {
413 return $this->importmysqldir($dburl, $dir);
416 function importmysqldir($dburl, $dir)
419 $this->fixMysqlInnodb(); /// run once
421 echo "Import MYSQL :: $dir\n";
424 require_once 'System.php';
425 $cat = System::which('cat');
426 $mysql = System::which('mysql');
430 $mysql_cmd = $mysql .
431 ' -h ' . $dburl['host'] .
432 ' -u' . escapeshellarg($dburl['user']) .
433 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
434 ' ' . basename($dburl['path']);
435 //echo $mysql_cmd . "\n" ;
437 $files = glob($dir.'/*.sql');
438 uksort($files, 'strcasecmp');
441 foreach($files as $fn) {
444 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
447 // .my.sql but not .pg.sql
448 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
449 && !preg_match('#\.my\.sql#i', basename($fn))
450 ) { // skip migration scripts at present..
453 if (!strlen(trim($fn))) {
457 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
459 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
462 $fp = popen($cmd, "r");
465 // send the current file part to the browser
466 $line = trim(fgets($fp, 1024));
471 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
472 echo " ---- {$line}\n"; flush();
476 switch($matches[1]) {
477 case 1017: // cause by renaming table -- old one does not exist..
478 case 1050: // create tables triggers this..
479 case 1060: // Duplicate column name
480 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
481 case 1091: // drop index -- name does not exist.. might hide errors..
483 case 1146: // drop a index on an unknown table.. - happens rarely...
484 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
490 echo " ---- {$line}\n"; flush();
494 // 1051: // Unknown table -- normally drop = add iff exists..
495 echo "File: $fn\n$line\n";
511 * simple regex based convert mysql to pgsql...
513 function convertToPG($src)
515 //echo "Convert $src\n";
517 $fn = $this->tempName('sql');
519 $ret = array( ); // pad it a bit.
520 $extra = array("", "" );
523 foreach(file($src) as $l) {
526 if (!strlen($l) || $l[0] == '#') {
530 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
533 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
534 $tbl = 'shop_' . strtolower($m[1]);
535 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
537 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
538 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
541 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
542 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
543 $extra[] = "create sequence {$tbl}_seq;";
547 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
548 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
551 // enum value -- use the text instead..
553 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
554 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
556 // ignore the alter enum
557 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
561 // UNIQUE KEY .. ignore
562 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
563 $last = array_pop($ret);
564 $ret[] = trim($last, ",");
568 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
572 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
576 // INDEX lookup ..ignore
577 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
578 $last = array_pop($ret);
579 $ret[] = trim($last, ",");
584 // CREATE INDEX ..ignore
585 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
586 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
591 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
593 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
594 $l = preg_replace('# blob#i', ' TEXT', $l);
595 $l = preg_replace('# longtext#i', ' TEXT', $l);
596 $l = preg_replace('# tinyint#i', ' INT', $l);
602 $ret = array_merge($extra,$ret);
603 // echo implode("\n", $ret); exit;
605 file_put_contents($fn, implode("\n", $ret));
611 function checkOpts($opts)
615 foreach($opts as $o=>$v) {
616 if (!preg_match('/^json-/', $o) || empty($v)) {
619 if (!file_exists($v)) {
620 die("File does not exist : OPTION --{$o} = {$v} \n");
624 $modules = array_reverse($this->modulesList());
626 // move 'project' one to the end...
628 foreach ($modules as $module){
629 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
630 if($module == 'Core' || !file_exists($file)){
634 $class = "Pman_{$module}_UpdateDatabase";
636 if(!method_exists($x, 'checkOpts')){
639 $x->checkOpts($opts);
643 static function jsonImportFromArray($opts)
645 foreach($opts as $o=>$v) {
646 if (!preg_match('/^json-/', $o) || empty($v)) {
649 $type = str_replace('_', '-', substr($o,5));
651 $data= json_decode(file_get_contents($v),true);
652 $pg = HTML_FlexyFramework::get()->page;
653 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
663 function runUpdateModulesData()
665 if (class_exists('PDO_DataObjects_Introspection')) {
666 PDO_DataObject_Introspection::$cache = array();
668 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
670 if(!in_array('Core', $this->disabled)){
671 echo "Running jsonImportFromArray\n";
672 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
675 echo "Running updateData on modules\n";
681 $modules = array_reverse($this->modulesList());
683 // move 'project' one to the end...
685 foreach ($modules as $module){
686 if(in_array($module, $this->disabled)){
689 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
690 if($module == 'Core' || !file_exists($file)){
695 $class = "Pman_{$module}_UpdateDatabase";
697 if(!method_exists($x, 'updateData')){
707 function updateDataEnums()
709 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
711 $enum = DB_DataObject::Factory('core_enum');
712 //DB_DAtaObject::debugLevel(1);
717 'name' => 'COMPTYPE',
718 'display_name' => 'Company Types',
719 'is_system_enum' => 1,
723 'display_name' => 'Owner',
724 'seqid' => 999, // last...
725 'is_system_enum' => 1,
732 'name' => 'HtmlEditor.font-family',
733 'display_name' => 'HTML Editor font families',
734 'is_system_enum' => 1,
737 'name' => 'Helvetica,Arial,sans-serif',
738 'display_name' => 'Helvetica',
743 'name' => 'Courier New',
744 'display_name' => 'Courier',
749 'display_name' => 'Tahoma',
753 'name' => 'Times New Roman,serif',
754 'display_name' => 'Times',
759 'display_name' => 'Verdana',
772 function updateDataGroups()
775 $groups = DB_DataObject::factory('core_group');
776 $groups->initGroups();
778 $groups->initDatabase($this,array(
780 'name' => 'bcc-email', // group who are bcc'ed on all requests.
781 'type' => 0, // system
784 'name' => 'system-email-from',
785 'type' => 0, // system
788 'name' => 'core-person-signup-bcc',
789 'type' => 0, // system
797 function updateDataCompanies()
800 // fix comptypes enums..
801 $c = DB_DataObject::Factory('core_company');
803 $c->selectAdd('distinct(comptype) as comptype');
804 $c->whereAdd("comptype != ''");
807 foreach($c->fetchAll('comptype') as $cts) {
811 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
814 $c = DB_DataObject::Factory('core_enum');
817 //DB_DataObject::debugLevel(1);
819 $c = DB_DataObject::Factory('core_company');
821 UPDATE {$c->tableName()}
823 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
837 function initEmails($templateDir, $emails, $mapping = false)
839 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
841 $pg = HTML_FlexyFramework::get()->page;
842 foreach($emails as $name=>$data) {
843 $cm = DB_DataObject::factory('core_email');
844 $update = $cm->get('name', $name);
847 if (empty($cm->bcc_group_id)) {
848 if (empty($data['bcc_group'])) {
849 $this->jerr("missing bcc_group for template $name");
851 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
854 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
857 if (!$g->members('email')) {
858 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
861 $cm->bcc_group_id = $g->id;
863 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
864 //if (empty($cm->test_class)) {
865 if (empty($data['test_class'])) {
866 $this->jerr("missing test_class for template $name");
868 $cm->test_class = $data['test_class'];
870 if(isset($cm->to_group_id)) {
875 !empty($data['to_group']) &&
876 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
878 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
880 if (empty($gp->id)) {
881 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
884 $cm->to_group_id = $gp->id;
888 isset($data['active']) && !isset($cm->active)
890 $cm->active = $data['active'];
893 require_once $cm->test_class . '.php';
895 $clsname = str_replace('/','_', $cm->test_class);
897 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
898 $got_it = $method->isStatic();
899 } catch(Exception $e) {
904 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
908 echo "email: {$name} - checked\n";
909 continue; /// we do not import the body content of templates that exist...
916 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
920 'file' => $templateDir. $name .'.html'
923 if (!empty($data['master'])) {
924 $opts['master'] = $templateDir . $master .'.html';
926 require_once 'Pman/Core/Import/Core_email.php';
927 $x = new Pman_Core_Import_Core_email();
929 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
931 echo "email: {$name} - CREATED\n";
936 function updateData()
939 if (class_exists('PDO_DataObjects_Introspection')) {
940 PDO_DataObject_Introspection::$cache = array();
942 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
945 $this->updateDataEnums();
946 $this->updateDataGroups();
947 $this->updateDataCompanies();
949 $c = DB_DataObject::Factory('I18n');
957 function fixMysqlInnodb()
960 static $done_check = false;
966 if (!empty($this->opts['skip-mysql-checks'])) {
969 // innodb in single files is far more efficient that MYD or one big innodb file.
970 // first check if database is using this format.
971 $db = DB_DataObject::factory('core_enum');
972 $db->query("show variables like 'innodb_file_per_table'");
974 if ($db->Value == 'OFF') {
975 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
978 $db = DB_DataObject::factory('core_enum');
979 $db->query("select version() as version");
982 if (version_compare($db->version, '5.7', '>=' )) {
984 $db = DB_DataObject::factory('core_enum');
985 $db->query("show variables like 'sql_mode'");
988 $modes = explode(",", $db->Value);
990 // these are 'new' problems with mysql.
992 in_array('NO_ZERO_IN_DATE', $modes) ||
993 in_array('NO_ZERO_DATE', $modes) ||
994 in_array('STRICT_TRANS_TABLES', $modes) ||
995 !in_array('ALLOW_INVALID_DATES', $modes)
997 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 $done_check = true;;
1012 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1014 function fixSequencesMysql()
1019 function fixSequencesPgsql()
1023 //DB_DataObject::debugLevel(1);
1024 $cs = DB_DataObject::factory('core_enum');
1028 CASE WHEN strpos(seq_name, '.') > 0 THEN
1031 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1034 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1035 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1039 n.nspname AS schema_name,
1040 c.relname AS table_name,
1041 a.attname AS column_name,
1042 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1044 JOIN pg_attribute a ON (c.oid=a.attrelid)
1045 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1046 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1047 WHERE has_schema_privilege(n.oid,'USAGE')
1048 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1049 AND has_table_privilege(c.oid,'SELECT')
1050 AND (NOT a.attisdropped)
1051 AND d.adsrc ~ '^nextval'
1055 CASE WHEN strpos(seq_name, '.') > 0 THEN
1056 substring(seq_name, 1,strpos(seq_name,'.')-1)
1061 GROUP BY seq_name HAVING count(*)=1
1064 while ($cs->fetch()) {
1067 foreach($cmds as $cmd) {
1068 $cs = DB_DataObject::factory('core_enum');
1072 $cs = DB_DataObject::factory('core_enum');
1074 SELECT 'SELECT SETVAL(' ||
1075 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1076 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1082 WHERE S.relkind = 'S'
1084 AND D.refobjid = T.oid
1085 AND D.refobjid = C.attrelid
1086 AND D.refobjsubid = C.attnum
1087 AND NS.oid = T.relnamespace
1091 while ($cs->fetch()) {
1094 foreach($cmds as $cmd) {
1095 $cs = DB_DataObject::factory('core_enum');
1102 var $extensions = array(
1107 function runExtensions()
1110 $ff = HTML_Flexyframework::get();
1112 $dburl = parse_url($ff->database);
1114 $dbtype = $dburl['scheme'];
1116 foreach($this->extensions as $ext) {
1118 $scls = ucfirst($dbtype). $ext;
1119 $cls = __CLASS__ . '_'. $scls;
1120 $fn = implode('/',explode('_', $cls)).'.php';
1121 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1132 function checkSystem($req = false, $pref = false)
1134 // most of these are from File_Convert...
1136 // these are required - and have simple dependancies.
1137 require_once 'System.php';
1138 $req = $req !== false ? $req : array(
1143 'rsvg-convert', //librsvg2-bin
1150 // these are prefered - but may have complicated depenacies
1151 $pref = $pref !== false ? $pref : array(
1155 'html2text', // not availabe in debian squeeze
1156 'pdftocairo', //poppler-utils - not available in debian squeeze.
1166 foreach($req as $r) {
1167 if (!System::which($r)) {
1173 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1175 foreach($pref as $r) {
1176 if (!System::which($r)) {
1182 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1189 function clearApacheDataobjectsCache()
1192 // this needs to clear it's own cache along with remote one..
1194 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1196 $response = $this->curl($url);
1198 $json = json_decode($response, true);
1200 if(empty($json['data']) || $json['data'] != 'DONE'){
1201 echo $response. "\n";
1202 echo "CURL clear cache failed\n";
1208 function curl($url, $request = array(), $method = 'GET')
1210 if($method == 'GET'){
1211 $request = http_build_query($request);
1212 $url = $url . "?" . $request;
1215 $ch = curl_init($url);
1217 if ($method == 'POST') {
1219 curl_setopt($ch, CURLOPT_POST, 1);
1220 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1224 curl_setopt($ch, CURLOPT_HTTPHEADER,
1225 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1229 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1231 curl_setopt($ch, CURLOPT_HEADER, false);
1232 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1233 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1234 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1236 $response = curl_exec($ch);