Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var contentLib = require("/lib/xp/content");
- var portalLib = require("/lib/xp/portal");
- var vetinst = require("vetinst/vetinst");
- exports.get = handleGet;
- function handleGet(req) {
- var site = portalLib.getSite();
- var queryContentWithOldGallery = contentLib.query({
- query: "_path LIKE '/content"+site._path+"/*' AND data.gallery.images LIKE '*'",
- count: 100
- });
- var errors = [];
- queryContentWithOldGallery.hits.forEach(function(content){
- try{
- var modifiedContent = contentLib.modify({
- key: content._id,
- branch: "draft",
- editor: function(c){
- c.data.accordion = null;
- c.data.showMostRead = null;
- c.data.gallery = null;
- c.data["related-reports"] = null;
- c.data["related-articles"] = null;
- c.data["related-researches"] = null;
- if(c.data.galleryGroup){
- c.data.galleryGroup.galleries = vetinst.forceArray(c.data.galleryGroup.galleries);
- if(c.data.galleryGroup.galleries.length > 0){
- c.data.galleryGroup.galleries.unshift(content.data.gallery);
- } else {
- c.data.galleryGroup = {
- galleries: [content.data.gallery]
- }
- }
- } else {
- c.data.galleryGroup = {
- galleries: [content.data.gallery]
- }
- }
- return c;
- }
- });
- contentLib.publish({
- keys: [content._id],
- sourceBranch: "draft",
- targetBranch: "master",
- includeDependencies: true
- });
- content = modifiedContent;
- } catch(e){
- log.error((e.cause?e.cause.message:e.message))
- errors.push(content.displayName+" - "+(e.cause?e.cause.message:e.message))
- }
- })
- return {
- contentType: "application/json",
- body:{
- query: queryContentWithOldGallery,
- errors: errors
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement