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

Include assets inside B/R #12627

Closed
giohappy opened this issue Oct 3, 2024 · 2 comments · Fixed by #12628
Closed

Include assets inside B/R #12627

giohappy opened this issue Oct 3, 2024 · 2 comments · Fixed by #12628
Assignees
Milestone

Comments

@giohappy
Copy link
Contributor

giohappy commented Oct 3, 2024

The assets (ASSETS_FOLDER) folder must be part of the B/R.
The logic will be the same as for the media folder.
DRY, transform the logic in a common method, bot for the backup and restore.

@etj
Copy link
Contributor

etj commented Oct 3, 2024

Two more tasks here, that can be implemented later:

  • LocalAssets may refer either to managed files (that is files inside the ASSETS_FOLDER) and unmanaged files. If Assets with unmanaged files are present, they should at least be logged as warning, since the restores assets may not work if the unmanaged files are not found.
  • When restoring Assets, if the target ASSETS_FOLDER is different than the source one, the root of the file's location should be replaced.

@mattiagiupponi
Copy link
Contributor

mattiagiupponi commented Oct 7, 2024

Restoring assets_root will be done in the future, now it migh raise other issues related to the heuristic replace.
A possible solution is to save the original .env file during the backup and access it during the restore.
A possible heuristic solutions could be the following:

logger.info("*** Update Assets path...")
for instance in LocalAsset.objects.iterator():
    should_be_updated = any(settings.ASSETS_ROOT not in loc for loc in instance.location)
    if should_be_updated:
        new_assets = []
        for loc in instance.location:
            if settings.ASSETS_ROOT not in loc:
                new_assets.append(loc.replace(os.path.dirname(os.path.dirname(loc)), ttings.ASSETS_ROOT))
            else:
                new_assets.append(loc)
        instance.location = new_assets
        instance.save()
logger.info("*** Assets path updated...")

github-actions bot pushed a commit that referenced this issue Oct 7, 2024
* [Fixes #12627] Include assets inside B/R
* [Fixes #12627] force localasset in get_link_url
* [Fixes #12627] fix pr comments
* [Fixes #12627] add todo for assets_root replace
* [Fixes #12627] change utils assets_root name

(cherry picked from commit 33be915)
mattiagiupponi added a commit that referenced this issue Oct 7, 2024
* [Fixes #12627] Include assets inside B/R
* [Fixes #12627] force localasset in get_link_url
* [Fixes #12627] fix pr comments
* [Fixes #12627] add todo for assets_root replace
* [Fixes #12627] change utils assets_root name

(cherry picked from commit 33be915)

Co-authored-by: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants