@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | $db = new Database( $this->wpdb ); |
34 | 34 | $template->action = 'structure'; |
35 | 35 | $template->tables = $db->get_tables(); |
36 | - if ( isset( $args['table'] ) ) { |
|
37 | - $template->table = $db->get_table( $args['table'] ); |
|
36 | + if ( isset( $args[ 'table' ] ) ) { |
|
37 | + $template->table = $db->get_table( $args[ 'table' ] ); |
|
38 | 38 | $template->record = $template->table->get_default_record(); |
39 | 39 | } |
40 | 40 | $template->xtypes = Column::get_xtypes(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function newtable( $args ) { |
50 | 50 | // Create table. |
51 | 51 | $db = new Database( $this->wpdb ); |
52 | - $table = $db->create_table( $args['new_table_name'] ); |
|
52 | + $table = $db->create_table( $args[ 'new_table_name' ] ); |
|
53 | 53 | |
54 | 54 | // Redirect user with message. |
55 | 55 | $template = new Template( 'table/schema.html' ); |
@@ -65,49 +65,49 @@ discard block |
||
65 | 65 | * @param string[] $args The request arguments. |
66 | 66 | */ |
67 | 67 | public function save( $args ) { |
68 | - if ( ! isset( $args['table'] ) || ! current_user_can( 'promote_users' ) ) { |
|
68 | + if ( ! isset( $args[ 'table' ] ) || ! current_user_can( 'promote_users' ) ) { |
|
69 | 69 | $url = admin_url( 'admin.php?page=tabulate' ); |
70 | 70 | wp_safe_redirect( $url ); |
71 | 71 | exit; |
72 | 72 | } |
73 | 73 | $db = new Database( $this->wpdb ); |
74 | - $table = $db->get_table( $args['table'] ); |
|
75 | - if ( isset( $args['delete'] ) ) { |
|
74 | + $table = $db->get_table( $args[ 'table' ] ); |
|
75 | + if ( isset( $args[ 'delete' ] ) ) { |
|
76 | 76 | wp_safe_redirect( $table->get_url( 'delete', null, 'schema' ) ); |
77 | 77 | exit; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Rename. |
81 | - $new_name = $args['table']; |
|
82 | - if ( $table instanceof Table && ! empty( $args['new_name'] ) ) { |
|
83 | - $table->rename( $args['new_name'] ); |
|
81 | + $new_name = $args[ 'table' ]; |
|
82 | + if ( $table instanceof Table && ! empty( $args[ 'new_name' ] ) ) { |
|
83 | + $table->rename( $args[ 'new_name' ] ); |
|
84 | 84 | $new_name = $table->get_name(); |
85 | 85 | } |
86 | 86 | |
87 | 87 | // Set comment. |
88 | - if ( isset( $args['new_comment'] ) ) { |
|
89 | - $table->set_comment( $args['new_comment'] ); |
|
88 | + if ( isset( $args[ 'new_comment' ] ) ) { |
|
89 | + $table->set_comment( $args[ 'new_comment' ] ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // Update columns. |
93 | 93 | $previous_column_name = ''; |
94 | - foreach ( $args['columns'] as $col_info ) { |
|
94 | + foreach ( $args[ 'columns' ] as $col_info ) { |
|
95 | 95 | // Validate inputs. |
96 | - $old_col_name = isset( $col_info['old_name'] ) ? $col_info['old_name'] : null; |
|
97 | - $new_col_name = isset( $col_info['new_name'] ) ? $col_info['new_name'] : null; |
|
98 | - $xtype = isset( $col_info['xtype'] ) ? $col_info['xtype'] : null; |
|
99 | - $size = isset( $col_info['size'] ) ? wp_unslash( $col_info['size'] ) : null; |
|
100 | - $nullable = isset( $col_info['nullable'] ); |
|
101 | - $default = isset( $col_info['default'] ) ? $col_info['default'] : null; |
|
102 | - $auto_increment = isset( $args['auto_increment'] ) && $args['auto_increment'] === $old_col_name; |
|
103 | - $unique = isset( $col_info['unique'] ); |
|
104 | - $comment = isset( $col_info['comment'] ) ? $col_info['comment'] : null; |
|
105 | - $target_table = isset( $col_info['target_table'] ) ? $db->get_table( $col_info['target_table'] ) : null; |
|
96 | + $old_col_name = isset( $col_info[ 'old_name' ] ) ? $col_info[ 'old_name' ] : null; |
|
97 | + $new_col_name = isset( $col_info[ 'new_name' ] ) ? $col_info[ 'new_name' ] : null; |
|
98 | + $xtype = isset( $col_info[ 'xtype' ] ) ? $col_info[ 'xtype' ] : null; |
|
99 | + $size = isset( $col_info[ 'size' ] ) ? wp_unslash( $col_info[ 'size' ] ) : null; |
|
100 | + $nullable = isset( $col_info[ 'nullable' ] ); |
|
101 | + $default = isset( $col_info[ 'default' ] ) ? $col_info[ 'default' ] : null; |
|
102 | + $auto_increment = isset( $args[ 'auto_increment' ] ) && $args[ 'auto_increment' ] === $old_col_name; |
|
103 | + $unique = isset( $col_info[ 'unique' ] ); |
|
104 | + $comment = isset( $col_info[ 'comment' ] ) ? $col_info[ 'comment' ] : null; |
|
105 | + $target_table = isset( $col_info[ 'target_table' ] ) ? $db->get_table( $col_info[ 'target_table' ] ) : null; |
|
106 | 106 | |
107 | 107 | // Change existing or insert new column. |
108 | 108 | $altered = false; |
109 | 109 | if ( $old_col_name ) { |
110 | - $col = $table->get_column( $col_info['old_name'] ); |
|
110 | + $col = $table->get_column( $col_info[ 'old_name' ] ); |
|
111 | 111 | if ( $col instanceof Column ) { |
112 | 112 | $col->alter( $new_col_name, $xtype, $size, $nullable, $default, $auto_increment, $unique, $comment, $target_table, $previous_column_name ); |
113 | 113 | $altered = true; |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | public function delete( $args ) { |
138 | 138 | $template = new Template( 'table/delete.html' ); |
139 | 139 | $db = new Database( $this->wpdb ); |
140 | - $table = $db->get_table( $args['table'] ); |
|
140 | + $table = $db->get_table( $args[ 'table' ] ); |
|
141 | 141 | |
142 | 142 | // Ask for confirmation. |
143 | - if ( ! isset( $args['confirm_deletion'] ) ) { |
|
143 | + if ( ! isset( $args[ 'confirm_deletion' ] ) ) { |
|
144 | 144 | $template->table = $table; |
145 | 145 | return $template->render(); |
146 | 146 | } |
@@ -144,33 +144,33 @@ discard block |
||
144 | 144 | protected function parse_info( $info ) { |
145 | 145 | |
146 | 146 | // Name. |
147 | - $this->name = $info['Field']; |
|
147 | + $this->name = $info[ 'Field' ]; |
|
148 | 148 | |
149 | 149 | // Type. |
150 | - $this->parse_type( $info['Type'] ); |
|
150 | + $this->parse_type( $info[ 'Type' ] ); |
|
151 | 151 | |
152 | 152 | // Default. |
153 | - $this->default_value = $info['Default']; |
|
153 | + $this->default_value = $info[ 'Default' ]; |
|
154 | 154 | |
155 | 155 | // Primary key. |
156 | - if ( 'PRI' === strtoupper( $info['Key'] ) ) { |
|
156 | + if ( 'PRI' === strtoupper( $info[ 'Key' ] ) ) { |
|
157 | 157 | $this->is_primary_key = true; |
158 | - if ( 'auto_increment' === $info['Extra'] ) { |
|
158 | + if ( 'auto_increment' === $info[ 'Extra' ] ) { |
|
159 | 159 | $this->is_auto_increment = true; |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Unique key. |
164 | - $this->is_unique = ( 'UNI' === strtoupper( $info['Key'] ) ); |
|
164 | + $this->is_unique = ( 'UNI' === strtoupper( $info[ 'Key' ] ) ); |
|
165 | 165 | |
166 | 166 | // Comment. |
167 | - $this->comment = $info['Comment']; |
|
167 | + $this->comment = $info[ 'Comment' ]; |
|
168 | 168 | |
169 | 169 | // Collation. |
170 | - $this->collation = $info['Collation']; |
|
170 | + $this->collation = $info[ 'Collation' ]; |
|
171 | 171 | |
172 | 172 | // Is this column NULL? |
173 | - $this->nullable = ( 'YES' === $info['Null'] ); |
|
173 | + $this->nullable = ( 'YES' === $info[ 'Null' ] ); |
|
174 | 174 | |
175 | 175 | // Is this a foreign key? |
176 | 176 | if ( in_array( $this->get_name(), $this->get_table()->get_foreign_key_names(), true ) ) { |
@@ -309,14 +309,14 @@ discard block |
||
309 | 309 | public function get_xtype() { |
310 | 310 | $xtypes = self::get_xtypes(); |
311 | 311 | if ( $this->is_foreign_key() ) { |
312 | - return $xtypes['fk']; |
|
312 | + return $xtypes[ 'fk' ]; |
|
313 | 313 | } |
314 | 314 | if ( $this->is_boolean() ) { |
315 | - return $xtypes['boolean']; |
|
315 | + return $xtypes[ 'boolean' ]; |
|
316 | 316 | } |
317 | 317 | // Otherwise fall back on the first xtype with a matching type. |
318 | 318 | foreach ( $xtypes as $xtype ) { |
319 | - if ( strtoupper( $this->get_type() ) === $xtype['type'] ) { |
|
319 | + if ( strtoupper( $this->get_type() ) === $xtype[ 'type' ] ) { |
|
320 | 320 | return $xtype; |
321 | 321 | } |
322 | 322 | } |
@@ -516,22 +516,22 @@ discard block |
||
516 | 516 | $this->scale = null; |
517 | 517 | $this->options = null; |
518 | 518 | if ( preg_match( $varchar_pattern, $type_string, $matches ) ) { |
519 | - $this->type = $matches[1]; |
|
520 | - $this->size = (int) $matches[2]; |
|
519 | + $this->type = $matches[ 1 ]; |
|
520 | + $this->size = ( int ) $matches[ 2 ]; |
|
521 | 521 | } elseif ( preg_match( $decimal_pattern, $type_string, $matches ) ) { |
522 | 522 | $this->type = 'decimal'; |
523 | - $this->precision = $matches[1]; |
|
524 | - $this->scale = $matches[2]; |
|
523 | + $this->precision = $matches[ 1 ]; |
|
524 | + $this->scale = $matches[ 2 ]; |
|
525 | 525 | } elseif ( preg_match( $float_pattern, $type_string, $matches ) ) { |
526 | 526 | $this->type = 'float'; |
527 | - $this->precision = $matches[1]; |
|
528 | - $this->scale = $matches[2]; |
|
527 | + $this->precision = $matches[ 1 ]; |
|
528 | + $this->scale = $matches[ 2 ]; |
|
529 | 529 | } elseif ( preg_match( $integer_pattern, $type_string, $matches ) ) { |
530 | - $this->type = $matches[1]; |
|
531 | - $this->size = (int) $matches[2]; |
|
530 | + $this->type = $matches[ 1 ]; |
|
531 | + $this->size = ( int ) $matches[ 2 ]; |
|
532 | 532 | } elseif ( preg_match( $enum_pattern, $type_string, $matches ) ) { |
533 | - $this->type = $matches[1]; |
|
534 | - $values = explode( "','", $matches[2] ); |
|
533 | + $this->type = $matches[ 1 ]; |
|
534 | + $values = explode( "','", $matches[ 2 ] ); |
|
535 | 535 | $this->options = array_combine( $values, $values ); |
536 | 536 | } |
537 | 537 | } |
@@ -542,14 +542,14 @@ discard block |
||
542 | 542 | * @return string |
543 | 543 | */ |
544 | 544 | public function __toString() { |
545 | - $pk = ($this->is_primary_key) ? ' PK' : ''; |
|
546 | - $auto = ($this->is_auto_increment) ? ' AI' : ''; |
|
545 | + $pk = ( $this->is_primary_key ) ? ' PK' : ''; |
|
546 | + $auto = ( $this->is_auto_increment ) ? ' AI' : ''; |
|
547 | 547 | if ( $this->references ) { |
548 | 548 | $ref = ' References ' . $this->references . '.'; |
549 | 549 | } else { |
550 | 550 | $ref = ''; |
551 | 551 | } |
552 | - $size = ($this->size > 0) ? "($this->size)" : ''; |
|
552 | + $size = ( $this->size > 0 ) ? "($this->size)" : ''; |
|
553 | 553 | return $this->name . ' ' . strtoupper( $this->type ) . $size . $pk . $auto . $ref; |
554 | 554 | } |
555 | 555 | |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | public function get_current_column_definition() { |
562 | 562 | return self::get_column_definition( |
563 | 563 | $this->get_name(), |
564 | - $this->get_xtype()['name'], |
|
564 | + $this->get_xtype()[ 'name' ], |
|
565 | 565 | $this->get_size(), |
566 | 566 | $this->nullable(), |
567 | 567 | $this->get_default(), |
@@ -590,14 +590,14 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function alter( $new_name = null, $xtype_name = null, $size = null, $nullable = null, $default = null, $auto_increment = null, $unique = null, $comment = null, $target_table = null, $after = null ) { |
592 | 592 | // Any that have not been set explicitely should be unchanged. |
593 | - $new_name = ! is_null( $new_name ) ? (string) $new_name : $this->get_name(); |
|
594 | - $xtype_name = ! is_null( $xtype_name ) ? (string) $xtype_name : $this->get_xtype()['name']; |
|
593 | + $new_name = ! is_null( $new_name ) ? ( string ) $new_name : $this->get_name(); |
|
594 | + $xtype_name = ! is_null( $xtype_name ) ? ( string ) $xtype_name : $this->get_xtype()[ 'name' ]; |
|
595 | 595 | $size = ! is_null( $size ) ? $size : $this->get_size(); |
596 | - $nullable = ! is_null( $nullable ) ? (boolean) $nullable : $this->nullable(); |
|
597 | - $default = ! is_null( $default ) ? (string) $default : $this->get_default(); |
|
598 | - $auto_increment = ! is_null( $auto_increment ) ? (boolean) $auto_increment : $this->is_auto_increment(); |
|
599 | - $unique = ! is_null( $unique ) ? (boolean) $unique : $this->is_unique(); |
|
600 | - $comment = ! is_null( $comment ) ? (string) $comment : $this->get_comment(); |
|
596 | + $nullable = ! is_null( $nullable ) ? ( boolean ) $nullable : $this->nullable(); |
|
597 | + $default = ! is_null( $default ) ? ( string ) $default : $this->get_default(); |
|
598 | + $auto_increment = ! is_null( $auto_increment ) ? ( boolean ) $auto_increment : $this->is_auto_increment(); |
|
599 | + $unique = ! is_null( $unique ) ? ( boolean ) $unique : $this->is_unique(); |
|
600 | + $comment = ! is_null( $comment ) ? ( string ) $comment : $this->get_comment(); |
|
601 | 601 | $target_table = ! is_null( $target_table ) ? $target_table : $this->get_referenced_table(); |
602 | 602 | |
603 | 603 | // Check the current column definition. |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | if ( $this->is_unique() ) { |
613 | 613 | $sql = 'SHOW INDEXES FROM `' . $table->get_name() . '` WHERE Column_name LIKE "' . $this->get_name() . '"'; |
614 | 614 | foreach ( $wpdb->get_results( $sql, ARRAY_A ) as $index ) { |
615 | - $sql = "DROP INDEX `" . $index['Key_name'] . "` ON `" . $table->get_name() . "`"; |
|
615 | + $sql = "DROP INDEX `" . $index[ 'Key_name' ] . "` ON `" . $table->get_name() . "`"; |
|
616 | 616 | $wpdb->query( $sql ); |
617 | 617 | } |
618 | 618 | } |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | public static function get_column_definition( $name, $xtype_name = null, $size = null, $nullable = true, $default = null, $auto_increment = null, $unique = null, $comment = null, $target_table = null, $after = null ) { |
671 | 671 | // Type. |
672 | 672 | $xtypes = self::get_xtypes(); |
673 | - $xtype = ( isset( $xtypes[ $xtype_name ] ) ) ? $xtypes[ $xtype_name ] : $xtypes['text_short']; |
|
674 | - $type_str = $xtype['type']; |
|
673 | + $xtype = ( isset( $xtypes[ $xtype_name ] ) ) ? $xtypes[ $xtype_name ] : $xtypes[ 'text_short' ]; |
|
674 | + $type_str = $xtype[ 'type' ]; |
|
675 | 675 | // Size or options. |
676 | 676 | $size_str = ''; |
677 | - if ( is_numeric( $xtype['sizes'] ) && $xtype['sizes'] > 0 ) { |
|
678 | - $size_str = '(' . ( $size ? : 50 ) . ')'; |
|
677 | + if ( is_numeric( $xtype[ 'sizes' ] ) && $xtype[ 'sizes' ] > 0 ) { |
|
678 | + $size_str = '(' . ( $size ?: 50 ) . ')'; |
|
679 | 679 | } |
680 | 680 | if ( 'enum' === $xtype_name ) { |
681 | 681 | // If not already wraped in quotes, explode and quote each option. |
@@ -688,14 +688,14 @@ discard block |
||
688 | 688 | $size_str = '(1)'; |
689 | 689 | } |
690 | 690 | // Nullable. |
691 | - $null_str = (true === $nullable) ? 'NULL' : 'NOT NULL'; |
|
691 | + $null_str = ( true === $nullable ) ? 'NULL' : 'NOT NULL'; |
|
692 | 692 | // Default. |
693 | 693 | $default_str = ''; |
694 | 694 | if ( 'text_long' !== $xtype_name ) { |
695 | 695 | $default_str = ! empty( $default ) ? "DEFAULT '$default'" : ( $nullable ? 'DEFAULT NULL' : '' ); |
696 | 696 | } |
697 | 697 | $auto_increment_str = ''; |
698 | - if ( $auto_increment && 'integer' === $xtype['name'] ) { |
|
698 | + if ( $auto_increment && 'integer' === $xtype[ 'name' ] ) { |
|
699 | 699 | $auto_increment_str = 'AUTO_INCREMENT'; |
700 | 700 | } |
701 | 701 | $unique_str = $unique ? 'UNIQUE' : ''; |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | . ' (`' . $pk_col->get_name() . '`)'; |
717 | 717 | $type_str = $pk_col->get_type(); |
718 | 718 | $size_str = '(' . $pk_col->get_size() . ')'; |
719 | - $sign_str = ($pk_col->is_unsigned()) ? 'UNSIGNED' : ''; |
|
719 | + $sign_str = ( $pk_col->is_unsigned() ) ? 'UNSIGNED' : ''; |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | // Put it all together. |