1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from mediagoblin
.util
import cleaned_markdown_conversion
19 from mongokit
import DocumentMigration
22 class MediaEntryMigration(DocumentMigration
):
23 def allmigration01_uploader_to_reference(self
):
25 Old MediaEntry['uploader'] accidentally embedded the User instead
26 of referencing it. Fix that!
28 # uploader is an associative array
29 self
.target
= {'uploader': {'$type': 3}}
31 for doc
in self
.collection
.find(self
.target
):
34 'uploader': doc
['uploader']['_id']}}
35 self
.collection
.update(
36 self
.target
, self
.update
, multi
=True, safe
=True)
38 def allmigration02_add_description_html(self
):
40 Now that we can have rich descriptions via Markdown, we should
41 update all existing entries to record the rich description versions.
43 self
.target
= {'description_html': {'$exists': False},
44 'description': {'$exists': True}}
47 for doc
in self
.collection
.find(self
.target
):
50 'description_html': cleaned_markdown_conversion(
53 class UserMigration(DocumentMigration
):
54 def allmigration01_add_bio_and_url_profile(self
):
56 User can elaborate profile with home page and biography
58 self
.target
= {'url': {'$exists': False},
59 'bio': {'$exists': False}}
61 for doc
in self
.collection
.find(self
.target
):
65 self
.collection
.update(
66 self
.target
, self
.update
, multi
=True, safe
=True)
69 MIGRATE_CLASSES
= ['MediaEntry', 'User']