@@ -60,7 +60,7 @@ |
||
60 | 60 | } |
61 | 61 | if ($format) |
62 | 62 | { |
63 | - $this->setFormat($format); |
|
63 | + $this->setFormat($format); |
|
64 | 64 | } |
65 | 65 | $this->file_name=$file_name; |
66 | 66 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | const FORMAT_TabSeparatedWithNames = 'TabSeparatedWithNames'; |
14 | 14 | const FORMAT_CSV = 'CSV'; |
15 | 15 | |
16 | - private $support_format=['TabSeparated','TabSeparatedWithNames','CSV']; |
|
16 | + private $support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV']; |
|
17 | 17 | /** |
18 | 18 | * @var string |
19 | 19 | */ |
@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @var string |
24 | 24 | */ |
25 | - private $format='CSV'; |
|
25 | + private $format = 'CSV'; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @var bool |
29 | 29 | */ |
30 | - private $gzip=false; |
|
30 | + private $gzip = false; |
|
31 | 31 | /** |
32 | 32 | * WriteToFile constructor. |
33 | 33 | * @param string $file_name |
34 | 34 | * @param bool $overwrite |
35 | 35 | * @param null $format |
36 | 36 | */ |
37 | - public function __construct($file_name,$overwrite=true,$format=null) { |
|
37 | + public function __construct($file_name, $overwrite = true, $format = null) { |
|
38 | 38 | |
39 | 39 | |
40 | 40 | if (!$file_name) |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | throw new QueryException('Can`t delete: ' . $file_name); |
54 | 54 | } |
55 | 55 | } |
56 | - $dir=dirname($file_name); |
|
56 | + $dir = dirname($file_name); |
|
57 | 57 | if (!is_writable($dir)) |
58 | 58 | { |
59 | 59 | throw new QueryException('Can`t writable dir: ' . $dir); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $this->setFormat($format); |
64 | 64 | } |
65 | - $this->file_name=$file_name; |
|
65 | + $this->file_name = $file_name; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function setGzip($flag) |
80 | 80 | { |
81 | - $this->gzip=$flag; |
|
81 | + $this->gzip = $flag; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setFormat($format) |
88 | 88 | { |
89 | - if (!in_array($format,$this->support_format)) |
|
89 | + if (!in_array($format, $this->support_format)) |
|
90 | 90 | { |
91 | 91 | throw new QueryException('Unsupport format: ' . $format); |
92 | 92 | } |
93 | - $this->format=$format; |
|
93 | + $this->format = $format; |
|
94 | 94 | } |
95 | 95 | /** |
96 | 96 | * @return int |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function bindParams(array $bindings) |
15 | 15 | { |
16 | - $this->bindings=[]; |
|
16 | + $this->bindings = []; |
|
17 | 17 | foreach ($bindings as $column => $value) { |
18 | 18 | $this->bindParam($column, $value); |
19 | 19 | } |
@@ -17,44 +17,44 @@ discard block |
||
17 | 17 | public function bindParams(array $bindings) |
18 | 18 | { |
19 | 19 | foreach ($bindings as $column => $value) { |
20 | - $this->bindings[$column]=$value; |
|
20 | + $this->bindings[$column] = $value; |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | - static function __ifsets($matches,$markers,$else=false) |
|
25 | + static function __ifsets($matches, $markers, $else = false) |
|
26 | 26 | { |
27 | - $content_false=''; |
|
27 | + $content_false = ''; |
|
28 | 28 | |
29 | 29 | if ($else) |
30 | 30 | { |
31 | - list($condition, $preset ,$variable, $content_true, $content_false) = $matches; |
|
31 | + list($condition, $preset, $variable, $content_true, $content_false) = $matches; |
|
32 | 32 | } |
33 | 33 | else |
34 | 34 | { |
35 | - list($condition, $preset ,$variable, $content_true) = $matches; |
|
35 | + list($condition, $preset, $variable, $content_true) = $matches; |
|
36 | 36 | } |
37 | - $preset=strtolower($preset); |
|
37 | + $preset = strtolower($preset); |
|
38 | 38 | |
39 | - if ($preset=='set') |
|
39 | + if ($preset == 'set') |
|
40 | 40 | { |
41 | - return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true: $content_false; |
|
41 | + return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true : $content_false; |
|
42 | 42 | } |
43 | - if ($preset=='bool') |
|
43 | + if ($preset == 'bool') |
|
44 | 44 | { |
45 | - return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable]==true) |
|
45 | + return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable] == true) |
|
46 | 46 | ? $content_true |
47 | 47 | : $content_false; |
48 | 48 | } |
49 | - if ($preset=='string') |
|
49 | + if ($preset == 'string') |
|
50 | 50 | { |
51 | 51 | return (isset($markers[$variable]) && is_string($markers[$variable]) && strlen($markers[$variable])) |
52 | 52 | ? $content_true |
53 | 53 | : $content_false; |
54 | 54 | } |
55 | - if ($preset=='int') |
|
55 | + if ($preset == 'int') |
|
56 | 56 | { |
57 | - return (isset($markers[$variable]) && intval($markers[$variable])<>0 ) |
|
57 | + return (isset($markers[$variable]) && intval($markers[$variable]) <> 0) |
|
58 | 58 | ? $content_true |
59 | 59 | : $content_false; |
60 | 60 | } |
@@ -68,29 +68,29 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function process($sql) |
70 | 70 | { |
71 | - $markers=$this->bindings; |
|
71 | + $markers = $this->bindings; |
|
72 | 72 | |
73 | 73 | // 2. process if/else conditions |
74 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
74 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
75 | 75 | list($condition, $variable, $content_true, $content_false) = $matches; |
76 | 76 | |
77 | - return (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) ) ) |
|
77 | + return (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) |
|
78 | 78 | ? $content_true |
79 | 79 | : $content_false; |
80 | 80 | }, $sql); |
81 | 81 | |
82 | 82 | // 3. process if conditions |
83 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
83 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
84 | 84 | list($condition, $variable, $content) = $matches; |
85 | 85 | |
86 | - if (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) )) { |
|
86 | + if (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) { |
|
87 | 87 | return $content; |
88 | 88 | } |
89 | 89 | }, $sql); |
90 | 90 | |
91 | 91 | // 1. process if[set|int]/else conditions |
92 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) {return self::__ifsets($matches,$markers,true); }, $sql); |
|
93 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { return self::__ifsets($matches,$markers,false); }, $sql); |
|
92 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) {return self::__ifsets($matches, $markers, true); }, $sql); |
|
93 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { return self::__ifsets($matches, $markers, false); }, $sql); |
|
94 | 94 | |
95 | 95 | return $sql; |
96 | 96 | } |
@@ -29,8 +29,7 @@ |
||
29 | 29 | if ($else) |
30 | 30 | { |
31 | 31 | list($condition, $preset ,$variable, $content_true, $content_false) = $matches; |
32 | - } |
|
33 | - else |
|
32 | + } else |
|
34 | 33 | { |
35 | 34 | list($condition, $preset ,$variable, $content_true) = $matches; |
36 | 35 | } |
@@ -177,7 +177,7 @@ |
||
177 | 177 | */ |
178 | 178 | public function setTimeout($timeout) |
179 | 179 | { |
180 | - return $this->settings()->max_execution_time($timeout); |
|
180 | + return $this->settings()->max_execution_time($timeout); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -295,8 +295,7 @@ discard block |
||
295 | 295 | if (!$useSessionId) |
296 | 296 | { |
297 | 297 | $this->settings()->makeSessionId(); |
298 | - } |
|
299 | - else |
|
298 | + } else |
|
300 | 299 | { |
301 | 300 | $this->settings()->session_id($useSessionId); |
302 | 301 | } |
@@ -415,7 +414,9 @@ discard block |
||
415 | 414 | */ |
416 | 415 | public function progressFunction($callback) |
417 | 416 | { |
418 | - if (!is_callable($callback)) throw new \InvalidArgumentException('Not is_callable progressFunction'); |
|
417 | + if (!is_callable($callback)) { |
|
418 | + throw new \InvalidArgumentException('Not is_callable progressFunction'); |
|
419 | + } |
|
419 | 420 | |
420 | 421 | if (!$this->settings()->is('send_progress_in_http_headers')) |
421 | 422 | { |
@@ -540,7 +541,7 @@ discard block |
||
540 | 541 | } |
541 | 542 | $preparedValues[] = array_values($row); |
542 | 543 | } |
543 | - }else{ //одна строка |
|
544 | + } else{ //одна строка |
|
544 | 545 | $preparedFields = array_keys($values); |
545 | 546 | $preparedValues = [array_values($values)]; |
546 | 547 | } |
@@ -609,8 +610,7 @@ discard block |
||
609 | 610 | { |
610 | 611 | $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
611 | 612 | |
612 | - } |
|
613 | - else |
|
613 | + } else |
|
614 | 614 | { |
615 | 615 | $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
616 | 616 | |
@@ -654,8 +654,7 @@ discard block |
||
654 | 654 | { |
655 | 655 | $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
656 | 656 | |
657 | - } |
|
658 | - else |
|
657 | + } else |
|
659 | 658 | { |
660 | 659 | $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
661 | 660 |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var bool |
41 | 41 | */ |
42 | - private $_connect_user_readonly=false; |
|
42 | + private $_connect_user_readonly = false; |
|
43 | 43 | /** |
44 | 44 | * @var array |
45 | 45 | */ |
46 | - private $_support_format=['TabSeparated','TabSeparatedWithNames','CSV','CSVWithNames','JSONEachRow']; |
|
46 | + private $_support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV', 'CSVWithNames', 'JSONEachRow']; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Client constructor. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function setReadOnlyUser($flag) |
122 | 122 | { |
123 | - $this->_connect_user_readonly=$flag; |
|
123 | + $this->_connect_user_readonly = $flag; |
|
124 | 124 | $this->settings()->setReadOnlyUser($this->_connect_user_readonly); |
125 | 125 | } |
126 | 126 | /** |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | |
164 | 164 | if (is_array($host)) |
165 | 165 | { |
166 | - $host=array_rand(array_flip($host)); |
|
166 | + $host = array_rand(array_flip($host)); |
|
167 | 167 | } |
168 | 168 | |
169 | - $this->_connect_host=$host; |
|
169 | + $this->_connect_host = $host; |
|
170 | 170 | $this->transport()->setHost($host); |
171 | 171 | } |
172 | 172 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | /** |
290 | 290 | * @return $this |
291 | 291 | */ |
292 | - public function useSession($useSessionId=false) |
|
292 | + public function useSession($useSessionId = false) |
|
293 | 293 | { |
294 | 294 | if (!$this->settings()->getSessionId()) |
295 | 295 | { |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function enableLogQueries($flag = true) |
348 | 348 | { |
349 | - $this->settings()->set('log_queries',intval($flag)); |
|
349 | + $this->settings()->set('log_queries', intval($flag)); |
|
350 | 350 | return $this; |
351 | 351 | } |
352 | 352 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @param bool $flag |
369 | 369 | * @return $this |
370 | 370 | */ |
371 | - public function https($flag=true) |
|
371 | + public function https($flag = true) |
|
372 | 372 | { |
373 | 373 | $this->settings()->https($flag); |
374 | 374 | return $this; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public function enableExtremes($flag = true) |
384 | 384 | { |
385 | - $this->settings()->set('extremes',intval($flag)); |
|
385 | + $this->settings()->set('extremes', intval($flag)); |
|
386 | 386 | return $this; |
387 | 387 | } |
388 | 388 | |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | * @throws Exception\TransportException |
398 | 398 | * @throws \Exception |
399 | 399 | */ |
400 | - public function select($sql, $bindings = [], $whereInFile = null, $writeToFile=null) |
|
400 | + public function select($sql, $bindings = [], $whereInFile = null, $writeToFile = null) |
|
401 | 401 | { |
402 | - return $this->transport()->select($sql, $bindings, $whereInFile,$writeToFile); |
|
402 | + return $this->transport()->select($sql, $bindings, $whereInFile, $writeToFile); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -446,9 +446,9 @@ discard block |
||
446 | 446 | * @throws Exception\TransportException |
447 | 447 | * @throws \Exception |
448 | 448 | */ |
449 | - public function selectAsync($sql, $bindings = [], $whereInFile = null,$writeToFile=null) |
|
449 | + public function selectAsync($sql, $bindings = [], $whereInFile = null, $writeToFile = null) |
|
450 | 450 | { |
451 | - return $this->transport()->selectAsync($sql, $bindings, $whereInFile,$writeToFile); |
|
451 | + return $this->transport()->selectAsync($sql, $bindings, $whereInFile, $writeToFile); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | */ |
486 | 486 | public function showCreateTable($table) |
487 | 487 | { |
488 | - return ($this->select('SHOW CREATE TABLE '.$table)->fetchOne('statement')); |
|
488 | + return ($this->select('SHOW CREATE TABLE ' . $table)->fetchOne('statement')); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -545,17 +545,17 @@ discard block |
||
545 | 545 | */ |
546 | 546 | public function prepareInsertAssocBulk(array $values) |
547 | 547 | { |
548 | - if (isset($values[0]) && is_array($values[0])){ //случай, когда много строк вставляется |
|
548 | + if (isset($values[0]) && is_array($values[0])) { //случай, когда много строк вставляется |
|
549 | 549 | $preparedFields = array_keys($values[0]); |
550 | 550 | $preparedValues = []; |
551 | - foreach ($values as $idx => $row){ |
|
551 | + foreach ($values as $idx => $row) { |
|
552 | 552 | $_fields = array_keys($row); |
553 | - if ($_fields !== $preparedFields){ |
|
554 | - throw new QueryException("Fields not match: ".implode(',',$_fields)." and ".implode(',', $preparedFields)." on element $idx"); |
|
553 | + if ($_fields !== $preparedFields) { |
|
554 | + throw new QueryException("Fields not match: " . implode(',', $_fields) . " and " . implode(',', $preparedFields) . " on element $idx"); |
|
555 | 555 | } |
556 | 556 | $preparedValues[] = array_values($row); |
557 | 557 | } |
558 | - }else{ //одна строка |
|
558 | + } else { //одна строка |
|
559 | 559 | $preparedFields = array_keys($values); |
560 | 560 | $preparedValues = [array_values($values)]; |
561 | 561 | } |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | */ |
589 | 589 | public function insertBatchTSVFiles($table_name, $file_names, $columns_array) |
590 | 590 | { |
591 | - return $this->insertBatchFiles($table_name,$file_names,$columns_array,'TabSeparated'); |
|
591 | + return $this->insertBatchFiles($table_name, $file_names, $columns_array, 'TabSeparated'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -601,17 +601,17 @@ discard block |
||
601 | 601 | * @return array |
602 | 602 | * @throws Exception\TransportException |
603 | 603 | */ |
604 | - public function insertBatchFiles($table_name, $file_names, $columns_array,$format="CSV") |
|
604 | + public function insertBatchFiles($table_name, $file_names, $columns_array, $format = "CSV") |
|
605 | 605 | { |
606 | 606 | if (is_string($file_names)) |
607 | 607 | { |
608 | - $file_names=[$file_names]; |
|
608 | + $file_names = [$file_names]; |
|
609 | 609 | } |
610 | 610 | if ($this->getCountPendingQueue() > 0) { |
611 | 611 | throw new QueryException('Queue must be empty, before insertBatch, need executeAsync'); |
612 | 612 | } |
613 | 613 | |
614 | - if (!in_array($format,$this->_support_format)) |
|
614 | + if (!in_array($format, $this->_support_format)) |
|
615 | 615 | { |
616 | 616 | throw new QueryException('Format not support in insertBatchFiles'); |
617 | 617 | } |
@@ -620,17 +620,17 @@ discard block |
||
620 | 620 | |
621 | 621 | foreach ($file_names as $fileName) { |
622 | 622 | if (!is_file($fileName) || !is_readable($fileName)) { |
623 | - throw new QueryException('Cant read file: ' . $fileName.' '.(is_file($fileName)?'':' is not file')); |
|
623 | + throw new QueryException('Cant read file: ' . $fileName . ' ' . (is_file($fileName) ? '' : ' is not file')); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | if (!$columns_array) |
627 | 627 | { |
628 | - $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
|
628 | + $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format; |
|
629 | 629 | |
630 | 630 | } |
631 | 631 | else |
632 | 632 | { |
633 | - $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
|
633 | + $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format; |
|
634 | 634 | |
635 | 635 | } |
636 | 636 | $result[$fileName] = $this->transport()->writeAsyncCSV($sql, $fileName); |
@@ -657,25 +657,25 @@ discard block |
||
657 | 657 | * @param string $format ['TabSeparated','TabSeparatedWithNames','CSV','CSVWithNames'] |
658 | 658 | * @return Transport\CurlerRequest |
659 | 659 | */ |
660 | - public function insertBatchStream($table_name, $columns_array,$format="CSV") |
|
660 | + public function insertBatchStream($table_name, $columns_array, $format = "CSV") |
|
661 | 661 | { |
662 | 662 | if ($this->getCountPendingQueue() > 0) { |
663 | 663 | throw new QueryException('Queue must be empty, before insertBatch, need executeAsync'); |
664 | 664 | } |
665 | 665 | |
666 | - if (!in_array($format,$this->_support_format)) |
|
666 | + if (!in_array($format, $this->_support_format)) |
|
667 | 667 | { |
668 | 668 | throw new QueryException('Format not support in insertBatchFiles'); |
669 | 669 | } |
670 | 670 | |
671 | 671 | if (!$columns_array) |
672 | 672 | { |
673 | - $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
|
673 | + $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format; |
|
674 | 674 | |
675 | 675 | } |
676 | 676 | else |
677 | 677 | { |
678 | - $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
|
678 | + $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format; |
|
679 | 679 | |
680 | 680 | } |
681 | 681 | |
@@ -742,16 +742,16 @@ discard block |
||
742 | 742 | * @throws Exception\TransportException |
743 | 743 | * @throws \Exception |
744 | 744 | */ |
745 | - public function tablesSize($flatList=false) |
|
745 | + public function tablesSize($flatList = false) |
|
746 | 746 | { |
747 | - $z=$this->select(' |
|
747 | + $z = $this->select(' |
|
748 | 748 | SELECT table,database, |
749 | 749 | formatReadableSize(sum(bytes)) as size, |
750 | 750 | sum(bytes) as sizebytes, |
751 | 751 | min(min_date) as min_date, |
752 | 752 | max(max_date) as max_date |
753 | 753 | FROM system.parts |
754 | - WHERE active AND database=\''.$this->settings()->getDatabase().'\' |
|
754 | + WHERE active AND database=\''.$this->settings()->getDatabase() . '\' |
|
755 | 755 | GROUP BY table,database |
756 | 756 | '); |
757 | 757 | |
@@ -774,12 +774,12 @@ discard block |
||
774 | 774 | * @throws Exception\TransportException |
775 | 775 | * @throws \Exception |
776 | 776 | */ |
777 | - public function isExists($database,$table) |
|
777 | + public function isExists($database, $table) |
|
778 | 778 | { |
779 | 779 | return $this->select(' |
780 | 780 | SELECT * |
781 | 781 | FROM system.tables |
782 | - WHERE name=\''.$table.'\' AND database=\''.$database.'\'' |
|
782 | + WHERE name=\''.$table . '\' AND database=\'' . $database . '\'' |
|
783 | 783 | )->rowsAsTree('name'); |
784 | 784 | } |
785 | 785 | |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | return $this->select(' |
799 | 799 | SELECT * |
800 | 800 | FROM system.parts |
801 | - WHERE like(table,\'%' . $table . '%\') AND database=\''.$this->settings()->getDatabase().'\' |
|
801 | + WHERE like(table,\'%' . $table . '%\') AND database=\'' . $this->settings()->getDatabase() . '\' |
|
802 | 802 | ORDER BY max_date ' . ($limit > 0 ? ' LIMIT ' . intval($limit) : '') |
803 | 803 | )->rowsAsTree('name'); |
804 | 804 | } |
@@ -814,8 +814,8 @@ discard block |
||
814 | 814 | public function dropPartition($dataBaseTableName, $partition_id) |
815 | 815 | { |
816 | 816 | |
817 | - $partition_id=trim($partition_id,'\''); |
|
818 | - $this->settings()->set('replication_alter_partitions_sync',2); |
|
817 | + $partition_id = trim($partition_id, '\''); |
|
818 | + $this->settings()->set('replication_alter_partitions_sync', 2); |
|
819 | 819 | $state = $this->write('ALTER TABLE {dataBaseTableName} DROP PARTITION :partion_id', [ |
820 | 820 | 'dataBaseTableName' => $dataBaseTableName, |
821 | 821 | 'partion_id' => $partition_id |
@@ -833,12 +833,12 @@ discard block |
||
833 | 833 | */ |
834 | 834 | public function truncateTable($tableName) |
835 | 835 | { |
836 | - $partions=$this->partitions($tableName); |
|
837 | - $out=[]; |
|
836 | + $partions = $this->partitions($tableName); |
|
837 | + $out = []; |
|
838 | 838 | foreach ($partions as $part_key=>$part) |
839 | 839 | { |
840 | - $part_id=$part['partition']; |
|
841 | - $out[$part_id]=$this->dropPartition($tableName,$part_id); |
|
840 | + $part_id = $part['partition']; |
|
841 | + $out[$part_id] = $this->dropPartition($tableName, $part_id); |
|
842 | 842 | } |
843 | 843 | return $out; |
844 | 844 | } |
@@ -873,9 +873,9 @@ discard block |
||
873 | 873 | } |
874 | 874 | } |
875 | 875 | |
876 | - $result=[]; |
|
876 | + $result = []; |
|
877 | 877 | foreach ($drop as $partition_id) { |
878 | - $result[$partition_id]=$this->dropPartition($table_name, $partition_id); |
|
878 | + $result[$partition_id] = $this->dropPartition($table_name, $partition_id); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | return $result; |
@@ -353,8 +353,9 @@ discard block |
||
353 | 353 | public function getHeaders() |
354 | 354 | { |
355 | 355 | $head=[]; |
356 | - foreach ($this->headers as $key=>$value) |
|
357 | - $head[]= sprintf("%s: %s", $key, $value); |
|
356 | + foreach ($this->headers as $key=>$value) { |
|
357 | + $head[]= sprintf("%s: %s", $key, $value); |
|
358 | + } |
|
358 | 359 | return $head; |
359 | 360 | } |
360 | 361 | |
@@ -394,8 +395,7 @@ discard block |
||
394 | 395 | if ($flag) { |
395 | 396 | $this->_httpCompression = $flag; |
396 | 397 | $this->options[CURLOPT_ENCODING] = 'gzip'; |
397 | - } |
|
398 | - else |
|
398 | + } else |
|
399 | 399 | { |
400 | 400 | $this->_httpCompression = false; |
401 | 401 | unset($this->options[CURLOPT_ENCODING]); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @var CurlerResponse |
49 | 49 | */ |
50 | - private $resp=null; |
|
50 | + private $resp = null; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @var bool |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * @var callable |
79 | 79 | */ |
80 | - private $callback_function=null; |
|
80 | + private $callback_function = null; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @var bool |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | CURLOPT_SSL_VERIFYHOST => 0, |
110 | 110 | CURLOPT_SSL_VERIFYPEER => false, |
111 | 111 | CURLOPT_TIMEOUT => 10, |
112 | - CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
112 | + CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
113 | 113 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
114 | 114 | CURLOPT_MAXREDIRS => 10, |
115 | 115 | CURLOPT_HEADER => TRUE, |
116 | 116 | CURLOPT_FOLLOWLOCATION => TRUE, |
117 | - CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
118 | - CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
117 | + CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
118 | + CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
119 | 119 | CURLOPT_RETURNTRANSFER => TRUE, |
120 | 120 | CURLOPT_USERAGENT => 'smi2/PHPClickHouse/client', |
121 | 121 | ); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function setReadFunction($callback) |
240 | 240 | { |
241 | - $this->options[CURLOPT_READFUNCTION]=$callback; |
|
241 | + $this->options[CURLOPT_READFUNCTION] = $callback; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | */ |
364 | 364 | public function getHeaders() |
365 | 365 | { |
366 | - $head=[]; |
|
366 | + $head = []; |
|
367 | 367 | foreach ($this->headers as $key=>$value) |
368 | - $head[]= sprintf("%s: %s", $key, $value); |
|
368 | + $head[] = sprintf("%s: %s", $key, $value); |
|
369 | 369 | return $head; |
370 | 370 | } |
371 | 371 | |
@@ -640,8 +640,8 @@ discard block |
||
640 | 640 | throw new \Exception('setFunctionProgress not is_callable'); |
641 | 641 | } |
642 | 642 | |
643 | - $this->option(CURLOPT_NOPROGRESS,false); |
|
644 | - $this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0 |
|
643 | + $this->option(CURLOPT_NOPROGRESS, false); |
|
644 | + $this->option(CURLOPT_PROGRESSFUNCTION, $callback); // version 5.5.0 |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | } |
705 | 705 | |
706 | 706 | if ($this->options[CURLOPT_VERBOSE]) { |
707 | - echo "\n-----------BODY REQUEST----------\n".$curl_opt[CURLOPT_POSTFIELDS]."\n------END--------\n"; |
|
707 | + echo "\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n"; |
|
708 | 708 | } |
709 | 709 | curl_setopt_array($this->handle, $curl_opt); |
710 | 710 | return true; |
@@ -176,8 +176,7 @@ discard block |
||
176 | 176 | foreach (explode("\r\n", $header_text) as $i => $line) { |
177 | 177 | if ($i === 0) { |
178 | 178 | $headers['http_code'] = $line; |
179 | - } |
|
180 | - else { |
|
179 | + } else { |
|
181 | 180 | $r = explode(': ', $line); |
182 | 181 | if (sizeof($r) == 2) { |
183 | 182 | $headers[$r[0]] = $r[1]; |
@@ -354,8 +353,7 @@ discard block |
||
354 | 353 | if (sizeof($add)) { |
355 | 354 | if ($canAdd >= sizeof($add)) { |
356 | 355 | $ll = $add; |
357 | - } |
|
358 | - else { |
|
356 | + } else { |
|
359 | 357 | $ll = array_rand($add, $canAdd); |
360 | 358 | if (!is_array($ll)) { |
361 | 359 | $ll = array($ll => $ll); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function total_time() |
72 | 72 | { |
73 | - return round($this->_info['total_time'],3); |
|
73 | + return round($this->_info['total_time'], 3); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function starttransfer_time() |
80 | 80 | { |
81 | - return round($this->_info['starttransfer_time'],3); |
|
81 | + return round($this->_info['starttransfer_time'], 3); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function connect_time() |
88 | 88 | { |
89 | - return round($this->_info['connect_time'],3); |
|
89 | + return round($this->_info['connect_time'], 3); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function pretransfer_time() |
96 | 96 | { |
97 | - return round($this->_info['pretransfer_time'],3); |
|
97 | + return round($this->_info['pretransfer_time'], 3); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function rawDataOrJson($format) |
291 | 291 | { |
292 | - if (stripos($format,'json')!==false) |
|
292 | + if (stripos($format, 'json') !== false) |
|
293 | 293 | { |
294 | 294 | return $this->json(); |
295 | 295 | } |
@@ -114,7 +114,9 @@ discard block |
||
114 | 114 | public function getUri() |
115 | 115 | { |
116 | 116 | $proto='http'; |
117 | - if ($this->settings()->isHttps()) $proto='https'; |
|
117 | + if ($this->settings()->isHttps()) { |
|
118 | + $proto='https'; |
|
119 | + } |
|
118 | 120 | |
119 | 121 | return $proto.'://' . $this->_host . ':' . $this->_port; |
120 | 122 | } |
@@ -328,13 +330,19 @@ discard block |
||
328 | 330 | if ($code==200) { |
329 | 331 | $response = curl_multi_getcontent($handle); |
330 | 332 | $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); |
331 | - if (!$header_size) return false; |
|
333 | + if (!$header_size) { |
|
334 | + return false; |
|
335 | + } |
|
332 | 336 | |
333 | 337 | $header = substr($response, 0, $header_size); |
334 | - if (!$header_size) return false; |
|
338 | + if (!$header_size) { |
|
339 | + return false; |
|
340 | + } |
|
335 | 341 | $pos=strrpos($header,'X-ClickHouse-Progress'); |
336 | 342 | |
337 | - if (!$pos) return false; |
|
343 | + if (!$pos) { |
|
344 | + return false; |
|
345 | + } |
|
338 | 346 | |
339 | 347 | $last=substr($header,$pos); |
340 | 348 | $data=@json_decode(str_ireplace('X-ClickHouse-Progress:','',$last),true); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @var callable |
63 | 63 | */ |
64 | - private $xClickHouseProgress=null; |
|
64 | + private $xClickHouseProgress = null; |
|
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Http constructor. |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getUri() |
115 | 115 | { |
116 | - $proto='http'; |
|
117 | - if ($this->settings()->isHttps()) $proto='https'; |
|
116 | + $proto = 'http'; |
|
117 | + if ($this->settings()->isHttps()) $proto = 'https'; |
|
118 | 118 | |
119 | - return $proto.'://' . $this->_host . ':' . $this->_port; |
|
119 | + return $proto . '://' . $this->_host . ':' . $this->_port; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | $new->timeOut($this->settings()->getTimeOut()); |
188 | - $new->connectTimeOut($this->_connectTimeOut)->keepAlive();// one sec |
|
188 | + $new->connectTimeOut($this->_connectTimeOut)->keepAlive(); // one sec |
|
189 | 189 | $new->verbose(boolval($this->_verbose)); |
190 | 190 | |
191 | 191 | return $new; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $request = $this->newRequest($extendinfo); |
280 | 280 | $request->url($url); |
281 | 281 | |
282 | - $request->setCallbackFunction(function (CurlerRequest $request) { |
|
282 | + $request->setCallbackFunction(function(CurlerRequest $request) { |
|
283 | 283 | fclose($request->getInfileHandle()); |
284 | 284 | }); |
285 | 285 | |
@@ -322,29 +322,29 @@ discard block |
||
322 | 322 | |
323 | 323 | public function __findXClickHouseProgress($handle) |
324 | 324 | { |
325 | - $code=curl_getinfo($handle,CURLINFO_HTTP_CODE); |
|
325 | + $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
|
326 | 326 | |
327 | 327 | // Search X-ClickHouse-Progress |
328 | - if ($code==200) { |
|
328 | + if ($code == 200) { |
|
329 | 329 | $response = curl_multi_getcontent($handle); |
330 | 330 | $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); |
331 | 331 | if (!$header_size) return false; |
332 | 332 | |
333 | 333 | $header = substr($response, 0, $header_size); |
334 | 334 | if (!$header_size) return false; |
335 | - $pos=strrpos($header,'X-ClickHouse-Progress'); |
|
335 | + $pos = strrpos($header, 'X-ClickHouse-Progress'); |
|
336 | 336 | |
337 | 337 | if (!$pos) return false; |
338 | 338 | |
339 | - $last=substr($header,$pos); |
|
340 | - $data=@json_decode(str_ireplace('X-ClickHouse-Progress:','',$last),true); |
|
339 | + $last = substr($header, $pos); |
|
340 | + $data = @json_decode(str_ireplace('X-ClickHouse-Progress:', '', $last), true); |
|
341 | 341 | |
342 | 342 | if ($data && is_callable($this->xClickHouseProgress)) { |
343 | 343 | |
344 | - if (is_array($this->xClickHouseProgress)){ |
|
345 | - call_user_func_array($this->xClickHouseProgress,[$data]); |
|
344 | + if (is_array($this->xClickHouseProgress)) { |
|
345 | + call_user_func_array($this->xClickHouseProgress, [$data]); |
|
346 | 346 | } else { |
347 | - call_user_func($this->xClickHouseProgress,$data); |
|
347 | + call_user_func($this->xClickHouseProgress, $data); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | |
@@ -407,13 +407,13 @@ discard block |
||
407 | 407 | } |
408 | 408 | |
409 | 409 | |
410 | - $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function (CurlerRequest $request) { |
|
410 | + $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function(CurlerRequest $request) { |
|
411 | 411 | fclose($request->getResultFileHandle()); |
412 | 412 | }); |
413 | 413 | } |
414 | 414 | if ($this->xClickHouseProgress) |
415 | 415 | { |
416 | - $request->setFunctionProgress([$this,'__findXClickHouseProgress']); |
|
416 | + $request->setFunctionProgress([$this, '__findXClickHouseProgress']); |
|
417 | 417 | } |
418 | 418 | // --------------------------------------------------------------------------------- |
419 | 419 | return $request; |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | */ |
544 | 544 | public function setProgressFunction(callable $callback) |
545 | 545 | { |
546 | - $this->xClickHouseProgress=$callback; |
|
546 | + $this->xClickHouseProgress = $callback; |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -193,7 +193,9 @@ discard block |
||
193 | 193 | // if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);} |
194 | 194 | if ($this->softCheck ) |
195 | 195 | { |
196 | - if (!$ok) break; |
|
196 | + if (!$ok) { |
|
197 | + break; |
|
198 | + } |
|
197 | 199 | continue; |
198 | 200 | } |
199 | 201 | |
@@ -209,7 +211,9 @@ discard block |
||
209 | 211 | $ok = false; |
210 | 212 | $this->error[] = 'log_max_index : ' . json_encode($replica); |
211 | 213 | } |
212 | - if (!$ok) break; |
|
214 | + if (!$ok) { |
|
215 | + break; |
|
216 | + } |
|
213 | 217 | } |
214 | 218 | return $ok; |
215 | 219 | } |
@@ -308,7 +312,9 @@ discard block |
||
308 | 312 | // Let's check that replication goes well |
309 | 313 | $rIsOk = $this->isReplicasWork($result['replicas'][$node]); |
310 | 314 | $result['replicasIsOk'][$node] = $rIsOk; |
311 | - if (!$rIsOk) $replicasIsOk = false; |
|
315 | + if (!$rIsOk) { |
|
316 | + $replicasIsOk = false; |
|
317 | + } |
|
312 | 318 | // --------------------------------------------------------------------------------------------------- |
313 | 319 | } |
314 | 320 | |
@@ -328,7 +334,9 @@ discard block |
||
328 | 334 | $this->error[] = 'Have bad node : ' . json_encode($this->badNodes); |
329 | 335 | $this->replicasIsOk = false; |
330 | 336 | } |
331 | - if (!sizeof($this->error)) $this->error = false; |
|
337 | + if (!sizeof($this->error)) { |
|
338 | + $this->error = false; |
|
339 | + } |
|
332 | 340 | $this->resultScan = $result; |
333 | 341 | // @todo : We connect to everyone in the DNS list, we need to decry that the requests were returned by all the hosts to which we connected |
334 | 342 | return $this; |
@@ -376,16 +384,19 @@ discard block |
||
376 | 384 | if (in_array($node,$nodes_check)) |
377 | 385 | { |
378 | 386 | $find=$node; |
379 | - } |
|
380 | - else |
|
387 | + } else |
|
381 | 388 | { |
382 | 389 | // node exists on cluster, but not check |
383 | 390 | } |
384 | 391 | |
385 | 392 | } |
386 | - if ($find) break; |
|
393 | + if ($find) { |
|
394 | + break; |
|
395 | + } |
|
396 | + } |
|
397 | + if ($find) { |
|
398 | + break; |
|
387 | 399 | } |
388 | - if ($find) break; |
|
389 | 400 | } |
390 | 401 | if (!$find){ |
391 | 402 | $find=$nodes[0]; |
@@ -435,7 +446,9 @@ discard block |
||
435 | 446 | public function getClusterInfoTable($cluster) |
436 | 447 | { |
437 | 448 | $this->connect(); |
438 | - if (empty($this->resultScan['cluster.list'][$cluster])) throw new QueryException('Cluster not find:' . $cluster); |
|
449 | + if (empty($this->resultScan['cluster.list'][$cluster])) { |
|
450 | + throw new QueryException('Cluster not find:' . $cluster); |
|
451 | + } |
|
439 | 452 | return $this->resultScan['cluster.list'][$cluster]; |
440 | 453 | } |
441 | 454 | |
@@ -474,8 +487,7 @@ discard block |
||
474 | 487 | if ($resultDetail) |
475 | 488 | { |
476 | 489 | $list[$db_name.'.'.$table_name]=$nodes; |
477 | - } |
|
478 | - else |
|
490 | + } else |
|
479 | 491 | { |
480 | 492 | $list[$db_name.'.'.$table_name]=array_keys($nodes); |
481 | 493 | } |
@@ -557,13 +569,17 @@ discard block |
||
557 | 569 | { |
558 | 570 | $list=$this->getTables(true); |
559 | 571 | |
560 | - if (empty($list[$database_table])) return []; |
|
572 | + if (empty($list[$database_table])) { |
|
573 | + return []; |
|
574 | + } |
|
561 | 575 | |
562 | 576 | |
563 | 577 | $result=[]; |
564 | 578 | foreach ($list[$database_table] as $node=>$row) |
565 | 579 | { |
566 | - if ($row['is_leader']) $result[]=$node; |
|
580 | + if ($row['is_leader']) { |
|
581 | + $result[]=$node; |
|
582 | + } |
|
567 | 583 | } |
568 | 584 | return $result; |
569 | 585 | } |
@@ -503,7 +503,7 @@ |
||
503 | 503 | */ |
504 | 504 | public function getSizeTable($database_table) |
505 | 505 | { |
506 | - $nodes=$this->getNodesByTable($database_table); |
|
506 | + $nodes=$this->getNodesByTable($database_table); |
|
507 | 507 | // scan need node`s |
508 | 508 | foreach ($nodes as $node) |
509 | 509 | { |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @var int|float |
44 | 44 | */ |
45 | - private $scanTimeOut=10; |
|
45 | + private $scanTimeOut = 10; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var array |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @var array |
79 | 79 | */ |
80 | - private $_table_size_cache=[]; |
|
80 | + private $_table_size_cache = []; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Cluster constructor. |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | // @todo : rewrite total_replicas=1 если кластер без реплики , нужно проверять какой класте и сколько в нем реплик |
193 | 193 | // if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);} |
194 | - if ($this->softCheck ) |
|
194 | + if ($this->softCheck) |
|
195 | 195 | { |
196 | 196 | if (!$ok) break; |
197 | 197 | continue; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $statementsClusters[$node]->getRequest()->setDnsCache(0)->timeOut($this->scanTimeOut)->connectTimeOut($this->scanTimeOut); |
263 | 263 | } |
264 | 264 | $this->defaultClient()->executeAsync(); |
265 | - $tables=[]; |
|
265 | + $tables = []; |
|
266 | 266 | |
267 | 267 | foreach ($this->nodes as $node) { |
268 | 268 | |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | try { |
271 | 271 | $r = $statementsReplicas[$node]->rows(); |
272 | 272 | foreach ($r as $row) { |
273 | - $tables[$row['database']][$row['table']][$node] =$row; |
|
273 | + $tables[$row['database']][$row['table']][$node] = $row; |
|
274 | 274 | } |
275 | 275 | $result['replicas'][$node] = $r; |
276 | - } catch (\Exception $E) { |
|
276 | + }catch (\Exception $E) { |
|
277 | 277 | $result['replicas'][$node] = false; |
278 | 278 | $badNodes[$node] = $E->getMessage(); |
279 | 279 | $this->error[] = 'statementsReplicas:' . $E->getMessage(); |
280 | 280 | } |
281 | 281 | // --------------------------------------------------------------------------------------------------- |
282 | - $hosts=[]; |
|
282 | + $hosts = []; |
|
283 | 283 | |
284 | 284 | try { |
285 | 285 | $c = $statementsClusters[$node]->rows(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | ]; |
296 | 296 | } |
297 | 297 | |
298 | - } catch (\Exception $E) { |
|
298 | + }catch (\Exception $E) { |
|
299 | 299 | $result['clusters'][$node] = false; |
300 | 300 | |
301 | 301 | $this->error[] = 'clusters:' . $E->getMessage(); |
@@ -363,22 +363,22 @@ discard block |
||
363 | 363 | * @return Client |
364 | 364 | * @throws Exception\TransportException |
365 | 365 | */ |
366 | - public function clientLike($cluster,$ip_addr_like) |
|
366 | + public function clientLike($cluster, $ip_addr_like) |
|
367 | 367 | { |
368 | - $nodes_check=$this->nodes; |
|
369 | - $nodes=$this->getClusterNodes($cluster); |
|
370 | - $list_ips_need=explode(';',$ip_addr_like); |
|
371 | - $find=false; |
|
372 | - foreach($list_ips_need as $like) |
|
368 | + $nodes_check = $this->nodes; |
|
369 | + $nodes = $this->getClusterNodes($cluster); |
|
370 | + $list_ips_need = explode(';', $ip_addr_like); |
|
371 | + $find = false; |
|
372 | + foreach ($list_ips_need as $like) |
|
373 | 373 | { |
374 | 374 | foreach ($nodes as $node) |
375 | 375 | { |
376 | 376 | |
377 | - if (stripos($node,$like)!==false) |
|
377 | + if (stripos($node, $like) !== false) |
|
378 | 378 | { |
379 | - if (in_array($node,$nodes_check)) |
|
379 | + if (in_array($node, $nodes_check)) |
|
380 | 380 | { |
381 | - $find=$node; |
|
381 | + $find = $node; |
|
382 | 382 | } |
383 | 383 | else |
384 | 384 | { |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | } |
391 | 391 | if ($find) break; |
392 | 392 | } |
393 | - if (!$find){ |
|
394 | - $find=$nodes[0]; |
|
393 | + if (!$find) { |
|
394 | + $find = $nodes[0]; |
|
395 | 395 | } |
396 | 396 | return $this->client($find); |
397 | 397 | } |
@@ -471,10 +471,10 @@ discard block |
||
471 | 471 | * @return array |
472 | 472 | * @throws Exception\TransportException |
473 | 473 | */ |
474 | - public function getTables($resultDetail=false) |
|
474 | + public function getTables($resultDetail = false) |
|
475 | 475 | { |
476 | 476 | $this->connect(); |
477 | - $list=[]; |
|
477 | + $list = []; |
|
478 | 478 | foreach ($this->tables as $db_name=>$tables) |
479 | 479 | { |
480 | 480 | foreach ($tables as $table_name=>$nodes) |
@@ -482,11 +482,11 @@ discard block |
||
482 | 482 | |
483 | 483 | if ($resultDetail) |
484 | 484 | { |
485 | - $list[$db_name.'.'.$table_name]=$nodes; |
|
485 | + $list[$db_name . '.' . $table_name] = $nodes; |
|
486 | 486 | } |
487 | 487 | else |
488 | 488 | { |
489 | - $list[$db_name.'.'.$table_name]=array_keys($nodes); |
|
489 | + $list[$db_name . '.' . $table_name] = array_keys($nodes); |
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | } |
@@ -503,23 +503,23 @@ discard block |
||
503 | 503 | */ |
504 | 504 | public function getSizeTable($database_table) |
505 | 505 | { |
506 | - $nodes=$this->getNodesByTable($database_table); |
|
506 | + $nodes = $this->getNodesByTable($database_table); |
|
507 | 507 | // scan need node`s |
508 | 508 | foreach ($nodes as $node) |
509 | 509 | { |
510 | 510 | if (empty($this->_table_size_cache[$node])) |
511 | 511 | { |
512 | - $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true); |
|
512 | + $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true); |
|
513 | 513 | } |
514 | 514 | } |
515 | 515 | |
516 | - $sizes=[]; |
|
516 | + $sizes = []; |
|
517 | 517 | foreach ($this->_table_size_cache as $node=>$rows) |
518 | 518 | { |
519 | 519 | foreach ($rows as $row) |
520 | 520 | { |
521 | - $sizes[$row['database'].'.'.$row['table']][$node]=$row; |
|
522 | - @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes']; |
|
521 | + $sizes[$row['database'] . '.' . $row['table']][$node] = $row; |
|
522 | + @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes']; |
|
523 | 523 | |
524 | 524 | |
525 | 525 | |
@@ -541,17 +541,17 @@ discard block |
||
541 | 541 | * @return array |
542 | 542 | * @throws Exception\TransportException |
543 | 543 | */ |
544 | - public function truncateTable($database_table,$timeOut=2000) |
|
544 | + public function truncateTable($database_table, $timeOut = 2000) |
|
545 | 545 | { |
546 | - $out=[]; |
|
547 | - list($db,$table)=explode('.',$database_table); |
|
548 | - $nodes=$this->getMasterNodeForTable($database_table); |
|
546 | + $out = []; |
|
547 | + list($db, $table) = explode('.', $database_table); |
|
548 | + $nodes = $this->getMasterNodeForTable($database_table); |
|
549 | 549 | // scan need node`s |
550 | 550 | foreach ($nodes as $node) |
551 | 551 | { |
552 | - $def=$this->client($node)->getTimeout(); |
|
552 | + $def = $this->client($node)->getTimeout(); |
|
553 | 553 | $this->client($node)->database($db)->setTimeout($timeOut); |
554 | - $out[$node]=$this->client($node)->truncateTable($table); |
|
554 | + $out[$node] = $this->client($node)->truncateTable($table); |
|
555 | 555 | $this->client($node)->setTimeout($def); |
556 | 556 | } |
557 | 557 | return $out; |
@@ -566,15 +566,15 @@ discard block |
||
566 | 566 | */ |
567 | 567 | public function getMasterNodeForTable($database_table) |
568 | 568 | { |
569 | - $list=$this->getTables(true); |
|
569 | + $list = $this->getTables(true); |
|
570 | 570 | |
571 | 571 | if (empty($list[$database_table])) return []; |
572 | 572 | |
573 | 573 | |
574 | - $result=[]; |
|
574 | + $result = []; |
|
575 | 575 | foreach ($list[$database_table] as $node=>$row) |
576 | 576 | { |
577 | - if ($row['is_leader']) $result[]=$node; |
|
577 | + if ($row['is_leader']) $result[] = $node; |
|
578 | 578 | } |
579 | 579 | return $result; |
580 | 580 | } |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function getNodesByTable($database_table) |
589 | 589 | { |
590 | - $list=$this->getTables(); |
|
590 | + $list = $this->getTables(); |
|
591 | 591 | if (empty($list[$database_table])) { |
592 | 592 | throw new QueryException('Not find :' . $database_table); |
593 | 593 | } |