0

哪些步骤将重现该问题?

  1. 将以下函数加载到 Google 站点中。
  2. 运行函数 moveblogs()。

什么是预期的输出?

我希望所有 2013 年的博客文章(公告)都将其标题记录在 Logger 中,然后移动到新的博客(公告页面)。

你看到了什么呢?

我看到了错误:

服务错误:SitesApp:内部错误(第 25 行,文件“代码”)关闭

如果可能,请提供重现问题的小示例脚本的代码:

 function moveblogs() {

  var fromblog =  SitesApp.getPageByUrl("https://sites.google.com/a/mydomain.com/intranethome/home/Around-Intranet");
  var toblog =  SitesApp.getPageByUrl("https://sites.google.com/a/mydomain.com/intranethome/home/2013-around-Intranet");

    var nextbloc = 0;

    while (true) {
      var pages2 = fromblog.getAllDescendants({"start":nextbloc,"max":100});

      if (pages2.length > 0){

        Logger.log("starting at.."+nextbloc+" there are .."+pages2.length+" pages starting with.."+pages2[0].getTitle());
        var i = nextbloc;
        for (var x in pages2) {

          var publishedyear = Utilities.formatDate(pages2[x].getDatePublished(),"GMT","yyyy")
          Logger.log("year: "+publishedyear);

          if (publishedyear==2013) {

            Logger.log("Title: "+pages2[x].getTitle());

            pages2[x].setParent(toblog);
            Utilities.sleep(1000);
          }
          i = i + 1;          
        }    
      } else {
        break;      
      }
      nextbloc = nextbloc + 100;

    }      

}

请在下面提供任何附加信息。

  1. 注释掉第 25 行可以成功记录 2012 年的博客文章。
  2. 下面的代码可以在单独的函数中移动单个博客文章:

    blogpost.setParent(toblog);

4

1 回答 1

0

我认为其中一个公告中的一个标题实际上存在问题。此脚本有效,但可能会超时。但是重新运行它只会继续它停止的地方。

 function moveblogs() {

  var fromblog =  SitesApp.getPageByUrl("https://sites.google.com/a/mydomain.com/intranethome/home/Around-Intranet");
  var toblog =  SitesApp.getPageByUrl("https://sites.google.com/a/mydomain.com/intranethome/home/2013-around-Intranet");

  var nextbloc = 0;

  while (true) {

    var pages2 = fromblog.getChildren({"start":nextbloc,
                                       "max":10,
                                       includeDrafts: false,
                                       includeDeleted: false,
                                      });

    if (pages2.length > 0){

      Logger.log("starting at.."+nextbloc+" there are .."+pages2.length+" pages starting with.."+newblogtitle);
      var i = nextbloc;
      for (var x in pages2) {

        var newblogtitle = pages2[x].getTitle();
        //var pageType = pages2[x].getPageType();

        var publishedyear = Utilities.formatDate(pages2[x].getDatePublished(),"GMT","yyyy")

          if (publishedyear==2013) {

          Logger.log("Title: "+ newblogtitle);

          try{

            pages2[x].setParent(toblog);
            //    Utilities.sleep(1000);
          }catch(err){
            Logger.log(err);
          }
        }
        i = i + 1;          
      }    
    } else {
      break;      
    }
    nextbloc = nextbloc + 10;

  }      

}

}
于 2013-10-21T20:06:46.773 回答