Skip to content

Commit

Permalink
SAK-47123 Add a SakaiScript method for site archive (sakaiproject#10395)
Browse files Browse the repository at this point in the history
* SAK-47123 Add a SakaiScript method for site archive

Based on code by NYU

* Update webservices/cxf/src/java/org/sakaiproject/webservices/SakaiScript.java

Co-authored-by: Brian Jones <[email protected]>
  • Loading branch information
smarquard and bjones86 authored Apr 5, 2022
1 parent 3b94b06 commit b75cb19
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions webservices/cxf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
<artifactId>scheduler-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sakaiproject.common</groupId>
<artifactId>archive-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.calendar</groupId>
<artifactId>sakai-calendar-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
import org.sakaiproject.api.app.messageforums.AreaManager;
import org.sakaiproject.api.app.scheduler.SchedulerManager;
import org.sakaiproject.archive.api.ArchiveService;
import org.sakaiproject.assignment.api.AssignmentService;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.SecurityService;
Expand Down Expand Up @@ -97,6 +98,7 @@ public class AbstractWebService {
protected ActivityService activityService;
protected QuestionPoolServiceAPI questionPoolServiceImpl;
protected LessonBuilderAccessAPI lessonBuilderAccessAPI;
protected ArchiveService archiveService;
protected FormattedText formattedText;
protected SqlService sqlService;

Expand Down Expand Up @@ -304,4 +306,8 @@ public void setSqlService(SqlService sqlService) {
this.sqlService = sqlService;
}

@WebMethod(exclude = true)
public void setArchiveService(ArchiveService archiveService) {
this.archiveService = archiveService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5206,4 +5206,41 @@ public String changeSiteMemberStatus(
return "success";

}

@WebMethod
@Path("/archiveSite")
@Produces("text/plain")
@GET
public String archiveSite(
@WebParam(name = "sessionid", partName = "sessionid") @QueryParam("sessionid") String sessionid,
@WebParam(name = "siteid", partName = "siteid") @QueryParam("siteid") String siteid){

Session session = establishSession(sessionid);

// Require user to be an admin
if (!securityService.isSuperUser(session.getUserId())) {
log.warn("WS archiveSite(): Permission denied. Must be super user to create a site archive");
throw new RuntimeException("WS archiveSite(): Permission denied. Must be super user to create a site archive");
}

try {
Site archiveTarget = siteService.getSite(siteid);
} catch (IdUnusedException e) {
log.warn("Unable to archive site {}: invalid site id", siteid);
return "failed: siteid " + siteid + " not found";
}

log.info("Archiving site {}", siteid);

try {
String msg = archiveService.archiveAndZip(siteid);
log.info("Successfully archived site {} - {}", siteid, msg);
} catch (Exception e) {
log.error("Failed to archive site: {} - {}", siteid, e.getMessage());
return e.getClass().getName() + " : " + e.getMessage();
}

return "success";
}

}
1 change: 1 addition & 0 deletions webservices/cxf/src/resources/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
<property name="preferencesService" ref="org.sakaiproject.user.api.PreferencesService"/>
<property name="timeService" ref="org.sakaiproject.time.api.TimeService"/>
<property name="questionPoolServiceImpl" ref="org.sakaiproject.tool.assessment.shared.api.questionpool.QuestionPoolServiceAPI"/>
<property name="archiveService" ref="org.sakaiproject.archive.api.ArchiveService"/>
<property name="lessonBuilderAccessAPI" ref="org.sakaiproject.lessonbuildertool.LessonBuilderAccessAPI"/>
<property name="formattedText" ref="org.sakaiproject.util.api.FormattedText" />
<property name="logConfigurationManager" ref="org.sakaiproject.log.api.LogConfigurationManager"/>
Expand Down

0 comments on commit b75cb19

Please sign in to comment.