Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Iseard
Kudos-Donations
Commits
ce0ba337
Commit
ce0ba337
authored
Feb 04, 2021
by
Michael Iseard
Browse files
Move migrations to separate function
parent
b2eb9f4d
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/Service/ActivatorService.php
View file @
ce0ba337
...
@@ -40,64 +40,74 @@ class ActivatorService {
...
@@ -40,64 +40,74 @@ class ActivatorService {
$twig
->
init
();
$twig
->
init
();
if
(
$old_version
)
{
if
(
$old_version
)
{
self
::
run_migrations
(
$old_version
);
}
if
(
version_compare
(
$old_version
,
'2.1.1'
,
'<'
)
)
{
self
::
create_donors_table
();
$logger
->
info
(
'Upgrading to version 2.1.1'
,
[
'previous_version'
=>
$old_version
]
);
self
::
create_transactions_table
();
Settings
::
remove_setting
(
'action_scheduler'
);
self
::
create_subscriptions_table
();
}
self
::
set_defaults
();
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
);
}
}
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'
);
* Run migrations if upgrading
$new_colors
=
Settings
::
get_setting
(
'theme_colors'
);
*
$new_colors
[
'primary'
]
=
$old_color
;
* @param string $old_version
Settings
::
update_setting
(
'theme_colors'
,
$new_colors
);
*
Settings
::
remove_setting
(
'theme_color'
);
* @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
();
if
(
version_compare
(
$old_version
,
'2.3.2'
,
'<'
)
)
{
self
::
create_transactions_table
();
self
::
create_subscriptions_table
();
self
::
set_defaults
();
$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'
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment