# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from copy import copy
from mediagoblin.init import setup_global_and_app_config, setup_database
from mediagoblin.db.mongo.util import ObjectId
from mediagoblin.db.sql.models import (Base, User, MediaEntry, MediaComment,
Tag, MediaTag, MediaFile, MediaAttachmentFile)
+from mediagoblin.media_types.image.models import ImageData
from mediagoblin.media_types.video.models import VideoData
from mediagoblin.db.sql.open import setup_connection_and_db_from_config as \
sql_connect
session.close()
+def convert_image(mk_db):
+ session = Session()
+
+ for media in mk_db.MediaEntry.find(
+ {'media_type': 'mediagoblin.media_types.image'}).sort('created'):
+ media_data = copy(media.media_data)
+
+ # TODO: Fix after exif is migrated
+ media_data.pop('exif', None)
+
+ if len(media_data):
+ media_data_row = ImageData(**media_data)
+ media_data_row.media_entry = obj_id_table[media._id]
+ session.add(media_data_row)
+
+ session.commit()
+ session.close()
+
+
def convert_video(mk_db):
session = Session()
Session.remove()
convert_media_entries(mk_db)
Session.remove()
+ convert_image(mk_db)
+ Session.remove()
convert_video(mk_db)
Session.remove()
convert_media_tags(mk_db)