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'])) {
183 $this->runUpdateModulesData();
186 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
187 // make sure we have a good cache...?
189 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
192 $this->runExtensions();
194 // $this->generateDataobjectsCache();
202 * imports SQL files from all DataObjects directories....
204 * except any matching /migrate/
209 // loop through all the modules, and see if they have a importSQL method?
212 $ff = HTML_Flexyframework::get();
214 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
216 //$this->{'import' . $url['scheme']}($url);
218 $dbtype = $dburl['scheme'];
221 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
226 $ar = $this->modulesList();
231 if(in_array($m, $this->disabled)){
232 echo "module $m is disabled \n";
236 echo "Importing SQL from module $m\n";
237 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
242 // check to see if the class has
246 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
247 if($m != 'Core' && file_exists($file)){
250 $class = "Pman_{$m}_UpdateDatabase";
252 if(method_exists($x, 'importModuleSQL')){
253 echo "Importing SQL from module $m using Module::importModuleSQL\n";
254 $x->opts = $this->opts;
255 $x->rootDir = $this->rootDir;
256 $x->importModuleSQL($dburl);
261 echo "Importing SQL from module $m\n";
264 // if init has been called
266 if (!empty($this->opts['init'])) {
267 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
273 $fd = $this->rootDir. "/Pman/$m/DataObjects";
275 $this->{$dirmethod}($dburl, $fd);
278 // new -- sql directory..
279 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
280 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
282 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
283 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
287 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
288 if (class_exists('PDO_DataObjects_Introspection')) {
289 PDO_DataObject_Introspection::$cache = array();
291 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
293 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
294 $this->{'fixSequences'. $dbtype}();
307 /** -------------- code to handle importing a whole directory of files into the database ------- **/
310 function importpgsqldir($url, $dir, $disable_triggers = false)
312 $ff = HTML_FlexyFramework::get();
314 require_once 'System.php';
315 $cat = System::which('cat');
316 $psql = System::which('psql');
319 if (!empty($url['pass'])) {
320 putenv("PGPASSWORD=". $url['pass']);
324 ' -h ' . $url['host'] .
325 ' -U' . escapeshellarg($url['user']) .
326 ' ' . basename($url['path']);
329 echo $psql_cmd . "\n" ;
330 echo "scan : $dir\n";
333 $files = array($dir);
338 $files = glob($dir.'/*.sql');
339 uksort($files, 'strcasecmp');
341 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
342 //usort($files, $lsort);
345 foreach($files as $bfn) {
348 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
351 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
352 && !preg_match('#\.pg\.sql#i', basename($bfn))
353 ) { // skip migration scripts at present..
358 if (!preg_match('/pgsql/', basename($dir) )) {
359 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
360 $fn = $this->convertToPG($bfn);
364 // files ending in .pg.sql are native postgres files.. ## depricated
367 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
369 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
385 * mysql - does not support conversions.
389 function importmysqlidir($dburl, $dir) {
390 return $this->importmysqldir($dburl, $dir);
393 function importmysqldir($dburl, $dir)
396 $this->fixMysqlInnodb(); /// run once
398 echo "Import MYSQL :: $dir\n";
401 require_once 'System.php';
402 $cat = System::which('cat');
403 $mysql = System::which('mysql');
407 $mysql_cmd = $mysql .
408 ' -h ' . $dburl['host'] .
409 ' -u' . escapeshellarg($dburl['user']) .
410 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
411 ' ' . basename($dburl['path']);
412 //echo $mysql_cmd . "\n" ;
414 $files = glob($dir.'/*.sql');
415 uksort($files, 'strcasecmp');
418 foreach($files as $fn) {
421 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
424 // .my.sql but not .pg.sql
425 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
426 && !preg_match('#\.my\.sql#i', basename($fn))
427 ) { // skip migration scripts at present..
430 if (!strlen(trim($fn))) {
434 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
436 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
439 $fp = popen($cmd, "r");
442 // send the current file part to the browser
443 $line = trim(fgets($fp, 1024));
448 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
449 echo " ---- {$line}\n"; flush();
453 switch($matches[1]) {
454 case 1017: // cause by renaming table -- old one does not exist..
455 case 1050: // create tables triggers this..
456 case 1060: // Duplicate column name
457 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
458 case 1091: // drop index -- name does not exist.. might hide errors..
460 case 1146: // drop a index on an unknown table.. - happens rarely...
461 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
467 echo " ---- {$line}\n"; flush();
471 // 1051: // Unknown table -- normally drop = add iff exists..
472 echo "File: $fn\n$line\n";
488 * simple regex based convert mysql to pgsql...
490 function convertToPG($src)
492 //echo "Convert $src\n";
494 $fn = $this->tempName('sql');
496 $ret = array( ); // pad it a bit.
497 $extra = array("", "" );
500 foreach(file($src) as $l) {
503 if (!strlen($l) || $l[0] == '#') {
507 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
510 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
511 $tbl = 'shop_' . strtolower($m[1]);
512 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
514 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
515 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
518 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
519 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
520 $extra[] = "create sequence {$tbl}_seq;";
524 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
525 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
528 // enum value -- use the text instead..
530 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
531 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
533 // ignore the alter enum
534 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
538 // UNIQUE KEY .. ignore
539 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
540 $last = array_pop($ret);
541 $ret[] = trim($last, ",");
545 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
549 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
553 // INDEX lookup ..ignore
554 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
555 $last = array_pop($ret);
556 $ret[] = trim($last, ",");
561 // CREATE INDEX ..ignore
562 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
563 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
568 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
570 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
571 $l = preg_replace('# blob#i', ' TEXT', $l);
572 $l = preg_replace('# longtext#i', ' TEXT', $l);
573 $l = preg_replace('# tinyint#i', ' INT', $l);
579 $ret = array_merge($extra,$ret);
580 // echo implode("\n", $ret); exit;
582 file_put_contents($fn, implode("\n", $ret));
588 function checkOpts($opts)
592 foreach($opts as $o=>$v) {
593 if (!preg_match('/^json-/', $o) || empty($v)) {
596 if (!file_exists($v)) {
597 die("File does not exist : OPTION --{$o} = {$v} \n");
601 $modules = array_reverse($this->modulesList());
603 // move 'project' one to the end...
605 foreach ($modules as $module){
606 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
607 if($module == 'Core' || !file_exists($file)){
611 $class = "Pman_{$module}_UpdateDatabase";
613 if(!method_exists($x, 'checkOpts')){
616 $x->checkOpts($opts);
620 static function jsonImportFromArray($opts)
622 foreach($opts as $o=>$v) {
623 if (!preg_match('/^json-/', $o) || empty($v)) {
626 $type = str_replace('_', '-', substr($o,5));
628 $data= json_decode(file_get_contents($v),true);
629 $pg = HTML_FlexyFramework::get()->page;
630 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
640 function runUpdateModulesData()
642 if (class_exists('PDO_DataObjects_Introspection')) {
643 PDO_DataObject_Introspection::$cache = array();
645 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
647 if(!in_array('Core', $this->disabled)){
648 echo "Running jsonImportFromArray\n";
649 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
652 echo "Running updateData on modules\n";
658 $modules = array_reverse($this->modulesList());
660 // move 'project' one to the end...
662 foreach ($modules as $module){
663 if(in_array($module, $this->disabled)){
666 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
667 if($module == 'Core' || !file_exists($file)){
672 $class = "Pman_{$module}_UpdateDatabase";
674 if(!method_exists($x, 'updateData')){
684 function updateDataEnums()
687 $enum = DB_DataObject::Factory('core_enum');
688 //DB_DAtaObject::debugLevel(1);
693 'name' => 'COMPTYPE',
694 'display_name' => 'Company Types',
695 'is_system_enum' => 1,
699 'display_name' => 'Owner',
700 'seqid' => 999, // last...
701 'is_system_enum' => 1,
708 'name' => 'HtmlEditor.font-family',
709 'display_name' => 'HTML Editor font families',
710 'is_system_enum' => 1,
713 'name' => 'Helvetica,Arial,sans-serif',
714 'display_name' => 'Helvetica',
719 'name' => 'Courier New',
720 'display_name' => 'Courier',
725 'display_name' => 'Tahoma',
729 'name' => 'Times New Roman,serif',
730 'display_name' => 'Times',
735 'display_name' => 'Verdana',
747 function updateDataGroups()
750 $groups = DB_DataObject::factory('core_group');
751 $groups->initGroups();
753 $groups->initDatabase($this,array(
755 'name' => 'bcc-email', // group who are bcc'ed on all requests.
756 'type' => 0, // system
759 'name' => 'system-email-from',
760 'type' => 0, // system
763 'name' => 'core-person-signup-bcc',
764 'type' => 0, // system
770 function updateDataCompanies()
773 // fix comptypes enums..
774 $c = DB_DataObject::Factory('core_company');
776 $c->selectAdd('distinct(comptype) as comptype');
777 $c->whereAdd("comptype != ''");
780 foreach($c->fetchAll('comptype') as $cts) {
784 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
787 $c = DB_DataObject::Factory('core_enum');
790 //DB_DataObject::debugLevel(1);
792 $c = DB_DataObject::Factory('core_company');
794 UPDATE {$c->tableName()}
796 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
810 function initEmails($templateDir, $emails)
813 $pg = HTML_FlexyFramework::get()->page;
814 foreach($emails as $name=>$data) {
815 $cm = DB_DataObject::factory('core_email');
816 $update = $cm->get('name', $name);
819 if (empty($cm->bcc_group)) {
820 if (empty($data['bcc_group'])) {
821 $this->jerr("missing bcc_group for template $name");
823 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
826 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
830 if (!$g->members('email')) {
831 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
834 $cm->bcc_group = $g->id;
836 if (empty($cm->test_class)) {
837 if (empty($data['test_class'])) {
838 $this->jerr("missing test_class for template $name");
840 $cm->test_class = $data['test_class'];
842 require_once $cm->test_class . '.php';
844 $clsname = str_replace('/','_', $cm->test_class);
846 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
847 $got_it = $method->isStatic();
848 } catch(Exception $e) {
853 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
857 echo "email: {$name} - checked\n";
858 continue; /// we do not import the body content of templates that exist...
865 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
869 'file' => $templateDir. $name .'.html'
872 if (!empty($data['master'])) {
873 $opts['master'] = $templateDir . $master .'.html';
875 require_once 'Pman/Core/Import/Core_email.php';
876 $x = new Pman_Core_Import_Core_email();
877 $x->updateOrCreateEmail('', $opts, $cm);
879 echo "email: {$name} - CREATED\n";
884 function updateData()
887 if (class_exists('PDO_DataObjects_Introspection')) {
888 PDO_DataObject_Introspection::$cache = array();
890 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
891 $this->updateDataEnums();
892 $this->updateDataGroups();
893 $this->updateDataCompanies();
895 $c = DB_DataObject::Factory('I18n');
903 function fixMysqlInnodb()
906 static $done_check = false;
910 // innodb in single files is far more efficient that MYD or one big innodb file.
911 // first check if database is using this format.
912 $db = DB_DataObject::factory('core_enum');
913 $db->query("show variables like 'innodb_file_per_table'");
915 if ($db->Value == 'OFF') {
916 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
919 $db = DB_DataObject::factory('core_enum');
920 $db->query("select version() as version");
923 if (version_compare($db->version, '5.7', '>=' )) {
925 $db = DB_DataObject::factory('core_enum');
926 $db->query("show variables like 'sql_mode'");
929 $modes = explode(",", $db->Value);
931 // these are 'new' problems with mysql.
933 in_array('NO_ZERO_IN_DATE', $modes) ||
934 in_array('NO_ZERO_DATE', $modes) ||
935 in_array('STRICT_TRANS_TABLES', $modes) ||
936 !in_array('ALLOW_INVALID_DATES', $modes)
938 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");
953 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
955 function fixSequencesMysql()
960 function fixSequencesPgsql()
964 //DB_DataObject::debugLevel(1);
965 $cs = DB_DataObject::factory('core_enum');
969 CASE WHEN strpos(seq_name, '.') > 0 THEN
972 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
975 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
976 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
980 n.nspname AS schema_name,
981 c.relname AS table_name,
982 a.attname AS column_name,
983 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
985 JOIN pg_attribute a ON (c.oid=a.attrelid)
986 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
987 JOIN pg_namespace n ON (c.relnamespace=n.oid)
988 WHERE has_schema_privilege(n.oid,'USAGE')
989 AND n.nspname NOT LIKE 'pg!_%' escape '!'
990 AND has_table_privilege(c.oid,'SELECT')
991 AND (NOT a.attisdropped)
992 AND d.adsrc ~ '^nextval'
996 CASE WHEN strpos(seq_name, '.') > 0 THEN
997 substring(seq_name, 1,strpos(seq_name,'.')-1)
1002 GROUP BY seq_name HAVING count(*)=1
1005 while ($cs->fetch()) {
1008 foreach($cmds as $cmd) {
1009 $cs = DB_DataObject::factory('core_enum');
1013 $cs = DB_DataObject::factory('core_enum');
1015 SELECT 'SELECT SETVAL(' ||
1016 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1017 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1023 WHERE S.relkind = 'S'
1025 AND D.refobjid = T.oid
1026 AND D.refobjid = C.attrelid
1027 AND D.refobjsubid = C.attnum
1028 AND NS.oid = T.relnamespace
1032 while ($cs->fetch()) {
1035 foreach($cmds as $cmd) {
1036 $cs = DB_DataObject::factory('core_enum');
1043 var $extensions = array(
1048 function runExtensions()
1051 $ff = HTML_Flexyframework::get();
1053 $dburl = parse_url($ff->database);
1055 $dbtype = $dburl['scheme'];
1057 foreach($this->extensions as $ext) {
1059 $scls = ucfirst($dbtype). $ext;
1060 $cls = __CLASS__ . '_'. $scls;
1061 $fn = implode('/',explode('_', $cls)).'.php';
1062 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1073 function checkSystem()
1075 // most of these are from File_Convert...
1077 // these are required - and have simple dependancies.
1078 require_once 'System.php';
1084 'rsvg-convert', //librsvg2-bin
1090 // these are prefered - but may have complicated depenacies
1095 'html2text', // not availabe in debian squeeze
1096 'pdftocairo', //poppler-utils - not available in debian squeeze.
1106 foreach($req as $r) {
1107 if (!System::which($r)) {
1113 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1115 foreach($pref as $r) {
1116 if (!System::which($r)) {
1122 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1129 // function generateDataobjectsCache()
1131 // $url = "http://localhost{$this->local_base_url}/Roo/SaveDocuments";
1133 // $this->curl($url, array(
1134 // 'onid' => $coba_declarations->id,
1135 // 'ontable' => $coba_declarations->tableName(),
1136 // 'method' => 'forms',
1141 function curl($url, $request = array(), $method = 'GET')
1143 if(is_array($request)){
1144 $request = http_build_query($request);
1147 $url = $url . ($method == 'GET' ? "?" . $request : '');
1149 $ch = curl_init($url);
1151 if ($method == 'POST') {
1152 curl_setopt($ch, CURLOPT_POST, 1);
1153 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1154 curl_setopt($ch, CURLOPT_HTTPHEADER,
1155 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1158 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1160 curl_setopt($ch, CURLOPT_HEADER, false);
1161 curl_setopt($ch, CURLOPT_VERBOSE, 1);
1162 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1163 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1165 $response = curl_exec($ch);