コード例 #1
0
  protected void migrateWiki() throws Exception {
    int count = WikiPageLocalServiceUtil.getWikiPagesCount();
    int pages = count / Indexer.DEFAULT_INTERVAL;

    MaintenanceUtil.appendStatus("Migrating wiki page attachments in " + count + " pages");

    for (int i = 0; i <= pages; i++) {
      int start = (i * Indexer.DEFAULT_INTERVAL);
      int end = start + Indexer.DEFAULT_INTERVAL;

      List<WikiPage> wikiPages = WikiPageLocalServiceUtil.getWikiPages(start, end);

      for (WikiPage wikiPage : wikiPages) {
        if (!wikiPage.isHead()) {
          continue;
        }

        migrateFiles(
            wikiPage.getCompanyId(), wikiPage.getAttachmentsDir(), wikiPage.getAttachmentsFiles());
      }
    }
  }
コード例 #2
0
  private void trashWikiAttachments(boolean restore) throws Exception {
    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setScopeGroupId(TestPropsValues.getGroupId());

    WikiNode wikiNode =
        WikiNodeLocalServiceUtil.addNode(
            TestPropsValues.getUserId(), ServiceTestUtil.randomString(), "", serviceContext);

    WikiPage wikiPage =
        WikiPageLocalServiceUtil.addPage(
            TestPropsValues.getUserId(),
            wikiNode.getNodeId(),
            ServiceTestUtil.randomString(),
            null,
            WikiPageConstants.NEW,
            true,
            serviceContext);

    String[] attachmentsFiles = wikiPage.getAttachmentsFiles();

    int initialNotInTrashCount = attachmentsFiles.length;

    String[] deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles();

    int initialTrashEntriesCount = deletedAttachmentsFiles.length;

    Class<?> clazz = getClass();

    byte[] fileBytes = FileUtil.getBytes(clazz.getResourceAsStream("dependencies/OSX_Test.docx"));

    File file = null;

    if ((fileBytes != null) && (fileBytes.length > 0)) {
      file = FileUtil.createTempFile(fileBytes);
    }

    WikiPageLocalServiceUtil.addPageAttachment(
        TestPropsValues.getUserId(),
        wikiNode.getNodeId(),
        wikiPage.getTitle(),
        ServiceTestUtil.randomString() + ".txt",
        file);

    attachmentsFiles = wikiPage.getAttachmentsFiles();

    Assert.assertEquals(initialNotInTrashCount + 1, attachmentsFiles.length);

    deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles();

    Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length);

    String fileName = attachmentsFiles[0];

    WikiPageLocalServiceUtil.movePageAttachmentToTrash(
        wikiNode.getNodeId(), wikiPage.getTitle(), fileName);

    attachmentsFiles = wikiPage.getAttachmentsFiles();

    Assert.assertEquals(initialNotInTrashCount, attachmentsFiles.length);

    deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles();

    Assert.assertEquals(initialTrashEntriesCount + 1, deletedAttachmentsFiles.length);

    fileName = deletedAttachmentsFiles[0];

    if (restore) {
      WikiPageLocalServiceUtil.movePageAttachmentFromTrash(
          wikiNode.getNodeId(), wikiPage.getTitle(), fileName);

      attachmentsFiles = wikiPage.getAttachmentsFiles();

      Assert.assertEquals(initialNotInTrashCount + 1, attachmentsFiles.length);

      deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles();

      Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length);
    } else {
      WikiPageLocalServiceUtil.deletePageAttachment(
          wikiNode.getNodeId(), wikiPage.getTitle(), fileName);

      attachmentsFiles = wikiPage.getAttachmentsFiles();

      Assert.assertEquals(initialNotInTrashCount, attachmentsFiles.length);

      deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles();

      Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length);
    }
  }