Commit ce0ba337 authored by Michael Iseard's avatar Michael Iseard
Browse files

Move migrations to separate function

parent b2eb9f4d
......@@ -40,64 +40,74 @@ class ActivatorService {
$twig->init();
if ( $old_version ) {
self::run_migrations($old_version);
}
if ( version_compare( $old_version, '2.1.1', '<' ) ) {
$logger->info( 'Upgrading to version 2.1.1', [ 'previous_version' => $old_version ] );
Settings::remove_setting( 'action_scheduler' );
}
if ( version_compare( $old_version, '2.2.0', '<' ) ) {
$link = Settings::get_setting( 'privacy_link' );
Settings::remove_setting( 'subscription_enabled' );
if ( $link ) {
Settings::update_setting( 'terms_link', $link );
Settings::remove_setting( 'privacy_link' );
}
}
if ( version_compare( $old_version, '2.3.0', '<' ) ) {
global $wpdb;
// Rename setting
$transaction_table = TransactionEntity::get_table_name();
$wpdb->query( "ALTER TABLE $transaction_table RENAME COLUMN `campaign_label` TO `campaign_id`" );
Settings::update_setting( 'show_intro', 1 );
// Apply mode to Donors
$donor_table = DonorEntity::get_table_name();
$wpdb->query("ALTER TABLE $donor_table ADD `mode` VARCHAR(45) NOT NULL");
$mapper = new MapperService( DonorEntity::class );
$donors = $mapper->get_all_by();
/** @var DonorEntity $donor */
foreach ( $donors as $donor ) {
$transactions = $donor->get_transactions();
if ( $transactions ) {
$donor->set_fields( [ 'mode' => $transactions[0]->mode ] );
}
$mapper->save( $donor );
}
}
self::create_donors_table();
self::create_transactions_table();
self::create_subscriptions_table();
self::set_defaults();
if ( version_compare( $old_version, '2.3.2', '<' ) ) {
$logger->info( 'Kudos Donations plugin activated' );
}
// Setting now replaced by 'theme_colors'
$old_color = Settings::get_setting('theme_color');
$new_colors = Settings::get_setting('theme_colors');
$new_colors['primary'] = $old_color;
Settings::update_setting('theme_colors', $new_colors);
Settings::remove_setting( 'theme_color' );
/**
* Run migrations if upgrading
*
* @param string $old_version
*
* @since 2.3.2
*/
public static function run_migrations( string $old_version ) {
if ( version_compare( $old_version, '2.1.1', '<' ) ) {
Settings::remove_setting( 'action_scheduler' );
}
if ( version_compare( $old_version, '2.2.0', '<' ) ) {
$link = Settings::get_setting( 'privacy_link' );
Settings::remove_setting( 'subscription_enabled' );
if ( $link ) {
Settings::update_setting( 'terms_link', $link );
Settings::remove_setting( 'privacy_link' );
}
}
if ( version_compare( $old_version, '2.3.0', '<' ) ) {
global $wpdb;
// Rename setting
$transaction_table = TransactionEntity::get_table_name();
$wpdb->query( "ALTER TABLE $transaction_table RENAME COLUMN `campaign_label` TO `campaign_id`" );
Settings::update_setting( 'show_intro', 1 );
// Apply mode to Donors
$donor_table = DonorEntity::get_table_name();
$wpdb->query("ALTER TABLE $donor_table ADD `mode` VARCHAR(45) NOT NULL");
$mapper = new MapperService( DonorEntity::class );
$donors = $mapper->get_all_by();
/** @var DonorEntity $donor */
foreach ( $donors as $donor ) {
$transactions = $donor->get_transactions();
if ( $transactions ) {
$donor->set_fields( [ 'mode' => $transactions[0]->mode ] );
}
$mapper->save( $donor );
}
}
self::create_donors_table();
self::create_transactions_table();
self::create_subscriptions_table();
self::set_defaults();
if ( version_compare( $old_version, '2.3.2', '<' ) ) {
$logger->info( 'Kudos Donations plugin activated' );
// Setting now replaced by 'theme_colors'
$old_color = Settings::get_setting('theme_color');
$new_colors = Settings::get_setting('theme_colors');
$new_colors['primary'] = $old_color;
Settings::update_setting('theme_colors', $new_colors);
Settings::remove_setting( 'theme_color' );
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment