AnsweredAssumed Answered

Delete Course Content

Question asked by nelson on May 14, 2018

I'm working on a Building Block and trying to delete courses and their content as part of an archiving process. This method does both, but it is deprecated:

 

blackboard.admin.persist.course.CourseSitePersister.remove(java.util.List<CourseSite> objList, boolean removeContent)

 

Does anyone know of a replacement for this method?

 

I have tried looping through the contents of the course and deleting the Contents or ContentFiles, but neither deletes the actual file, which can still be found in the Content Collection afterwards.

 

// Returns a list of items representing the top-level content items in the course.
List<Content> topLevelContents = ContentDbLoader.Default.getInstance().loadMapView(coursePk, null);

// For each top level content, load its sub-contents
for (Content topLevelContent : topLevelContents) {

    /*
     * Loads a list of Content by performing a deep load rooted at the content item
     * with the given Id. The load is performed in the specified fashion
     * (lightweight or heavyweight) using the supplied connection.
     * 
     * If the specified content item is not an aggregate type, it will have no
     * descendants and the returned list will thus contain only one content item --
     * the content item with the provided Id.
     * 
     * The order of content items within the returned list is such that parent
     * content items will always appear in the list before their children content
     * items, and for content items within a particular folder, the order of content
     * items is preserved. The first item in the list will always be the content
     * item within the provided Id. Beyond these stipulations the ordering is not
     * guaranteed.
     */
    List<Content> contents = ContentDbLoader.Default.getInstance().loadListById(topLevelContent.getId(), null, true);

    for (Content content : contents) {
        for (ContentFile contentFile : content.getContentFiles()) {
            // This just disassociates the file with the Content item. "(Invalid File)" is added to the 
            // Content's name in the Content area, but the file can still be found in the Content Collection.
            ContentFileDbPersister.Default.getInstance().deleteById(contentFile.getId());
        }
        // This deletes the Content item from the Content area, but the file can still be found in the Content Collection.
        ContentDbPersister.Default.getInstance().deleteById(content.getId());
    }
}

 

One method that does work is:

 

ContentSystemServiceFactory.getInstance().getDocumentManager().remove(contentFile.getName());

 

However, it only works if I use a static String, such as documentManager.remove("contentFileName"), where contentFilename is stored in the file_name column in the files table. The problem is that loading the content (the method loadListById() ) seems to put some sort of lock on the file. The logs don't show that the removal failed, but the file still exists afterwards.

 

Does anyone know of a better way to delete files?

 

We're self-hosted on version Q2 2017, 3200.0.5-rel.6+3dd6b56

Outcomes