Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
Wp Migrations
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
Library
Wp Migrations
Commits
c3fb21d0
Verified
Commit
c3fb21d0
authored
1 year ago
by
Bartek Jaskulski
Browse files
Options
Downloads
Patches
Plain Diff
fix: respect migration status and break loop on error
Signed-off-by:
Bart Jaskulski
<
bjaskulski@protonmail.com
>
parent
faa9ebc0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/WpdbMigrator.php
+21
-11
21 additions, 11 deletions
src/WpdbMigrator.php
with
21 additions
and
11 deletions
src/WpdbMigrator.php
+
21
−
11
View file @
c3fb21d0
...
...
@@ -108,8 +108,21 @@ class WpdbMigrator implements Migrator {
}
$this
->
logger
->
info
(
'DB update start'
);
$current_version
=
$this
->
get_current_version
();
try
{
$this
->
do_migrate
();
}
catch
(
\Throwable
$e
)
{
// @phpstan-ignore-next-line
$error_msg
=
sprintf
(
'Error while upgrading a database: %s'
,
$this
->
wpdb
->
last_error
);
$this
->
logger
->
error
(
$error_msg
);
trigger_error
(
esc_html
(
$error_msg
),
E_USER_WARNING
);
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
}
$this
->
logger
->
info
(
'DB update finished'
);
}
private
function
do_migrate
():
void
{
$current_version
=
$this
->
get_current_version
();
foreach
(
$this
->
migrations_repository
->
get_migrations
()
as
$migration
)
{
if
(
$this
->
comparator
->
compare
(
...
...
@@ -117,21 +130,18 @@ class WpdbMigrator implements Migrator {
$this
->
get_current_version
()
)
>
0
)
{
$this
->
logger
->
info
(
sprintf
(
'DB update %s:%s'
,
$current_version
,
$migration
->
get_version
()
)
);
try
{
$migration
->
get_migration
()
->
up
();
$success
=
$migration
->
get_migration
()
->
up
();
if
(
$success
)
{
$this
->
logger
->
info
(
sprintf
(
'DB update %s:%s -> '
,
$current_version
,
$migration
->
get_version
()
)
.
'OK'
);
update_option
(
$this
->
option_name
,
(
string
)
$migration
->
get_version
(),
true
);
}
catch
(
\Throwable
$e
)
{
// @phpstan-ignore-next-line
$error_msg
=
sprintf
(
'Error while upgrading a database: %s'
,
$this
->
wpdb
->
last_error
);
$this
->
logger
->
error
(
$error_msg
);
trigger_error
(
$error_msg
,
E_USER_WARNING
);
// phpcs:ignore
}
else
{
throw
new
\RuntimeException
();
}
}
}
$this
->
logger
->
info
(
'DB update finished'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment