- 
                Notifications
    You must be signed in to change notification settings 
- Fork 242
Better channel restoration for local dev with content proxying #5046
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
base: unstable
Are you sure you want to change the base?
Changes from all commits
d9e638e
              a8e64db
              8557480
              43eb687
              586f089
              16638f6
              06a5f9c
              4b78507
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -2,28 +2,65 @@ | |
|  | ||
| from django.core.management.base import BaseCommand | ||
|  | ||
| from contentcuration.utils.import_tools import import_channel | ||
| from contentcuration.utils.import_tools import ImportManager | ||
|  | ||
| logger = logging.getLogger('command') | ||
| logger = logging.getLogger("command") | ||
|  | ||
|  | ||
| class Command(BaseCommand): | ||
| """ | ||
| This command is used to restore a channel from another Studio instance. This is for | ||
| development purposes only and should not be used in production. | ||
| """ | ||
|  | ||
| def add_arguments(self, parser): | ||
| # ID of channel to read data from | ||
| parser.add_argument('source_id', type=str) | ||
| parser.add_argument("source_id", type=str) | ||
|  | ||
| # ID of channel to write data to (can be same as source channel) | ||
| parser.add_argument('--target', help='restore channel db to TARGET CHANNEL ID') | ||
| parser.add_argument('--download-url', help='where to download db from') | ||
| parser.add_argument('--editor', help='add user as editor to channel') | ||
| parser.add_argument( | ||
| "--target", | ||
| help="A different channel ID for which to restore the channel. If not provided, the source channel ID will be used.", | ||
| ) | ||
| parser.add_argument( | ||
| "--source-url", | ||
| default="http://localhost:8080", | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. port  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it is. The default functionality before my changes had this command attempt to load from the local instance, so I kept that, but having this be the nginx route means that the logic for fetching the channel's SQLite database can be the same as non-local (production) | ||
| help="Studio instance from which to download the channel DB or content files", | ||
| ) | ||
| parser.add_argument("--token", help="API token for the Studio instance") | ||
| parser.add_argument( | ||
| "--editor", | ||
| default="[email protected]", | ||
| help="Add user as editor to channel with provided email address", | ||
| ) | ||
| parser.add_argument( | ||
| "--download-content", | ||
| action="store_true", | ||
| default=False, | ||
| help="Whether to download content files", | ||
| ) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We surely needed this. Thanks for adding it ❤️ | ||
| parser.add_argument( | ||
| "--public", | ||
| action="store_true", | ||
| default=False, | ||
| help="Whether to make the channel public", | ||
| ) | ||
| parser.add_argument( | ||
| "--publish", | ||
| action="store_true", | ||
| default=False, | ||
| help="Whether to publish the channel after restoration", | ||
| ) | ||
|  | ||
| def handle(self, *args, **options): | ||
| # Set up variables for restoration process | ||
| logger.info("\n\n********** STARTING CHANNEL RESTORATION **********") | ||
| source_id = options['source_id'] | ||
| target_id = options.get('target') or source_id | ||
| download_url = options.get('download_url') | ||
| editor = options.get('editor') | ||
|  | ||
| import_channel(source_id, target_id, download_url, editor, logger=logger) | ||
| manager = ImportManager( | ||
| options["source_url"], | ||
| options["source_id"], | ||
| target_id=options.get("target"), | ||
| editor=options.get("editor"), | ||
| public=options.get("public"), | ||
| publish=options.get("publish"), | ||
| token=options.get("token"), | ||
| download_content=options.get("download_content"), | ||
| ) | ||
| manager.run() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an
echohere to tell the actual URL to access on, to make sure people ignore the logging from the django runserver?