src/WPametu/DB/TableBuilder.php
private function db_update( $file ){
        require $file;
        if( isset($table) ){
            // Test required members
            $config = wp_parse_args($table, [
                'name' => str_replace('.php', '', basename($file)),
                'version' => false,
                'engine' => Engine::INNODB,
                'columns' => false,
                'primary_key' => [],
                'indexes' => [],
                'unique' => [],
                'fulltext' => [],
            ]);
            $table_name = $config['name'];
            if( $config['name'] && $config['version'] && $config['indexes'] ){
                if( $this->need_update($table_name, $config['version']) ){
                    // Add prefix
                    $config['name'] = $this->db->prefix.$config['name'];
                    // Need update. Let's make query!
                    $query = $this->make_query($config);
                    if( !function_exists('dbDelta') ){
                        require_once ABSPATH . "wp-admin/includes/upgrade.php";
                    }
                    // Do dbDelta
                    $result = dbDelta($query);
                    // Return message
                    if( isset( $result[$config['name']] ) ){
                        $message = sprintf('<code>%s</code> created.', $config['name']);
                    }else{
                        $message = sprintf('<code>%s</code> updated.', $config['name']);
                    }
                    if( !empty($this->db->last_error) ){
                        $message .= sprintf(' <small>(Error: %s)</small>', $this->db->last_error);
                    }
                    // Check table existence
                    if( $this->table_exists($config['name']) ){
                        update_option($this->option_key, array_merge($this->option, [
                            $table_name => $config['version'],
                        ]));
                    }else{
                        $message = sprintf('Failed to create or update <code>%s</code>', $config['name']);
                    }
                    return $message;
                }
            }else{
                throw new \Exception(sprintf('Config file %s is wrong.', $file));
            }
        }else{
            throw new \Exception(sprintf('Config file %s must be PHP Array format.', $file));
        }
        return '';
    }
private function db_update( $file ){
        require $file;
        if( isset($table) ){
            // Test required members
            $config = wp_parse_args($table, [
                'name' => str_replace('.php', '', basename($file)),
                'version' => false,
                'engine' => Engine::INNODB,
                'columns' => false,
                'primary_key' => [],
                'indexes' => [],
                'unique' => [],
                'fulltext' => [],
            ]);
            $table_name = $config['name'];
            if( $config['name'] && $config['version'] && $config['indexes'] ){
                if( $this->need_update($table_name, $config['version']) ){
                    // Add prefix
                    $config['name'] = $this->db->prefix.$config['name'];
                    // Need update. Let's make query!
                    $query = $this->make_query($config);
                    if( !function_exists('dbDelta') ){
                        require_once ABSPATH . "wp-admin/includes/upgrade.php";
                    }
                    // Do dbDelta
                    $result = dbDelta($query);
                    // Return message
                    if( isset( $result[$config['name']] ) ){
                        $message = sprintf('<code>%s</code> created.', $config['name']);
                    }else{
                        $message = sprintf('<code>%s</code> updated.', $config['name']);
                    }
                    if( !empty($this->db->last_error) ){
                        $message .= sprintf(' <small>(Error: %s)</small>', $this->db->last_error);
                    }
                    // Check table existence
                    if( $this->table_exists($config['name']) ){
                        update_option($this->option_key, array_merge($this->option, [
                            $table_name => $config['version'],
                        ]));
                    }else{
                        $message = sprintf('Failed to create or update <code>%s</code>', $config['name']);
                    }
                    return $message;
                }
            }else{
                throw new \Exception(sprintf('Config file %s is wrong.', $file));
            }
        }else{
            throw new \Exception(sprintf('Config file %s must be PHP Array format.', $file));
        }
        return '';
    }
private function db_update ( $ file ) { require $ file ; if ( isset ( $ table ) ) { // Test required members $ config = wp_parse_args ( $ table , [ 'name' => str_replace ( '.php' , '' , basename ( $ file ) ) , 'version' => false , 'engine' => Engine :: INNODB , 'columns' => false , 'primary_key' => [ ] , 'indexes' => [ ] , 'unique' => [ ] , 'fulltext' => [ ] , ] ) ; $ table_name = $ config [ 'name' ] ; if ( $ config [ 'name' ] && $ config [ 'version' ] && $ config [ 'indexes' ] ) { if ( $ this -> need_update ( $ table_name , $ config [ 'version' ] ) ) { // Add prefix $ config [ 'name' ] = $ this -> db -> prefix . $ config [ 'name' ] ; // Need update. Let's make query! $ query = $ this -> make_query ( $ config ) ; if ( ! function_exists ( 'dbDelta' ) ) { require_once ABSPATH . "wp-admin/includes/upgrade.php" ; } // Do dbDelta $ result = dbDelta ( $ query ) ; // Return message if ( isset ( $ result [ $ config [ 'name' ] ] ) ) { $ message = sprintf ( '<code>%s</code> created.' , $ config [ 'name' ] ) ; } else { $ message = sprintf ( '<code>%s</code> updated.' , $ config [ 'name' ] ) ; } if ( ! empty ( $ this -> db -> last_error ) ) { $ message .= sprintf ( ' <small>(Error: %s)</small>' , $ this -> db -> last_error ) ; } // Check table existence if ( $ this -> table_exists ( $ config [ 'name' ] ) ) { update_option ( $ this -> option_key , array_merge ( $ this -> option , [ $ table_name => $ config [ 'version' ] , ] ) ) ; } else { $ message = sprintf ( 'Failed to create or update <code>%s</code>' , $ config [ 'name' ] ) ; } return $ message ; } } else { throw new \ Exception ( sprintf ( 'Config file %s is wrong.' , $ file ) ) ; } } else { throw new \ Exception ( sprintf ( 'Config file %s must be PHP Array format.' , $ file ) ) ; } return '' ; }
Update db if possible

@param string $file path to config
@return string
@throws \Exception
Update db if possible