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 'procedures-only' => array(
65 'desc' => 'Only import procedures (not supported by most modules yet) - ignores sql directory',
71 'json-person' => array(
72 'desc' => 'Person JSON file',
80 static function cli_opts()
83 $ret = self::$cli_opts;
84 $ff = HTML_FlexyFramework::get();
86 $mods = $a->modulesList();
87 foreach($mods as $m) {
89 $fd = $ff->rootDir. "/Pman/$m/UpdateDatabase.php";
90 if (!file_exists($fd)) {
96 $cls = new ReflectionClass('Pman_'. $m . '_UpdateDatabase');
98 $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
107 var $disabled = array();
112 var $local_base_url = false;
117 $ff = HTML_FlexyFramework::get();
118 if (!empty($ff->cli)) {
123 parent::getAuth(); // load company!
124 $au = $this->getAuthUser();
125 if (!$au || $au->company()->comptype != 'OWNER') {
126 $this->jerr("Not authenticated", array('authFailure' => true));
128 $this->authUser = $au;
132 function get($args, $opts=array())
134 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
136 $this->checkSystem();
138 if (class_exists('PDO_DataObjects_Introspection')) {
139 PDO_DataObject_Introspection::$cache = array();
142 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
144 $ff = HTML_FlexyFramework::get();
146 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
147 die("Please setup local_base_url");
150 $this->local_base_url = $ff->Pman['local_base_url'];
152 if(!empty($ff->Core_Notify)){
153 // require_once 'Pman/Core/NotifySmtpCheck.php';
154 // $x = new Pman_Core_NotifySmtpCheck();
158 $this->disabled = explode(',', $ff->disable);
160 //$this->fixSequencesPgsql();exit;
163 // ask all the modules to verify the opts
165 $this->checkOpts($opts);
168 // do this first, so the innodb change + utf8 fixes column max sizes
170 // this will trigger errors about freetext indexes - we will have to remove them manually.?
171 // 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..)
173 $this->runExtensions();
176 if (empty($opts['data-only'])) {
179 if (!empty($opts['only-module-sql'])) {
182 echo "GET HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\n";exit;
183 $this->runUpdateModulesData();
187 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
188 // make sure we have a good cache...?
190 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
193 $this->runExtensions();
195 $this->generateDataobjectsCache();
203 * imports SQL files from all DataObjects directories....
205 * except any matching /migrate/
210 // loop through all the modules, and see if they have a importSQL method?
213 $ff = HTML_Flexyframework::get();
215 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
217 //$this->{'import' . $url['scheme']}($url);
219 $dbtype = $dburl['scheme'];
222 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
227 $ar = $this->modulesList();
232 if(in_array($m, $this->disabled)){
233 echo "module $m is disabled \n";
237 echo "Importing SQL from module $m\n";
238 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
243 // check to see if the class has
247 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
248 if($m != 'Core' && file_exists($file)){
251 $class = "Pman_{$m}_UpdateDatabase";
253 if(method_exists($x, 'importModuleSQL')){
254 echo "Importing SQL from module $m using Module::importModuleSQL\n";
255 $x->opts = $this->opts;
256 $x->rootDir = $this->rootDir;
257 $x->importModuleSQL($dburl);
262 echo "Importing SQL from module $m\n";
265 // if init has been called
267 if (!empty($this->opts['init'])) {
268 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
274 $fd = $this->rootDir. "/Pman/$m/DataObjects";
276 $this->{$dirmethod}($dburl, $fd);
279 // new -- sql directory..
280 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
281 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
283 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
284 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
288 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
289 if (class_exists('PDO_DataObjects_Introspection')) {
290 PDO_DataObject_Introspection::$cache = array();
292 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
294 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
295 $this->{'fixSequences'. $dbtype}();
308 /** -------------- code to handle importing a whole directory of files into the database ------- **/
311 function importpgsqldir($url, $dir, $disable_triggers = false)
313 $ff = HTML_FlexyFramework::get();
315 require_once 'System.php';
316 $cat = System::which('cat');
317 $psql = System::which('psql');
320 if (!empty($url['pass'])) {
321 putenv("PGPASSWORD=". $url['pass']);
325 ' -h ' . $url['host'] .
326 ' -U' . escapeshellarg($url['user']) .
327 ' ' . basename($url['path']);
330 echo $psql_cmd . "\n" ;
331 echo "scan : $dir\n";
334 $files = array($dir);
339 $files = glob($dir.'/*.sql');
340 uksort($files, 'strcasecmp');
342 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
343 //usort($files, $lsort);
346 foreach($files as $bfn) {
349 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
352 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
353 && !preg_match('#\.pg\.sql#i', basename($bfn))
354 ) { // skip migration scripts at present..
359 if (!preg_match('/pgsql/', basename($dir) )) {
360 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
361 $fn = $this->convertToPG($bfn);
365 // files ending in .pg.sql are native postgres files.. ## depricated
368 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
370 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
386 * mysql - does not support conversions.
390 function importmysqlidir($dburl, $dir) {
391 return $this->importmysqldir($dburl, $dir);
394 function importmysqldir($dburl, $dir)
397 $this->fixMysqlInnodb(); /// run once
399 echo "Import MYSQL :: $dir\n";
402 require_once 'System.php';
403 $cat = System::which('cat');
404 $mysql = System::which('mysql');
408 $mysql_cmd = $mysql .
409 ' -h ' . $dburl['host'] .
410 ' -u' . escapeshellarg($dburl['user']) .
411 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
412 ' ' . basename($dburl['path']);
413 //echo $mysql_cmd . "\n" ;
415 $files = glob($dir.'/*.sql');
416 uksort($files, 'strcasecmp');
419 foreach($files as $fn) {
422 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
425 // .my.sql but not .pg.sql
426 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
427 && !preg_match('#\.my\.sql#i', basename($fn))
428 ) { // skip migration scripts at present..
431 if (!strlen(trim($fn))) {
435 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
437 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
440 $fp = popen($cmd, "r");
443 // send the current file part to the browser
444 $line = trim(fgets($fp, 1024));
449 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
450 echo " ---- {$line}\n"; flush();
454 switch($matches[1]) {
455 case 1017: // cause by renaming table -- old one does not exist..
456 case 1050: // create tables triggers this..
457 case 1060: // Duplicate column name
458 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
459 case 1091: // drop index -- name does not exist.. might hide errors..
461 case 1146: // drop a index on an unknown table.. - happens rarely...
462 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
468 echo " ---- {$line}\n"; flush();
472 // 1051: // Unknown table -- normally drop = add iff exists..
473 echo "File: $fn\n$line\n";
489 * simple regex based convert mysql to pgsql...
491 function convertToPG($src)
493 //echo "Convert $src\n";
495 $fn = $this->tempName('sql');
497 $ret = array( ); // pad it a bit.
498 $extra = array("", "" );
501 foreach(file($src) as $l) {
504 if (!strlen($l) || $l[0] == '#') {
508 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
511 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
512 $tbl = 'shop_' . strtolower($m[1]);
513 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
515 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
516 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
519 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
520 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
521 $extra[] = "create sequence {$tbl}_seq;";
525 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
526 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
529 // enum value -- use the text instead..
531 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
532 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
534 // ignore the alter enum
535 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
539 // UNIQUE KEY .. ignore
540 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
541 $last = array_pop($ret);
542 $ret[] = trim($last, ",");
546 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
550 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
554 // INDEX lookup ..ignore
555 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
556 $last = array_pop($ret);
557 $ret[] = trim($last, ",");
562 // CREATE INDEX ..ignore
563 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
564 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
569 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
571 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
572 $l = preg_replace('# blob#i', ' TEXT', $l);
573 $l = preg_replace('# longtext#i', ' TEXT', $l);
574 $l = preg_replace('# tinyint#i', ' INT', $l);
580 $ret = array_merge($extra,$ret);
581 // echo implode("\n", $ret); exit;
583 file_put_contents($fn, implode("\n", $ret));
589 function checkOpts($opts)
593 foreach($opts as $o=>$v) {
594 if (!preg_match('/^json-/', $o) || empty($v)) {
597 if (!file_exists($v)) {
598 die("File does not exist : OPTION --{$o} = {$v} \n");
602 $modules = array_reverse($this->modulesList());
604 // move 'project' one to the end...
606 foreach ($modules as $module){
607 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
608 if($module == 'Core' || !file_exists($file)){
612 $class = "Pman_{$module}_UpdateDatabase";
614 if(!method_exists($x, 'checkOpts')){
617 $x->checkOpts($opts);
621 static function jsonImportFromArray($opts)
623 foreach($opts as $o=>$v) {
624 if (!preg_match('/^json-/', $o) || empty($v)) {
627 $type = str_replace('_', '-', substr($o,5));
629 $data= json_decode(file_get_contents($v),true);
630 $pg = HTML_FlexyFramework::get()->page;
631 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
641 function runUpdateModulesData()
643 if (class_exists('PDO_DataObjects_Introspection')) {
644 PDO_DataObject_Introspection::$cache = array();
646 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
648 if(!in_array('Core', $this->disabled)){
649 echo "Running jsonImportFromArray\n";
650 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
653 echo "Running updateData on modules\n";
659 $modules = array_reverse($this->modulesList());
661 // move 'project' one to the end...
663 foreach ($modules as $module){
664 if(in_array($module, $this->disabled)){
667 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
668 if($module == 'Core' || !file_exists($file)){
673 $class = "Pman_{$module}_UpdateDatabase";
675 if(!method_exists($x, 'updateData')){
685 function updateDataEnums()
688 $enum = DB_DataObject::Factory('core_enum');
689 //DB_DAtaObject::debugLevel(1);
694 'name' => 'COMPTYPE',
695 'display_name' => 'Company Types',
696 'is_system_enum' => 1,
700 'display_name' => 'Owner',
701 'seqid' => 999, // last...
702 'is_system_enum' => 1,
709 'name' => 'HtmlEditor.font-family',
710 'display_name' => 'HTML Editor font families',
711 'is_system_enum' => 1,
714 'name' => 'Helvetica,Arial,sans-serif',
715 'display_name' => 'Helvetica',
720 'name' => 'Courier New',
721 'display_name' => 'Courier',
726 'display_name' => 'Tahoma',
730 'name' => 'Times New Roman,serif',
731 'display_name' => 'Times',
736 'display_name' => 'Verdana',
748 function updateDataGroups()
751 $groups = DB_DataObject::factory('core_group');
752 $groups->initGroups();
754 $groups->initDatabase($this,array(
756 'name' => 'bcc-email', // group who are bcc'ed on all requests.
757 'type' => 0, // system
760 'name' => 'system-email-from',
761 'type' => 0, // system
764 'name' => 'core-person-signup-bcc',
765 'type' => 0, // system
771 function updateDataCompanies()
774 // fix comptypes enums..
775 $c = DB_DataObject::Factory('core_company');
777 $c->selectAdd('distinct(comptype) as comptype');
778 $c->whereAdd("comptype != ''");
781 foreach($c->fetchAll('comptype') as $cts) {
785 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
788 $c = DB_DataObject::Factory('core_enum');
791 //DB_DataObject::debugLevel(1);
793 $c = DB_DataObject::Factory('core_company');
795 UPDATE {$c->tableName()}
797 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
811 function initEmails($templateDir, $emails)
814 $pg = HTML_FlexyFramework::get()->page;
815 foreach($emails as $name=>$data) {
816 $cm = DB_DataObject::factory('core_email');
817 $update = $cm->get('name', $name);
820 if (empty($cm->bcc_group)) {
821 if (empty($data['bcc_group'])) {
822 $this->jerr("missing bcc_group for template $name");
824 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
827 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
831 if (!$g->members('email')) {
832 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
835 $cm->bcc_group = $g->id;
837 if (empty($cm->test_class)) {
838 if (empty($data['test_class'])) {
839 $this->jerr("missing test_class for template $name");
841 $cm->test_class = $data['test_class'];
843 require_once $cm->test_class . '.php';
845 $clsname = str_replace('/','_', $cm->test_class);
847 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
848 $got_it = $method->isStatic();
849 } catch(Exception $e) {
854 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
858 echo "email: {$name} - checked\n";
859 continue; /// we do not import the body content of templates that exist...
866 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
870 'file' => $templateDir. $name .'.html'
873 if (!empty($data['master'])) {
874 $opts['master'] = $templateDir . $master .'.html';
876 require_once 'Pman/Core/Import/Core_email.php';
877 $x = new Pman_Core_Import_Core_email();
878 $x->updateOrCreateEmail('', $opts, $cm);
880 echo "email: {$name} - CREATED\n";
885 function updateData()
888 if (class_exists('PDO_DataObjects_Introspection')) {
889 PDO_DataObject_Introspection::$cache = array();
891 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
892 $this->updateDataEnums();
893 $this->updateDataGroups();
894 $this->updateDataCompanies();
896 $c = DB_DataObject::Factory('I18n');
904 function fixMysqlInnodb()
907 static $done_check = false;
911 // innodb in single files is far more efficient that MYD or one big innodb file.
912 // first check if database is using this format.
913 $db = DB_DataObject::factory('core_enum');
914 $db->query("show variables like 'innodb_file_per_table'");
916 if ($db->Value == 'OFF') {
917 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
920 $db = DB_DataObject::factory('core_enum');
921 $db->query("select version() as version");
924 if (version_compare($db->version, '5.7', '>=' )) {
926 $db = DB_DataObject::factory('core_enum');
927 $db->query("show variables like 'sql_mode'");
930 $modes = explode(",", $db->Value);
932 // these are 'new' problems with mysql.
934 in_array('NO_ZERO_IN_DATE', $modes) ||
935 in_array('NO_ZERO_DATE', $modes) ||
936 in_array('STRICT_TRANS_TABLES', $modes) ||
937 !in_array('ALLOW_INVALID_DATES', $modes)
939 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");
954 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
956 function fixSequencesMysql()
961 function fixSequencesPgsql()
965 //DB_DataObject::debugLevel(1);
966 $cs = DB_DataObject::factory('core_enum');
970 CASE WHEN strpos(seq_name, '.') > 0 THEN
973 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
976 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
977 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
981 n.nspname AS schema_name,
982 c.relname AS table_name,
983 a.attname AS column_name,
984 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
986 JOIN pg_attribute a ON (c.oid=a.attrelid)
987 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
988 JOIN pg_namespace n ON (c.relnamespace=n.oid)
989 WHERE has_schema_privilege(n.oid,'USAGE')
990 AND n.nspname NOT LIKE 'pg!_%' escape '!'
991 AND has_table_privilege(c.oid,'SELECT')
992 AND (NOT a.attisdropped)
993 AND d.adsrc ~ '^nextval'
997 CASE WHEN strpos(seq_name, '.') > 0 THEN
998 substring(seq_name, 1,strpos(seq_name,'.')-1)
1003 GROUP BY seq_name HAVING count(*)=1
1006 while ($cs->fetch()) {
1009 foreach($cmds as $cmd) {
1010 $cs = DB_DataObject::factory('core_enum');
1014 $cs = DB_DataObject::factory('core_enum');
1016 SELECT 'SELECT SETVAL(' ||
1017 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1018 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1024 WHERE S.relkind = 'S'
1026 AND D.refobjid = T.oid
1027 AND D.refobjid = C.attrelid
1028 AND D.refobjsubid = C.attnum
1029 AND NS.oid = T.relnamespace
1033 while ($cs->fetch()) {
1036 foreach($cmds as $cmd) {
1037 $cs = DB_DataObject::factory('core_enum');
1044 var $extensions = array(
1049 function runExtensions()
1052 $ff = HTML_Flexyframework::get();
1054 $dburl = parse_url($ff->database);
1056 $dbtype = $dburl['scheme'];
1058 foreach($this->extensions as $ext) {
1060 $scls = ucfirst($dbtype). $ext;
1061 $cls = __CLASS__ . '_'. $scls;
1062 $fn = implode('/',explode('_', $cls)).'.php';
1063 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1074 function checkSystem()
1076 // most of these are from File_Convert...
1078 // these are required - and have simple dependancies.
1079 require_once 'System.php';
1085 'rsvg-convert', //librsvg2-bin
1091 // these are prefered - but may have complicated depenacies
1096 'html2text', // not availabe in debian squeeze
1097 'pdftocairo', //poppler-utils - not available in debian squeeze.
1107 foreach($req as $r) {
1108 if (!System::which($r)) {
1114 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1116 foreach($pref as $r) {
1117 if (!System::which($r)) {
1123 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1130 function generateDataobjectsCache()
1132 $url = "http://localhost{$this->local_base_url}/Roo/Core/RefreshDatabaseCache";
1134 $response = $this->curl($url);
1137 print_r($response);exit;
1140 function curl($url, $request = array(), $method = 'GET')
1142 if($method == 'GET'){
1143 $request = http_build_query($request);
1144 $url = $url . "?" . $request;
1147 $ch = curl_init($url);
1149 if ($method == 'POST') {
1151 curl_setopt($ch, CURLOPT_POST, 1);
1152 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1156 curl_setopt($ch, CURLOPT_HTTPHEADER,
1157 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1161 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1163 curl_setopt($ch, CURLOPT_HEADER, false);
1164 curl_setopt($ch, CURLOPT_VERBOSE, 1);
1165 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1166 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1168 $response = curl_exec($ch);