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 $this->verifyExtensions(array('curl'));
157 if (class_exists('PDO_DataObjects_Introspection')) {
158 PDO_DataObject_Introspection::$cache = array();
160 echo "Generate DB cache\n";
161 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
162 echo "Generated DB cache\n";
163 $ff = HTML_FlexyFramework::get();
165 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
166 die("Please setup Pman[local_base_url]\n");
169 $this->local_base_url = $ff->Pman['local_base_url'];
171 if(!empty($ff->Core_Notify)){
172 // require_once 'Pman/Core/NotifySmtpCheck.php';
173 // $x = new Pman_Core_NotifySmtpCheck();
177 $this->disabled = explode(',', $ff->disable);
179 //$this->fixSequencesPgsql();exit;
182 if (!empty($opts['debug'])) {
183 DB_DataObject::DebugLevel($opts['debug']);
186 // ask all the modules to verify the opts
187 echo "Checi options\n";
188 $this->checkOpts($opts);
192 // do this first, so the innodb change + utf8 fixes column max sizes
194 // this will trigger errors about freetext indexes - we will have to remove them manually.?
195 // 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..)
197 $this->runExtensions();
200 if (empty($opts['data-only'])) {
203 if (!empty($opts['only-module-sql'])) {
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->clearApacheDataobjectsCache();
221 $this->clearApacheAssetCache();
225 echo "\nUpdate Completed SUCCESS\n";
229 * imports SQL files from all DataObjects directories....
231 * except any matching /migrate/
236 // loop through all the modules, and see if they have a importSQL method?
239 $ff = HTML_Flexyframework::get();
241 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
243 //$this->{'import' . $url['scheme']}($url);
245 $dbtype = $dburl['scheme'];
248 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
253 $ar = $this->modulesList();
258 if(in_array($m, $this->disabled)){
259 echo "module $m is disabled \n";
263 echo "Importing SQL from module $m\n";
264 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
269 // check to see if the class has
273 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
274 if($m != 'Core' && file_exists($file)){
277 $class = "Pman_{$m}_UpdateDatabase";
279 if(method_exists($x, 'importModuleSQL')){
280 echo "Importing SQL from module $m using Module::importModuleSQL\n";
281 $x->opts = $this->opts;
282 $x->rootDir = $this->rootDir;
283 $x->importModuleSQL($dburl);
288 echo "Importing SQL from module $m\n";
291 // if init has been called
293 if (!empty($this->opts['init'])) {
294 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
300 $fd = $this->rootDir. "/Pman/$m/DataObjects";
302 $this->{$dirmethod}($dburl, $fd);
305 // new -- sql directory..
306 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
307 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
308 $dbdir = $dbtype == 'mysqli' ? 'mysql' : $dbtype;
310 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
311 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbdir}");
315 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
316 if (class_exists('PDO_DataObjects_Introspection')) {
317 PDO_DataObject_Introspection::$cache = array();
319 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
321 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
322 $this->{'fixSequences'. $dbtype}();
335 /** -------------- code to handle importing a whole directory of files into the database ------- **/
338 function importpgsqldir($url, $dir, $disable_triggers = false)
340 $ff = HTML_FlexyFramework::get();
342 require_once 'System.php';
343 $cat = System::which('cat');
344 $psql = System::which('psql');
347 if (!empty($url['pass'])) {
348 putenv("PGPASSWORD=". $url['pass']);
352 ' -h ' . $url['host'] .
353 ' -U' . escapeshellarg($url['user']) .
354 ' ' . basename($url['path']);
357 echo $psql_cmd . "\n" ;
358 echo "scan : $dir\n";
361 $files = array($dir);
366 $files = glob($dir.'/*.sql');
367 uksort($files, 'strcasecmp');
369 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
370 //usort($files, $lsort);
373 foreach($files as $bfn) {
376 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
379 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
380 && !preg_match('#\.pg\.sql#i', basename($bfn))
381 ) { // skip migration scripts at present..
386 if (!preg_match('/pgsql/', basename($dir) )) {
387 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
388 $fn = $this->convertToPG($bfn);
392 // files ending in .pg.sql are native postgres files.. ## depricated
395 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
397 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
413 * mysql - does not support conversions.
417 function importmysqlidir($dburl, $dir) {
418 return $this->importmysqldir($dburl, $dir);
421 function importmysqldir($dburl, $dir)
424 $this->fixMysqlInnodb(); /// run once
426 echo "Import MYSQL :: $dir\n";
429 require_once 'System.php';
430 $cat = System::which('cat');
431 $mysql = System::which('mysql');
435 $mysql_cmd = $mysql .
436 ' -h ' . $dburl['host'] .
437 ' -u' . escapeshellarg($dburl['user']) .
438 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
439 ' ' . basename($dburl['path']);
440 //echo $mysql_cmd . "\n" ;
442 $files = glob($dir.'/*.sql');
443 uksort($files, 'strcasecmp');
446 foreach($files as $fn) {
449 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
452 // .my.sql but not .pg.sql
453 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
454 && !preg_match('#\.my\.sql#i', basename($fn))
455 ) { // skip migration scripts at present..
458 if (!strlen(trim($fn))) {
462 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
464 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
467 $fp = popen($cmd, "r");
470 // send the current file part to the browser
471 $line = trim(fgets($fp, 1024));
476 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
477 echo " ---- {$line}\n"; flush();
481 switch($matches[1]) {
482 case 1017: // cause by renaming table -- old one does not exist..
483 case 1050: // create tables triggers this..
484 case 1060: // Duplicate column name
485 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
486 case 1091: // drop index -- name does not exist.. might hide errors..
488 case 1146: // drop a index on an unknown table.. - happens rarely...
489 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
495 echo " ---- {$line}\n"; flush();
499 // 1051: // Unknown table -- normally drop = add iff exists..
500 echo "File: $fn\n$line\n";
516 * simple regex based convert mysql to pgsql...
518 function convertToPG($src)
520 //echo "Convert $src\n";
522 $fn = $this->tempName('sql');
524 $ret = array( ); // pad it a bit.
525 $extra = array("", "" );
528 foreach(file($src) as $l) {
531 if (!strlen($l) || $l[0] == '#') {
535 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
538 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
539 $tbl = 'shop_' . strtolower($m[1]);
540 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
542 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
543 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
546 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
547 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
548 $extra[] = "create sequence {$tbl}_seq;";
552 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
553 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
556 // enum value -- use the text instead..
558 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
559 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
561 // ignore the alter enum
562 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
566 // UNIQUE KEY .. ignore
567 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
568 $last = array_pop($ret);
569 $ret[] = trim($last, ",");
573 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
577 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
581 // INDEX lookup ..ignore
582 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
583 $last = array_pop($ret);
584 $ret[] = trim($last, ",");
589 // CREATE INDEX ..ignore
590 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
591 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
596 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
598 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
599 $l = preg_replace('# blob#i', ' TEXT', $l);
600 $l = preg_replace('# longtext#i', ' TEXT', $l);
601 $l = preg_replace('# tinyint#i', ' INT', $l);
607 $ret = array_merge($extra,$ret);
608 // echo implode("\n", $ret); exit;
610 file_put_contents($fn, implode("\n", $ret));
616 function checkOpts($opts)
620 foreach($opts as $o=>$v) {
621 if (!preg_match('/^json-/', $o) || empty($v)) {
624 if (!file_exists($v)) {
625 die("File does not exist : OPTION --{$o} = {$v} \n");
629 $modules = array_reverse($this->modulesList());
631 // move 'project' one to the end...
633 foreach ($modules as $module){
634 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
635 if($module == 'Core' || !file_exists($file)){
639 $class = "Pman_{$module}_UpdateDatabase";
641 if(!method_exists($x, 'checkOpts')){
644 $x->checkOpts($opts);
648 static function jsonImportFromArray($opts)
650 foreach($opts as $o=>$v) {
651 if (!preg_match('/^json-/', $o) || empty($v)) {
654 $type = str_replace('_', '-', substr($o,5));
656 $data= json_decode(file_get_contents($v),true);
657 $pg = HTML_FlexyFramework::get()->page;
658 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
668 function runUpdateModulesData()
670 if (class_exists('PDO_DataObjects_Introspection')) {
671 PDO_DataObject_Introspection::$cache = array();
673 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
675 if(!in_array('Core', $this->disabled)){
676 echo "Running jsonImportFromArray\n";
677 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
680 echo "Running updateData on modules\n";
686 $modules = array_reverse($this->modulesList());
688 // move 'project' one to the end...
690 foreach ($modules as $module){
691 if(in_array($module, $this->disabled)){
694 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
695 if($module == 'Core' || !file_exists($file)){
700 $class = "Pman_{$module}_UpdateDatabase";
702 if(!method_exists($x, 'updateData')){
712 function updateDataEnums()
714 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
716 $enum = DB_DataObject::Factory('core_enum');
717 //DB_DAtaObject::debugLevel(1);
722 'name' => 'COMPTYPE',
723 'display_name' => 'Company Types',
724 'is_system_enum' => 1,
728 'display_name' => 'Owner',
729 'seqid' => 999, // last...
730 'is_system_enum' => 1,
737 'name' => 'HtmlEditor.font-family',
738 'display_name' => 'HTML Editor font families',
739 'is_system_enum' => 1,
742 'name' => 'Helvetica,Arial,sans-serif',
743 'display_name' => 'Helvetica',
748 'name' => 'Courier New',
749 'display_name' => 'Courier',
754 'display_name' => 'Tahoma',
758 'name' => 'Times New Roman,serif',
759 'display_name' => 'Times',
764 'display_name' => 'Verdana',
777 function updateDataGroups()
780 $groups = DB_DataObject::factory('core_group');
781 $groups->initGroups();
783 $groups->initDatabase($this,array(
785 'name' => 'bcc-email', // group who are bcc'ed on all requests.
786 'type' => 0, // system
789 'name' => 'system-email-from',
790 'type' => 0, // system
793 'name' => 'core-person-signup-bcc',
794 'type' => 0, // system
802 function updateDataCompanies()
805 // fix comptypes enums..
806 $c = DB_DataObject::Factory('core_company');
808 $c->selectAdd('distinct(comptype) as comptype');
809 $c->whereAdd("comptype != ''");
812 foreach($c->fetchAll('comptype') as $cts) {
816 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
819 $c = DB_DataObject::Factory('core_enum');
822 //DB_DataObject::debugLevel(1);
824 $c = DB_DataObject::Factory('core_company');
826 UPDATE {$c->tableName()}
828 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
842 function initEmails($templateDir, $emails, $mapping = false)
844 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
846 $pg = HTML_FlexyFramework::get()->page;
847 foreach($emails as $name=>$data) {
848 $cm = DB_DataObject::factory('core_email');
849 $update = $cm->get('name', $name);
852 if (empty($cm->bcc_group_id)) {
853 if (empty($data['bcc_group'])) {
854 $this->jerr("missing bcc_group for template $name");
856 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
859 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
862 if (!$g->members('email')) {
863 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
866 $cm->bcc_group_id = $g->id;
868 // initEmails will always have the latest location of the test class - in theory the user should not be changign the value of this...
869 //if (empty($cm->test_class)) {
870 if (empty($data['test_class'])) {
871 $this->jerr("missing test_class for template $name");
873 $cm->test_class = $data['test_class'];
875 if(isset($cm->to_group_id)) {
880 !empty($data['to_group']) &&
881 (!isset($cm->to_group_id) || !empty($cm->to_group_id))
883 $gp = DB_DataObject::Factory('core_group')->lookup('name',$data['to_group']);
885 if (empty($gp->id)) {
886 $this->jerr("to_group {$data['to_group']} does not exist when importing template $name");
889 $cm->to_group_id = $gp->id;
893 isset($data['active']) && !isset($cm->active)
895 $cm->active = $data['active'];
898 require_once $cm->test_class . '.php';
900 $clsname = str_replace('/','_', $cm->test_class);
902 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
903 $got_it = $method->isStatic();
904 } catch(Exception $e) {
909 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
913 echo "email: {$name} - checked\n";
914 continue; /// we do not import the body content of templates that exist...
921 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
925 'file' => $templateDir. $name .'.html'
928 if (!empty($data['master'])) {
929 $opts['master'] = $templateDir . $master .'.html';
931 require_once 'Pman/Core/Import/Core_email.php';
932 $x = new Pman_Core_Import_Core_email();
934 $x->updateOrCreateEmail('', $opts, $cm, $mapping);
936 echo "email: {$name} - CREATED\n";
941 function updateData()
944 if (class_exists('PDO_DataObjects_Introspection')) {
945 PDO_DataObject_Introspection::$cache = array();
947 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
950 $this->updateDataEnums();
951 $this->updateDataGroups();
952 $this->updateDataCompanies();
954 $c = DB_DataObject::Factory('I18n');
962 function fixMysqlInnodb()
965 static $done_check = false;
971 if (!empty($this->opts['skip-mysql-checks'])) {
974 // innodb in single files is far more efficient that MYD or one big innodb file.
975 // first check if database is using this format.
976 $db = DB_DataObject::factory('core_enum');
977 $db->query("show variables like 'innodb_file_per_table'");
979 if ($db->Value == 'OFF') {
980 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
983 $db = DB_DataObject::factory('core_enum');
984 $db->query("select version() as version");
987 if (version_compare($db->version, '5.7', '>=' )) {
989 $db = DB_DataObject::factory('core_enum');
990 $db->query("show variables like 'sql_mode'");
993 $modes = explode(",", $db->Value);
995 // these are 'new' problems with mysql.
997 in_array('NO_ZERO_IN_DATE', $modes) ||
998 in_array('NO_ZERO_DATE', $modes) ||
999 in_array('STRICT_TRANS_TABLES', $modes) ||
1000 !in_array('ALLOW_INVALID_DATES', $modes)
1002 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");
1006 $done_check = true;;
1017 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
1019 function fixSequencesMysql()
1024 function fixSequencesPgsql()
1028 //DB_DataObject::debugLevel(1);
1029 $cs = DB_DataObject::factory('core_enum');
1033 CASE WHEN strpos(seq_name, '.') > 0 THEN
1036 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
1039 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
1040 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
1044 n.nspname AS schema_name,
1045 c.relname AS table_name,
1046 a.attname AS column_name,
1047 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
1049 JOIN pg_attribute a ON (c.oid=a.attrelid)
1050 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
1051 JOIN pg_namespace n ON (c.relnamespace=n.oid)
1052 WHERE has_schema_privilege(n.oid,'USAGE')
1053 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1054 AND has_table_privilege(c.oid,'SELECT')
1055 AND (NOT a.attisdropped)
1056 AND d.adsrc ~ '^nextval'
1060 CASE WHEN strpos(seq_name, '.') > 0 THEN
1061 substring(seq_name, 1,strpos(seq_name,'.')-1)
1066 GROUP BY seq_name HAVING count(*)=1
1069 while ($cs->fetch()) {
1072 foreach($cmds as $cmd) {
1073 $cs = DB_DataObject::factory('core_enum');
1077 $cs = DB_DataObject::factory('core_enum');
1079 SELECT 'SELECT SETVAL(' ||
1080 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1081 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1087 WHERE S.relkind = 'S'
1089 AND D.refobjid = T.oid
1090 AND D.refobjid = C.attrelid
1091 AND D.refobjsubid = C.attnum
1092 AND NS.oid = T.relnamespace
1096 while ($cs->fetch()) {
1099 foreach($cmds as $cmd) {
1100 $cs = DB_DataObject::factory('core_enum');
1107 var $extensions = array(
1112 function runExtensions()
1115 $ff = HTML_Flexyframework::get();
1117 $dburl = parse_url($ff->database);
1119 $dbtype = $dburl['scheme'];
1121 foreach($this->extensions as $ext) {
1123 $scls = ucfirst($dbtype). $ext;
1124 $cls = __CLASS__ . '_'. $scls;
1125 $fn = implode('/',explode('_', $cls)).'.php';
1126 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1137 function checkSystem($req = false, $pref = false)
1139 // most of these are from File_Convert...
1141 // these are required - and have simple dependancies.
1142 require_once 'System.php';
1143 $req = $req !== false ? $req : array(
1148 'rsvg-convert', //librsvg2-bin
1155 // these are prefered - but may have complicated depenacies
1156 $pref = $pref !== false ? $pref : array(
1160 'html2text', // not availabe in debian squeeze
1161 'pdftocairo', //poppler-utils - not available in debian squeeze.
1171 foreach($req as $r) {
1172 if (!System::which($r)) {
1178 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1180 foreach($pref as $r) {
1181 if (!System::which($r)) {
1187 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1194 function clearApacheDataobjectsCache()
1196 echo "Clearing Database Cache\n";
1197 // this needs to clear it's own cache along with remote one..
1200 $response = $this->curl("http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache");
1202 $json = json_decode($response, true);
1204 if(empty($json['data']) || $json['data'] != 'DONE'){
1205 echo $response. "\n";
1206 echo "Clear DataObjects Cache failed\n";
1213 function clearApacheAssetCache()
1215 echo "Clearing Asset Cache\n";
1216 $response = $this->curl(
1217 "http://localhost{$this->local_base_url}/Core/Asset",
1218 array( '_clear_cache' => 1 ,'returnHTML' => 'NO' ),
1221 $json = json_decode($response, true);
1223 if(empty($json['success']) || !$json['success']) {
1224 echo $response. "\n";
1225 echo "CURL Clear Asset cache failed\n";
1232 function curl($url, $request = array(), $method = 'GET')
1234 if($method == 'GET'){
1235 $request = http_build_query($request);
1236 $url = $url . "?" . $request;
1239 $ch = curl_init($url);
1241 if ($method == 'POST') {
1243 curl_setopt($ch, CURLOPT_POST, 1);
1244 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1247 curl_setopt($ch, CURLOPT_HTTPHEADER,
1248 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1252 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1254 curl_setopt($ch, CURLOPT_HEADER, false);
1255 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1256 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1257 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1259 $response = curl_exec($ch);
1266 static function verifyExtensions($extensions)
1270 foreach ($extensions as $e){
1272 if(extension_loaded($e)) {
1276 $error[] = "Error: Please install php extension: {$e}";
1282 $ff = HTML_FLexyFramework::get();
1284 $ff->page->jerr(implode('\n', $error));