001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.wiki.convert;
016    
017    import com.liferay.portal.convert.DLStoreConvertProcess;
018    import com.liferay.portal.convert.DLStoreConverter;
019    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
020    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
021    import com.liferay.portal.kernel.dao.orm.Property;
022    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
023    import com.liferay.portal.kernel.exception.PortalException;
024    import com.liferay.portal.kernel.repository.model.FileEntry;
025    import com.liferay.portal.util.MaintenanceUtil;
026    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
027    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
028    import com.liferay.portlet.wiki.model.WikiPage;
029    import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
030    
031    /**
032     * @author Ivan Zaera
033     */
034    public class WikiDLStoreConvertProcess implements DLStoreConvertProcess {
035    
036            @Override
037            public void migrate(final DLStoreConverter dlStoreConverter)
038                    throws PortalException {
039    
040                    int count = WikiPageLocalServiceUtil.getWikiPagesCount();
041    
042                    MaintenanceUtil.appendStatus(
043                            "Migrating wiki page attachments in " + count + " pages");
044    
045                    ActionableDynamicQuery actionableDynamicQuery =
046                            WikiPageLocalServiceUtil.getActionableDynamicQuery();
047    
048                    actionableDynamicQuery.setAddCriteriaMethod(
049                            new ActionableDynamicQuery.AddCriteriaMethod() {
050    
051                                    @Override
052                                    public void addCriteria(DynamicQuery dynamicQuery) {
053                                            Property property = PropertyFactoryUtil.forName("head");
054    
055                                            dynamicQuery.add(property.eq(true));
056                                    }
057    
058                            });
059                    actionableDynamicQuery.setPerformActionMethod(
060                            new ActionableDynamicQuery.PerformActionMethod() {
061    
062                                    @Override
063                                    public void performAction(Object object) {
064                                            WikiPage wikiPage = (WikiPage)object;
065    
066                                            for (FileEntry fileEntry :
067                                                            wikiPage.getAttachmentsFileEntries()) {
068    
069                                                    DLFileEntry dlFileEntry =
070                                                            (DLFileEntry)fileEntry.getModel();
071    
072                                                    dlStoreConverter.migrateDLFileEntry(
073                                                            wikiPage.getCompanyId(),
074                                                            DLFolderConstants.getDataRepositoryId(
075                                                                    dlFileEntry.getRepositoryId(),
076                                                                    dlFileEntry.getFolderId()),
077                                                            dlFileEntry);
078                                            }
079                                    }
080    
081                            });
082    
083                    actionableDynamicQuery.performActions();
084            }
085    
086    }