Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x]: Control Panel not updated after database restore #11327

Closed
bencresty opened this issue May 26, 2022 · 8 comments
Closed

[3.x]: Control Panel not updated after database restore #11327

bencresty opened this issue May 26, 2022 · 8 comments

Comments

@bencresty
Copy link

bencresty commented May 26, 2022

What happened?

Description

When restoring a database with php craft db/restore {dbfile} the database gets restored alright, but the CMS is still showing entries that were removed in the restored database file and so should be gone. This was not caused by a browser cache.
A Craft clear cache (not sure which, I used php craft clear-caches/all which did the job) was needed after the database restore call to update the CMS view. IMO the restore database command should automatically refresh the Control Panel/CMS after a db restore.

Steps to reproduce

  1. Have a production environment and a development environment up with using the same database (with some entries)
  2. Open the Control Panel on the production environment and remove one or more entries
  3. Backup the database from the production environment to a local sql-file
  4. Rename the sql file to use the name of the development database
  5. Open the development control panel and see all entries are still there
  6. Call the craft db/restore-command on the development environment from the command line to import the renamed production db sql file to use in the development environment
  7. ctrl-F5 in the browser to refresh the development Control Panel
  8. See that the removed entries are still there, eventhough the database is imported from the production environment where some entries were removed (also still visible when removing cookies etc. in the browser)
  9. Clear all Craft caches on development: php craft clear-caches/all
  10. ctrl-F5 in the browser to refresh the development Control Panel
  11. See that now the changed database is actually visually visible, so the removed entries are gone now in the control panel

Notes:

  • The removed entries were set to 'offline' before they were removed and the database was backupped.
  • It's a multi locales/sites setup

Expected behavior

Control panel should always be in sync with the actual database.

Actual behavior

Control panel is not representing the actual database state after a db restore

Craft CMS version

3.7.43

PHP version

8.0.12

Operating system and version

Windows 10

Database type and version

MariaDb 10.4.21

Image driver and version

Installed plugins and versions

@brandonkelly
Copy link
Member

Just added a Clear data caches? prompt to the end of the db/restore command for the next release, which will call clear-caches/data internally if responded with yes (the default).

@bencresty
Copy link
Author

@brandonkelly Great solution for everybody. Thanks for the quick action

@bencresty
Copy link
Author

@brandonkelly Uh... one question tho now that I think about it...

How can we say yes to this popup question when the restore command is being called from a script (we're using it like that to deploy/update databases to a server)?

@brandonkelly
Copy link
Member

@bencresty You can just start calling clear-caches/data immediately after, from the same script.

@bencresty
Copy link
Author

bencresty commented May 30, 2022

@brandonkelly thanks. I understand that in that case we can use the clear cache command after the restore db command. But isn't the restore database in that case still waiting for an anwer to the clear caches question? Or will there be an optional parameter to turn that question off or even pre-answer it?

@brandonkelly
Copy link
Member

@bencresty It was just added as a convenience for when the command is being run interactively. If it’s not interactive, it’s not considered.

@brandonkelly
Copy link
Member

Craft 3.7.44 and 4.0.4 are out now with that change.

@bencresty
Copy link
Author

@brandonkelly allright, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants