|
14 | 14 | import requests |
15 | 15 | from django.core.management import call_command |
16 | 16 | from django.http import Http404 |
| 17 | +from django.db import connections |
17 | 18 | from django.utils.translation import ugettext as _ |
18 | 19 | from kolibri.content.models import ChannelMetadataCache |
19 | 20 | from kolibri.content.utils.channels import get_mounted_drives_with_channel_info |
@@ -143,37 +144,53 @@ def localdrive(self, request): |
143 | 144 |
|
144 | 145 |
|
145 | 146 | def _networkimport(channel_id, update_progress=None): |
146 | | - call_command("importchannel", "network", channel_id) |
| 147 | + call_command( |
| 148 | + "importchannel", |
| 149 | + "network", |
| 150 | + channel_id, |
| 151 | + update_progress=update_progress) |
147 | 152 | call_command( |
148 | 153 | "importcontent", |
149 | 154 | "network", |
150 | 155 | channel_id, |
151 | 156 | update_progress=update_progress) |
152 | | - |
| 157 | + connections.close_all() # close all DB connections (FIX for #1818) |
153 | 158 |
|
154 | 159 | def _localimport(drive_id, update_progress=None): |
155 | 160 | drives = get_mounted_drives_with_channel_info() |
156 | 161 | drive = drives[drive_id] |
| 162 | + # copy channel's db file then copy all the content files from sorage dir |
157 | 163 | for channel in drive.metadata["channels"]: |
158 | | - call_command("importchannel", "local", channel["id"], drive.datafolder) |
| 164 | + call_command( |
| 165 | + "importchannel", |
| 166 | + "local", |
| 167 | + channel["id"], |
| 168 | + drive.datafolder, |
| 169 | + update_progress=update_progress) |
159 | 170 | call_command( |
160 | 171 | "importcontent", |
161 | 172 | "local", |
162 | 173 | channel["id"], |
163 | 174 | drive.datafolder, |
164 | 175 | update_progress=update_progress) |
| 176 | + connections.close_all() # close all DB connections (FIX for #1818) |
165 | 177 |
|
166 | 178 |
|
167 | 179 | def _localexport(drive_id, update_progress=None): |
168 | 180 | drives = get_mounted_drives_with_channel_info() |
169 | 181 | drive = drives[drive_id] |
170 | 182 | for channel in ChannelMetadataCache.objects.all(): |
171 | | - call_command("exportchannel", channel.id, drive.datafolder) |
| 183 | + call_command( |
| 184 | + "exportchannel", |
| 185 | + channel.id, |
| 186 | + drive.datafolder, |
| 187 | + update_progress=update_progress) |
172 | 188 | call_command( |
173 | 189 | "exportcontent", |
174 | 190 | channel.id, |
175 | 191 | drive.datafolder, |
176 | 192 | update_progress=update_progress) |
| 193 | + connections.close_all() # close all DB connections (FIX for #1818) |
177 | 194 |
|
178 | 195 |
|
179 | 196 | def _job_to_response(job): |
|
0 commit comments