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',
86 static function cli_opts()
89 $ret = self::$cli_opts;
90 $ff = HTML_FlexyFramework::get();
92 $mods = $a->modulesList();
93 foreach($mods as $m) {
95 $fd = $ff->rootDir. "/Pman/$m/UpdateDatabase.php";
96 if (!file_exists($fd)) {
102 $cls = new ReflectionClass('Pman_'. $m . '_UpdateDatabase');
104 $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
113 var $disabled = array();
118 var $local_base_url = false;
123 $ff = HTML_FlexyFramework::get();
124 if (!empty($ff->cli)) {
129 parent::getAuth(); // load company!
130 $au = $this->getAuthUser();
131 if (!$au || $au->company()->comptype != 'OWNER') {
132 $this->jerr("Not authenticated", array('authFailure' => true));
134 $this->authUser = $au;
138 function get($args, $opts=array())
140 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
142 $this->checkSystem();
144 if (class_exists('PDO_DataObjects_Introspection')) {
145 PDO_DataObject_Introspection::$cache = array();
148 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
150 $ff = HTML_FlexyFramework::get();
152 if(!isset($ff->Pman) || !isset($ff->Pman['local_base_url'])){
153 die("Please setup local_base_url");
156 $this->local_base_url = $ff->Pman['local_base_url'];
158 if(!empty($ff->Core_Notify)){
159 // require_once 'Pman/Core/NotifySmtpCheck.php';
160 // $x = new Pman_Core_NotifySmtpCheck();
164 $this->disabled = explode(',', $ff->disable);
166 //$this->fixSequencesPgsql();exit;
169 // ask all the modules to verify the opts
171 $this->checkOpts($opts);
174 // do this first, so the innodb change + utf8 fixes column max sizes
176 // this will trigger errors about freetext indexes - we will have to remove them manually.?
177 // 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..)
179 $this->runExtensions();
182 if (empty($opts['data-only'])) {
185 if (!empty($opts['only-module-sql'])) {
189 $this->runUpdateModulesData();
191 if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
192 // make sure we have a good cache...?
194 DB_DataObject::factory('core_company')->initCompanies($this, $opts);
197 $this->runExtensions();
199 $this->generateDataobjectsCache();
207 * imports SQL files from all DataObjects directories....
209 * except any matching /migrate/
214 // loop through all the modules, and see if they have a importSQL method?
217 $ff = HTML_Flexyframework::get();
219 $dburl = parse_url($ff->database); // used to be DB_DataObject['database'] - but not portable to PDO
221 //$this->{'import' . $url['scheme']}($url);
223 $dbtype = $dburl['scheme'];
226 $dirmethod = 'import' . $dburl['scheme'] . 'dir';
231 $ar = $this->modulesList();
236 if(in_array($m, $this->disabled)){
237 echo "module $m is disabled \n";
241 echo "Importing SQL from module $m\n";
242 if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
247 // check to see if the class has
251 $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
252 if($m != 'Core' && file_exists($file)){
255 $class = "Pman_{$m}_UpdateDatabase";
257 if(method_exists($x, 'importModuleSQL')){
258 echo "Importing SQL from module $m using Module::importModuleSQL\n";
259 $x->opts = $this->opts;
260 $x->rootDir = $this->rootDir;
261 $x->importModuleSQL($dburl);
266 echo "Importing SQL from module $m\n";
269 // if init has been called
271 if (!empty($this->opts['init'])) {
272 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
278 $fd = $this->rootDir. "/Pman/$m/DataObjects";
280 $this->{$dirmethod}($dburl, $fd);
283 // new -- sql directory..
284 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
285 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
287 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
288 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
292 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
293 if (class_exists('PDO_DataObjects_Introspection')) {
294 PDO_DataObject_Introspection::$cache = array();
296 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
298 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
299 $this->{'fixSequences'. $dbtype}();
312 /** -------------- code to handle importing a whole directory of files into the database ------- **/
315 function importpgsqldir($url, $dir, $disable_triggers = false)
317 $ff = HTML_FlexyFramework::get();
319 require_once 'System.php';
320 $cat = System::which('cat');
321 $psql = System::which('psql');
324 if (!empty($url['pass'])) {
325 putenv("PGPASSWORD=". $url['pass']);
329 ' -h ' . $url['host'] .
330 ' -U' . escapeshellarg($url['user']) .
331 ' ' . basename($url['path']);
334 echo $psql_cmd . "\n" ;
335 echo "scan : $dir\n";
338 $files = array($dir);
343 $files = glob($dir.'/*.sql');
344 uksort($files, 'strcasecmp');
346 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
347 //usort($files, $lsort);
350 foreach($files as $bfn) {
353 if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
356 if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
357 && !preg_match('#\.pg\.sql#i', basename($bfn))
358 ) { // skip migration scripts at present..
363 if (!preg_match('/pgsql/', basename($dir) )) {
364 if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
365 $fn = $this->convertToPG($bfn);
369 // files ending in .pg.sql are native postgres files.. ## depricated
372 $cmd = "$psql_cmd < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
374 echo "$bfn: $cmd ". ($ff->cli ? "\n" : "<BR>\n");
390 * mysql - does not support conversions.
394 function importmysqlidir($dburl, $dir) {
395 return $this->importmysqldir($dburl, $dir);
398 function importmysqldir($dburl, $dir)
401 $this->fixMysqlInnodb(); /// run once
403 echo "Import MYSQL :: $dir\n";
406 require_once 'System.php';
407 $cat = System::which('cat');
408 $mysql = System::which('mysql');
412 $mysql_cmd = $mysql .
413 ' -h ' . $dburl['host'] .
414 ' -u' . escapeshellarg($dburl['user']) .
415 (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass']) : '') .
416 ' ' . basename($dburl['path']);
417 //echo $mysql_cmd . "\n" ;
419 $files = glob($dir.'/*.sql');
420 uksort($files, 'strcasecmp');
423 foreach($files as $fn) {
426 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
429 // .my.sql but not .pg.sql
430 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
431 && !preg_match('#\.my\.sql#i', basename($fn))
432 ) { // skip migration scripts at present..
435 if (!strlen(trim($fn))) {
439 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ." 2>&1" ;
441 echo basename($dir).'/'. basename($fn) . '::' . $cmd. ($this->cli ? "\n" : "<BR>\n");
444 $fp = popen($cmd, "r");
447 // send the current file part to the browser
448 $line = trim(fgets($fp, 1024));
453 if (!preg_match('/^ERROR\s+([0-9]+)/', $line, $matches)) {
454 echo " ---- {$line}\n"; flush();
458 switch($matches[1]) {
459 case 1017: // cause by renaming table -- old one does not exist..
460 case 1050: // create tables triggers this..
461 case 1060: // Duplicate column name
462 case 1061: // Duplicate key name - triggered by add index.. but could hide error. - unlikely though.
463 case 1091: // drop index -- name does not exist.. might hide errors..
465 case 1146: // drop a index on an unknown table.. - happens rarely...
466 case 1054: // Unknown column -- triggered by CHANGE COLUMN - but may hide other errrors..
472 echo " ---- {$line}\n"; flush();
476 // 1051: // Unknown table -- normally drop = add iff exists..
477 echo "File: $fn\n$line\n";
493 * simple regex based convert mysql to pgsql...
495 function convertToPG($src)
497 //echo "Convert $src\n";
499 $fn = $this->tempName('sql');
501 $ret = array( ); // pad it a bit.
502 $extra = array("", "" );
505 foreach(file($src) as $l) {
508 if (!strlen($l) || $l[0] == '#') {
512 if (preg_match('#create\s+table\s+([a-z0-9_]+)#i', $l, $m)) {
515 if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i', $l, $m)) {
516 $tbl = 'shop_' . strtolower($m[1]);
517 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
519 if (preg_match('#\`([a-z0-9_]+)\`#i', $l, $m) && !preg_match('#alter\s+table\s+#i', $l)) {
520 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
523 if ($tbl && preg_match('#auto_increment#i', $l, $m)) {
524 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
525 $extra[] = "create sequence {$tbl}_seq;";
529 if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', $l, $m)){
530 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
533 // enum value -- use the text instead..
535 if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i', $l, $m)) {
536 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
538 // ignore the alter enum
539 if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i', $l, $m)) {
543 // UNIQUE KEY .. ignore
544 if ($tbl && preg_match('#UNIQUE KEY#i', $l, $m)) {
545 $last = array_pop($ret);
546 $ret[] = trim($last, ",");
550 if ($tbl && preg_match('#RENAME\s+TO#i', $l, $m)) {
554 if ($tbl && preg_match('#change\s+column#i', $l, $m)) {
558 // INDEX lookup ..ignore
559 if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i', $l, $m)) {
560 $last = array_pop($ret);
561 $ret[] = trim($last, ",");
566 // CREATE INDEX ..ignore
567 if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i', $l, $m)) {
568 // $l = "CREATE INDEX {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
573 $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
575 $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
576 $l = preg_replace('# blob#i', ' TEXT', $l);
577 $l = preg_replace('# longtext#i', ' TEXT', $l);
578 $l = preg_replace('# tinyint#i', ' INT', $l);
584 $ret = array_merge($extra,$ret);
585 // echo implode("\n", $ret); exit;
587 file_put_contents($fn, implode("\n", $ret));
593 function checkOpts($opts)
597 foreach($opts as $o=>$v) {
598 if (!preg_match('/^json-/', $o) || empty($v)) {
601 if (!file_exists($v)) {
602 die("File does not exist : OPTION --{$o} = {$v} \n");
606 $modules = array_reverse($this->modulesList());
608 // move 'project' one to the end...
610 foreach ($modules as $module){
611 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
612 if($module == 'Core' || !file_exists($file)){
616 $class = "Pman_{$module}_UpdateDatabase";
618 if(!method_exists($x, 'checkOpts')){
621 $x->checkOpts($opts);
625 static function jsonImportFromArray($opts)
627 foreach($opts as $o=>$v) {
628 if (!preg_match('/^json-/', $o) || empty($v)) {
631 $type = str_replace('_', '-', substr($o,5));
633 $data= json_decode(file_get_contents($v),true);
634 $pg = HTML_FlexyFramework::get()->page;
635 DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
645 function runUpdateModulesData()
647 if (class_exists('PDO_DataObjects_Introspection')) {
648 PDO_DataObject_Introspection::$cache = array();
650 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
652 if(!in_array('Core', $this->disabled)){
653 echo "Running jsonImportFromArray\n";
654 Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
657 echo "Running updateData on modules\n";
663 $modules = array_reverse($this->modulesList());
665 // move 'project' one to the end...
667 foreach ($modules as $module){
668 if(in_array($module, $this->disabled)){
671 $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
672 if($module == 'Core' || !file_exists($file)){
677 $class = "Pman_{$module}_UpdateDatabase";
679 if(!method_exists($x, 'updateData')){
689 function updateDataEnums()
692 $enum = DB_DataObject::Factory('core_enum');
693 //DB_DAtaObject::debugLevel(1);
698 'name' => 'COMPTYPE',
699 'display_name' => 'Company Types',
700 'is_system_enum' => 1,
704 'display_name' => 'Owner',
705 'seqid' => 999, // last...
706 'is_system_enum' => 1,
713 'name' => 'HtmlEditor.font-family',
714 'display_name' => 'HTML Editor font families',
715 'is_system_enum' => 1,
718 'name' => 'Helvetica,Arial,sans-serif',
719 'display_name' => 'Helvetica',
724 'name' => 'Courier New',
725 'display_name' => 'Courier',
730 'display_name' => 'Tahoma',
734 'name' => 'Times New Roman,serif',
735 'display_name' => 'Times',
740 'display_name' => 'Verdana',
752 function updateDataGroups()
755 $groups = DB_DataObject::factory('core_group');
756 $groups->initGroups();
758 $groups->initDatabase($this,array(
760 'name' => 'bcc-email', // group who are bcc'ed on all requests.
761 'type' => 0, // system
764 'name' => 'system-email-from',
765 'type' => 0, // system
768 'name' => 'core-person-signup-bcc',
769 'type' => 0, // system
775 function updateDataCompanies()
778 // fix comptypes enums..
779 $c = DB_DataObject::Factory('core_company');
781 $c->selectAdd('distinct(comptype) as comptype');
782 $c->whereAdd("comptype != ''");
785 foreach($c->fetchAll('comptype') as $cts) {
789 $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
792 $c = DB_DataObject::Factory('core_enum');
795 //DB_DataObject::debugLevel(1);
797 $c = DB_DataObject::Factory('core_company');
799 UPDATE {$c->tableName()}
801 comptype_id = (SELECT id FROM core_enum where etype='comptype' and name={$c->tableName()}.comptype LIMIT 1)
815 function initEmails($templateDir, $emails)
818 $pg = HTML_FlexyFramework::get()->page;
819 foreach($emails as $name=>$data) {
820 $cm = DB_DataObject::factory('core_email');
821 $update = $cm->get('name', $name);
824 if (empty($cm->bcc_group)) {
825 if (empty($data['bcc_group'])) {
826 $this->jerr("missing bcc_group for template $name");
828 $g = DB_DataObject::Factory('core_group')->lookup('name',$data['bcc_group']);
831 $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
835 if (!$g->members('email')) {
836 $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
839 $cm->bcc_group = $g->id;
841 if (empty($cm->test_class)) {
842 if (empty($data['test_class'])) {
843 $this->jerr("missing test_class for template $name");
845 $cm->test_class = $data['test_class'];
847 require_once $cm->test_class . '.php';
849 $clsname = str_replace('/','_', $cm->test_class);
851 $method = new ReflectionMethod($clsname , 'test_'. $name) ;
852 $got_it = $method->isStatic();
853 } catch(Exception $e) {
858 $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
862 echo "email: {$name} - checked\n";
863 continue; /// we do not import the body content of templates that exist...
870 // $basedir = $this->bootLoader->rootDir . $mail_template_dir;
874 'file' => $templateDir. $name .'.html'
877 if (!empty($data['master'])) {
878 $opts['master'] = $templateDir . $master .'.html';
880 require_once 'Pman/Core/Import/Core_email.php';
881 $x = new Pman_Core_Import_Core_email();
882 $x->updateOrCreateEmail('', $opts, $cm);
884 echo "email: {$name} - CREATED\n";
889 function updateData()
892 if (class_exists('PDO_DataObjects_Introspection')) {
893 PDO_DataObject_Introspection::$cache = array();
895 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
896 $this->updateDataEnums();
897 $this->updateDataGroups();
898 $this->updateDataCompanies();
900 $c = DB_DataObject::Factory('I18n');
908 function fixMysqlInnodb()
911 static $done_check = false;
917 if (!empty($this->opts['skip-mysql-checks'])) {
920 // innodb in single files is far more efficient that MYD or one big innodb file.
921 // first check if database is using this format.
922 $db = DB_DataObject::factory('core_enum');
923 $db->query("show variables like 'innodb_file_per_table'");
925 if ($db->Value == 'OFF') {
926 die("Error: set innodb_file_per_table = 1 in my.cnf (or run with --skip-mysql-checks\n\n");
929 $db = DB_DataObject::factory('core_enum');
930 $db->query("select version() as version");
933 if (version_compare($db->version, '5.7', '>=' )) {
935 $db = DB_DataObject::factory('core_enum');
936 $db->query("show variables like 'sql_mode'");
939 $modes = explode(",", $db->Value);
941 // these are 'new' problems with mysql.
943 in_array('NO_ZERO_IN_DATE', $modes) ||
944 in_array('NO_ZERO_DATE', $modes) ||
945 in_array('STRICT_TRANS_TABLES', $modes) ||
946 !in_array('ALLOW_INVALID_DATES', $modes)
948 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");
963 /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
965 function fixSequencesMysql()
970 function fixSequencesPgsql()
974 //DB_DataObject::debugLevel(1);
975 $cs = DB_DataObject::factory('core_enum');
979 CASE WHEN strpos(seq_name, '.') > 0 THEN
982 quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
985 ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
986 quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
990 n.nspname AS schema_name,
991 c.relname AS table_name,
992 a.attname AS column_name,
993 regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name
995 JOIN pg_attribute a ON (c.oid=a.attrelid)
996 JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum)
997 JOIN pg_namespace n ON (c.relnamespace=n.oid)
998 WHERE has_schema_privilege(n.oid,'USAGE')
999 AND n.nspname NOT LIKE 'pg!_%' escape '!'
1000 AND has_table_privilege(c.oid,'SELECT')
1001 AND (NOT a.attisdropped)
1002 AND d.adsrc ~ '^nextval'
1006 CASE WHEN strpos(seq_name, '.') > 0 THEN
1007 substring(seq_name, 1,strpos(seq_name,'.')-1)
1012 GROUP BY seq_name HAVING count(*)=1
1015 while ($cs->fetch()) {
1018 foreach($cmds as $cmd) {
1019 $cs = DB_DataObject::factory('core_enum');
1023 $cs = DB_DataObject::factory('core_enum');
1025 SELECT 'SELECT SETVAL(' ||
1026 quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
1027 ', MAX(' || quote_ident(C.attname)|| ')::integer ) FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd
1033 WHERE S.relkind = 'S'
1035 AND D.refobjid = T.oid
1036 AND D.refobjid = C.attrelid
1037 AND D.refobjsubid = C.attnum
1038 AND NS.oid = T.relnamespace
1042 while ($cs->fetch()) {
1045 foreach($cmds as $cmd) {
1046 $cs = DB_DataObject::factory('core_enum');
1053 var $extensions = array(
1058 function runExtensions()
1061 $ff = HTML_Flexyframework::get();
1063 $dburl = parse_url($ff->database);
1065 $dbtype = $dburl['scheme'];
1067 foreach($this->extensions as $ext) {
1069 $scls = ucfirst($dbtype). $ext;
1070 $cls = __CLASS__ . '_'. $scls;
1071 $fn = implode('/',explode('_', $cls)).'.php';
1072 if (!file_exists(__DIR__.'/UpdateDatabase/'. $scls .'.php')) {
1083 function checkSystem()
1085 // most of these are from File_Convert...
1087 // these are required - and have simple dependancies.
1088 require_once 'System.php';
1094 'rsvg-convert', //librsvg2-bin
1100 // these are prefered - but may have complicated depenacies
1105 'html2text', // not availabe in debian squeeze
1106 'pdftocairo', //poppler-utils - not available in debian squeeze.
1116 foreach($req as $r) {
1117 if (!System::which($r)) {
1123 die("Missing these programs - need installing\n" . implode("\n",$res). "\n");
1125 foreach($pref as $r) {
1126 if (!System::which($r)) {
1132 echo "WARNING: Missing these programs - they may need installing\n". implode("\n",$res);
1139 function generateDataobjectsCache()
1141 $url = "http://localhost{$this->local_base_url}/Core/RefreshDatabaseCache";
1147 function curl($url, $request = array(), $method = 'GET')
1149 if($method == 'GET'){
1150 $request = http_build_query($request);
1151 $url = $url . "?" . $request;
1154 $ch = curl_init($url);
1156 if ($method == 'POST') {
1158 curl_setopt($ch, CURLOPT_POST, 1);
1159 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
1163 curl_setopt($ch, CURLOPT_HTTPHEADER,
1164 array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
1168 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1170 curl_setopt($ch, CURLOPT_HEADER, false);
1171 curl_setopt($ch, CURLOPT_VERBOSE, 0);
1172 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1173 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1175 $response = curl_exec($ch);