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();
185 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
186 // make sure we have a good cache...?
188 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
191 $this->runExtensions();
193 $this->generateDataobjectsCache();
201 * imports SQL files from all DataObjects directories....
203 * except any matching /migrate/
208 // loop through all the modules, and see if they have a importSQL method?
211 $ff = HTML_Flexyframework::get();
213 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
215 //$this->{'import' . $url['scheme']}($url);
217 $dbtype = $dburl['scheme'];
220 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
225 $ar = $this->modulesList();
230 if(in_array($m, $this->disabled)){
231 echo "module $m is disabled \n";
235 echo "Importing SQL from module $m\n";
236 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
241 // check to see if the class has
245 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
246 if($m != 'Core' && file_exists($file)){
249 $class = "Pman_{$m}_UpdateDatabase";
251 if(method_exists($x, 'importModuleSQL')){
252 echo "Importing SQL from module $m using Module::importModuleSQL\n";
253 $x->opts = $this->opts;
254 $x->rootDir = $this->rootDir;
255 $x->importModuleSQL($dburl);
260 echo "Importing SQL from module $m\n";
263 // if init has been called
265 if (!empty($this->opts['init'])) {
266 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
272 $fd = $this->rootDir. "/Pman/$m/DataObjects";
274 $this->{$dirmethod}($dburl, $fd);
277 // new -- sql directory..
278 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
279 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
281 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
282 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
286 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
287 if (class_exists('PDO_DataObjects_Introspection')) {
288 PDO_DataObject_Introspection::$cache = array();
290 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
292 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
293 $this->{'fixSequences'. $dbtype}();
306 /** -------------- code to handle importing a whole directory of files into the database ------- **/
309 function importpgsqldir($url, $dir, $disable_triggers = false)
311 $ff = HTML_FlexyFramework::get();
313 require_once 'System.php';
314 $cat = System::which('cat');
315 $psql = System::which('psql');
318 if (!empty($url['pass'])) {
319 putenv("PGPASSWORD=". $url['pass']);
323 ' -h ' . $url['host'] .
324 ' -U' . escapeshellarg($url['user']) .
325 ' ' . basename($url['path']);
328 echo $psql_cmd . "\n" ;
329 echo "scan : $dir\n";
332 $files = array($dir);
337 $files = glob($dir.'/*.sql');
338 uksort($files, 'strcasecmp');
340 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
341 //usort($files, $lsort);
344 foreach($files as $bfn) {
347 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
350 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
351 && !preg_match('#\.pg\.sql#i', basename($bfn))
352 ) { // skip migration scripts at present..
357 if (!preg_match('/pgsql/', basename($dir) )) {
358 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
359 $fn = $this->convertToPG($bfn);
363 // files ending in .pg.sql are native postgres files.. ## depricated
366 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
368 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
384 * mysql - does not support conversions.
388 function importmysqlidir($dburl, $dir) {
389 return $this->importmysqldir($dburl, $dir);
392 function importmysqldir($dburl, $dir)
395 $this->fixMysqlInnodb(); /// run once
397 echo "Import MYSQL :: $dir\n";
400 require_once 'System.php';
401 $cat = System::which('cat');
402 $mysql = System::which('mysql');
406 $mysql_cmd = $mysql .
407 ' -h ' . $dburl['host'] .
408 ' -u' . escapeshellarg($dburl['user']) .
409 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
410 ' ' . basename($dburl['path']);
411 //echo $mysql_cmd . "\n" ;
413 $files = glob($dir.'/*.sql');
414 uksort($files, 'strcasecmp');
417 foreach($files as $fn) {
420 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
423 // .my.sql but not .pg.sql
424 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
425 && !preg_match('#\.my\.sql#i', basename($fn))
426 ) { // skip migration scripts at present..
429 if (!strlen(trim($fn))) {
433 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
435 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
438 $fp = popen($cmd, "r");
441 // send the current file part to the browser
442 $line = trim(fgets($fp, 1024));
447 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
448 echo " ---- {$line}\n"; flush();
452 switch($matches[1]) {
453 case 1017: // cause by renaming table -- old one does not exist..
454 case 1050: // create tables triggers this..
455 case 1060: // Duplicate column name
456 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
457 case 1091: // drop index -- name does not exist.. might hide errors..
459 case 1146: // drop a index on an unknown table.. - happens rarely...
460 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
466 echo " ---- {$line}\n"; flush();
470 // 1051: // Unknown table -- normally drop = add iff exists..
471 echo "File: $fn\n$line\n";
487 * simple regex based convert mysql to pgsql...
489 function convertToPG($src)
491 //echo "Convert $src\n";
493 $fn = $this->tempName('sql');
495 $ret = array( ); // pad it a bit.
496 $extra = array("", "" );
499 foreach(file($src) as $l) {
502 if (!strlen($l) || $l[0] == '#') {
506 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
509 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
510 $tbl = 'shop_' . strtolower($m[1]);
511 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
513 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
514 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
517 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
518 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
519 $extra[] = "create sequence {$tbl}_seq;";
523 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
524 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
527 // enum value -- use the text instead..
529 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
530 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
532 // ignore the alter enum
533 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
537 // UNIQUE KEY .. ignore
538 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
539 $last = array_pop($ret);
540 $ret[] = trim($last, ",");
544 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
548 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
552 // INDEX lookup ..ignore
553 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
554 $last = array_pop($ret);
555 $ret[] = trim($last, ",");
560 // CREATE INDEX ..ignore
561 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
562 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
567 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
569 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
570 $l = preg_replace('# blob#i', ' TEXT', $l);
571 $l = preg_replace('# longtext#i', ' TEXT', $l);
572 $l = preg_replace('# tinyint#i', ' INT', $l);
578 $ret = array_merge($extra,$ret);
579 // echo implode("\n", $ret); exit;
581 file_put_contents($fn, implode("\n", $ret));
587 function checkOpts($opts)
591 foreach($opts as $o=>$v) {
592 if (!preg_match('/^json-/', $o) || empty($v)) {
595 if (!file_exists($v)) {
596 die("File does not exist : OPTION --{$o} = {$v} \n");
600 $modules = array_reverse($this->modulesList());
602 // move 'project' one to the end...
604 foreach ($modules as $module){
605 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
606 if($module == 'Core' || !file_exists($file)){
610 $class = "Pman_{$module}_UpdateDatabase";
612 if(!method_exists($x, 'checkOpts')){
615 $x->checkOpts($opts);
619 static function jsonImportFromArray($opts)
621 foreach($opts as $o=>$v) {
622 if (!preg_match('/^json-/', $o) || empty($v)) {
625 $type = str_replace('_', '-', substr($o,5));
627 $data= json_decode(file_get_contents($v),true);
628 $pg = HTML_FlexyFramework::get()->page;
629 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
639 function runUpdateModulesData()
641 if (class_exists('PDO_DataObjects_Introspection')) {
642 PDO_DataObject_Introspection::$cache = array();
644 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
646 if(!in_array('Core', $this->disabled)){
647 echo "Running jsonImportFromArray\n";
648 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
651 echo "Running updateData on modules\n";
657 $modules = array_reverse($this->modulesList());
659 // move 'project' one to the end...
661 foreach ($modules as $module){
662 if(in_array($module, $this->disabled)){
665 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
666 if($module == 'Core' || !file_exists($file)){
671 $class = "Pman_{$module}_UpdateDatabase";
673 if(!method_exists($x, 'updateData')){
683 function updateDataEnums()
686 $enum = DB_DataObject::Factory('core_enum');
687 //DB_DAtaObject::debugLevel(1);
692 'name' => 'COMPTYPE',
693 'display_name' => 'Company Types',
694 'is_system_enum' => 1,
698 'display_name' => 'Owner',
699 'seqid' => 999, // last...
700 'is_system_enum' => 1,
707 'name' => 'HtmlEditor.font-family',
708 'display_name' => 'HTML Editor font families',
709 'is_system_enum' => 1,
712 'name' => 'Helvetica,Arial,sans-serif',
713 'display_name' => 'Helvetica',
718 'name' => 'Courier New',
719 'display_name' => 'Courier',
724 'display_name' => 'Tahoma',
728 'name' => 'Times New Roman,serif',
729 'display_name' => 'Times',
734 'display_name' => 'Verdana',
746 function updateDataGroups()
749 $groups = DB_DataObject::factory('core_group');
750 $groups->initGroups();
752 $groups->initDatabase($this,array(
754 'name' => 'bcc-email', // group who are bcc'ed on all requests.
755 'type' => 0, // system
758 'name' => 'system-email-from',
759 'type' => 0, // system
762 'name' => 'core-person-signup-bcc',
763 'type' => 0, // system
769 function updateDataCompanies()
772 // fix comptypes enums..
773 $c = DB_DataObject::Factory('core_company');
775 $c->selectAdd('distinct(comptype) as comptype');
776 $c->whereAdd("comptype != ''");
779 foreach($c->fetchAll('comptype') as $cts) {
783 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
786 $c = DB_DataObject::Factory('core_enum');
789 //DB_DataObject::debugLevel(1);
791 $c = DB_DataObject::Factory('core_company');
793 UPDATE {$c->tableName()}
795 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
809 function initEmails($templateDir, $emails)
812 $pg = HTML_FlexyFramework::get()->page;
813 foreach($emails as $name=>$data) {
814 $cm = DB_DataObject::factory('core_email');
815 $update = $cm->get('name', $name);
818 if (empty($cm->bcc_group)) {
819 if (empty($data['bcc_group'])) {
820 $this->jerr("missing bcc_group for template $name");
822 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
825 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
829 if (!$g->members('email')) {
830 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
833 $cm->bcc_group = $g->id;
835 if (empty($cm->test_class)) {
836 if (empty($data['test_class'])) {
837 $this->jerr("missing test_class for template $name");
839 $cm->test_class = $data['test_class'];
841 require_once $cm->test_class . '.php';
843 $clsname = str_replace('/','_', $cm->test_class);
845 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
846 $got_it = $method->isStatic();
847 } catch(Exception $e) {
852 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
856 echo "email: {$name} - checked\n";
857 continue; /// we do not import the body content of templates that exist...
864 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
868 'file' => $templateDir. $name .'.html'
871 if (!empty($data['master'])) {
872 $opts['master'] = $templateDir . $master .'.html';
874 require_once 'Pman/Core/Import/Core_email.php';
875 $x = new Pman_Core_Import_Core_email();
876 $x->updateOrCreateEmail('', $opts, $cm);
878 echo "email: {$name} - CREATED\n";
883 function updateData()
886 if (class_exists('PDO_DataObjects_Introspection')) {
887 PDO_DataObject_Introspection::$cache = array();
889 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
890 $this->updateDataEnums();
891 $this->updateDataGroups();
892 $this->updateDataCompanies();
894 $c = DB_DataObject::Factory('I18n');
902 function fixMysqlInnodb()
905 static $done_check = false;
909 // innodb in single files is far more efficient that MYD or one big innodb file.
910 // first check if database is using this format.
911 $db = DB_DataObject::factory('core_enum');
912 $db->query("show variables like 'innodb_file_per_table'");
914 if ($db->Value == 'OFF') {
915 die("Error: set innodb_file_per_table = 1 in my.cnf\n\n");
918 $db = DB_DataObject::factory('core_enum');
919 $db->query("select version() as version");
922 if (version_compare($db->version, '5.7', '>=' )) {
924 $db = DB_DataObject::factory('core_enum');
925 $db->query("show variables like 'sql_mode'");
928 $modes = explode(",", $db->Value);
930 // these are 'new' problems with mysql.
932 in_array('NO_ZERO_IN_DATE', $modes) ||
933 in_array('NO_ZERO_DATE', $modes) ||
934 in_array('STRICT_TRANS_TABLES', $modes) ||
935 !in_array('ALLOW_INVALID_DATES', $modes)
937 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");
952 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
954 function fixSequencesMysql()
959 function fixSequencesPgsql()
963 //DB_DataObject::debugLevel(1);
964 $cs = DB_DataObject::factory('core_enum');
968 CASE WHEN strpos(seq_name, '.') > 0 THEN
971 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
974 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
975 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
979 n.nspname AS schema_name,
980 c.relname AS table_name,
981 a.attname AS column_name,
982 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
984 JOIN pg_attribute a ON (c.oid=a.attrelid)
985 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
986 JOIN pg_namespace n ON (c.relnamespace=n.oid)
987 WHERE has_schema_privilege(n.oid,'USAGE')
988 AND n.nspname NOT LIKE 'pg!_%' escape '!'
989 AND has_table_privilege(c.oid,'SELECT')
990 AND (NOT a.attisdropped)
991 AND d.adsrc ~ '^nextval'
995 CASE WHEN strpos(seq_name, '.') > 0 THEN
996 substring(seq_name, 1,strpos(seq_name,'.')-1)
1001 GROUP BY seq_name HAVING count(*)=1
1004 while ($cs->fetch()) {
1007 foreach($cmds as $cmd) {
1008 $cs = DB_DataObject::factory('core_enum');
1012 $cs = DB_DataObject::factory('core_enum');
1014 SELECT 'SELECT SETVAL(' ||
1015 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1016 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1022 WHERE S.relkind = 'S'
1024 AND D.refobjid = T.oid
1025 AND D.refobjid = C.attrelid
1026 AND D.refobjsubid = C.attnum
1027 AND NS.oid = T.relnamespace
1031 while ($cs->fetch()) {
1034 foreach($cmds as $cmd) {
1035 $cs = DB_DataObject::factory('core_enum');
1042 var $extensions = array(
1047 function runExtensions()
1050 $ff = HTML_Flexyframework::get();
1052 $dburl = parse_url($ff->database);
1054 $dbtype = $dburl['scheme'];
1056 foreach($this->extensions as $ext) {
1058 $scls = ucfirst($dbtype). $ext;
1059 $cls = __CLASS__ . '_'. $scls;
1060 $fn = implode('/',explode('_', $cls)).'.php';
1061 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1072 function checkSystem()
1074 // most of these are from File_Convert...
1076 // these are required - and have simple dependancies.
1077 require_once 'System.php';
1083 'rsvg-convert', //librsvg2-bin
1089 // these are prefered - but may have complicated depenacies
1094 'html2text', // not availabe in debian squeeze
1095 'pdftocairo', //poppler-utils - not available in debian squeeze.
1105 foreach($req as $r) {
1106 if (!System::which($r)) {
1112 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1114 foreach($pref as $r) {
1115 if (!System::which($r)) {
1121 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1128 function generateDataobjectsCache()
1130 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1132 $response = $this->curl($url);
1135 print_r($response);exit;
1138 function curl($url, $request = array(), $method = 'GET')
1140 if($method == 'GET'){
1141 $request = http_build_query($request);
1142 $url = $url . "?" . $request;
1145 $ch = curl_init($url);
1147 if ($method == 'POST') {
1149 curl_setopt($ch, CURLOPT_POST, 1);
1150 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)));
1159 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1161 curl_setopt($ch, CURLOPT_HEADER, false);
1162 curl_setopt($ch, CURLOPT_VERBOSE, 1);
1163 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1164 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1166 $response = curl_exec($ch);