startSetup(); $this->applyUpgradeFunctions( $setup, $context ); $setup->endSetup(); } private function getUpgradeFunctions( $low_version = '1.0.0' ) { $methods = get_class_methods( $this ); foreach ( $methods as $key => $method ) { if ( preg_match( '/^upgrade_(.+)$/i', $method, $matches ) ) { if ( version_compare( $low_version, $matches[ 1 ], '<' ) ) { continue; } } unset( $methods[ $key ] ); } $methods = array_filter( $methods ); $methods = array_unique( $methods ); sort( $methods ); return $methods; } private function applyUpgradeFunctions( SchemaSetupInterface $setup, ModuleContextInterface $context ) { $methods = $this->getUpgradeFunctions( $context->getVersion() ); foreach ( $methods as $method ) { call_user_func_array( [ $this, $method ], [ $setup, $context ] ); } } public function upgrade_1_0_1( SchemaSetupInterface $setup, ModuleContextInterface $context ) { $tables = [ 'olegnax_bannerslider_group' => [ 'identifier' => [ 'type' => Table::TYPE_TEXT, 'size' => 255, 'nullable' => false, 'default' => '', 'comment' => 'Identifier from v1.0.1' ], ], ]; $connection = $setup->getConnection(); foreach ( $tables as $table_name => $table ) { $_table = $setup->getTable( $table_name ); foreach ( $table as $field_name => $field ) { foreach ( [ 'type' => Table::TYPE_INTEGER, 'size' => null, 'comment' => '', ] as $attr_name => $attr ) { if ( !array_key_exists( $attr_name, $field ) ) { $field[ $attr_name ] = $attr; } } $connection->addColumn( $_table, $field_name, $field ); } } } }