| 1 | # GNU MediaGoblin -- federated, autonomous media hosting |
| 2 | # Copyright (C) 2011 Free Software Foundation, Inc |
| 3 | # |
| 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. |
| 8 | # |
| 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. |
| 13 | # |
| 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/>. |
| 16 | |
| 17 | from mediagoblin.util import cleaned_markdown_conversion |
| 18 | |
| 19 | from mongokit import DocumentMigration |
| 20 | |
| 21 | |
| 22 | class MediaEntryMigration(DocumentMigration): |
| 23 | def allmigration01_uploader_to_reference(self): |
| 24 | """ |
| 25 | Old MediaEntry['uploader'] accidentally embedded the User instead |
| 26 | of referencing it. Fix that! |
| 27 | """ |
| 28 | # uploader is an associative array |
| 29 | self.target = {'uploader': {'$type': 3}} |
| 30 | if not self.status: |
| 31 | for doc in self.collection.find(self.target): |
| 32 | self.update = { |
| 33 | '$set': { |
| 34 | 'uploader': doc['uploader']['_id']}} |
| 35 | self.collection.update( |
| 36 | self.target, self.update, multi=True, safe=True) |
| 37 | |
| 38 | def allmigration02_add_description_html(self): |
| 39 | """ |
| 40 | Now that we can have rich descriptions via Markdown, we should |
| 41 | update all existing entries to record the rich description versions. |
| 42 | """ |
| 43 | self.target = {'description_html': {'$exists': False}, |
| 44 | 'description': {'$exists': True}} |
| 45 | |
| 46 | if not self.status: |
| 47 | for doc in self.collection.find(self.target): |
| 48 | self.update = { |
| 49 | '$set': { |
| 50 | 'description_html': cleaned_markdown_conversion( |
| 51 | doc['description'])}} |
| 52 | |
| 53 | class UserMigration(DocumentMigration): |
| 54 | def allmigration01_add_bio_and_url_profile(self): |
| 55 | """ |
| 56 | User can elaborate profile with home page and biography |
| 57 | """ |
| 58 | self.target = {'url': {'$exists': False}, |
| 59 | 'bio': {'$exists': False}} |
| 60 | if not self.status: |
| 61 | for doc in self.collection.find(self.target): |
| 62 | self.update = { |
| 63 | '$set': {'url': '', |
| 64 | 'bio': ''}} |
| 65 | self.collection.update( |
| 66 | self.target, self.update, multi=True, safe=True) |
| 67 | |
| 68 | |
| 69 | MIGRATE_CLASSES = ['MediaEntry', 'User'] |