Beispiel #1
0
  /**
   * 执行升级操作
   *
   * @param appid
   * @param version
   */
  private void exeUpdate(String appid, String version) {

    String patchPath = EopSetting.EOP_PATH + "/patch/" + appid + "/" + version;
    String updateSql = patchPath + "/sql/update.sql";
    String cmsUpdateSql = patchPath + "/sql/cms_update.sql";

    // 执行升级数据库脚本
    if (new File(updateSql).exists()) {

      if (logger.isDebugEnabled()) {
        logger.debug("执行[" + updateSql + "]...");
      }

      String content = FileUtil.read(updateSql, "UTF-8");
      this.executeSql(content);

      if (logger.isDebugEnabled()) {
        logger.debug("执行[" + updateSql + "]成功.");
      }

    } else {
      if (logger.isDebugEnabled()) {
        logger.debug("[" + updateSql + "]不存在跳过.");
      }
    }

    // 执行cms相应升级数据库脚本
    if (new File(cmsUpdateSql).exists()) {
      if (logger.isDebugEnabled()) {
        logger.debug("执行[" + cmsUpdateSql + "]...");
      }

      String content = FileUtil.read(cmsUpdateSql, "UTF-8");

      if (logger.isDebugEnabled()) {
        logger.debug("执行内容[" + content + "]...");
      }

      this.batchSqlExecutor.executeForCms(content);

      if (logger.isDebugEnabled()) {
        logger.debug("执行[" + cmsUpdateSql + "]成功.");
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug("复制[" + patchPath + "/web" + "]...");
    }

    FileUtil.copyFolder(patchPath + "/web", EopSetting.EOP_PATH);
    if (logger.isDebugEnabled()) {
      logger.debug("复制[" + patchPath + "/web" + "]成功.");
    }
  }
 public static void main(String[] args) {
   String content =
       FileUtil.read(
           "D:/Works/Trunk/javamall/WebContent/products/eopsaler/example_data_mysql.sql", "UTF-8");
   // content = ExampleDataInstaller.parseConst(content);
   System.out.println(content.substring(0, 50));
 }
  @Transactional(propagation = Propagation.REQUIRED)
  public void install(String productId, Node fragment) {
    boolean xmlData = true;
    String dataSqlPath = EopSetting.PRODUCTS_STORAGE_PATH + "/" + productId + "/example_data.xml";
    try {
      File xmlFile = new File(dataSqlPath);
      if (!xmlFile.exists()) { // 	如果example_data.xml不存在,执行旧版本
        xmlData = false;
        dataSqlPath = getDataSqlPath(productId);
      }

      loggerPrint("安装datasqlPath:" + dataSqlPath);

      if (!"base".equals(productId)) {
        InstallUtil.putMessaage(
            "正在安装示例数据,可能要花费较长时间,请稍后 <img src='resource/com/enation/app/saas/widget/product/loading.gif'");
      } else {
        InstallUtil.putMessaage("正在安装基础数据...");
      }

      if (xmlData) {
        anyDBInstall(dataSqlPath);
      } else {
        if (new File(dataSqlPath).exists()) {
          // 安装示例数据
          String content = FileUtil.read(dataSqlPath, "UTF-8");
          // 解析文件头部CONST和EOPSITE命令,CONST用于替换下面的文本内容,EOPSITE用于更新eop_site表
          content = parseConst(content);

          content = parseUserSiteID(content);
          content = this.filter(content);
          content = content + parseUserSiteID(eopsiteSQL);

          sqlFileExecutor.execute(content);

        } else {
          System.out.println(dataSqlPath + " not exist");
        }
      }
      loggerPrint("示例数据安装完毕");

      FileUtil.copyFolder(
          EopSetting.PRODUCTS_STORAGE_PATH + "/" + productId + "/attachment/",
          EopSetting.IMG_SERVER_PATH + EopContext.getContext().getContextPath() + "/attachment/");

      // 非base应用copy init.sql
      if (!"base".equals(productId)) {
        FileUtil.copyFile(
            EopSetting.PRODUCTS_STORAGE_PATH + "/" + productId + "/init.sql",
            EopSetting.EOP_PATH + EopContext.getContext().getContextPath() + "/init.sql");
      }

    } catch (Exception e) {
      e.printStackTrace();
      this.logger.debug(e.getMessage(), e);
      throw new RuntimeException("安装示例数据出错...");
    }
  }
 /*     */ public void initData() /*     */ {
   /*     */ String tablenameperfix;
   /*     */ Iterator i$;
   /* 513 */ if ("2".equals(EopSetting.RUNMODE))
   /*     */ {
     /* 515 */ EopSite site = EopContext.getContext().getCurrentSite();
     /* 516 */ String productId = site.getProductid();
     /* 517 */ org.dom4j.Document setupDoc = this.setupLoader.load(productId);
     /*     */
     /* 519 */ tablenameperfix = "";
     /*     */
     /* 521 */ tablenameperfix = "_" + site.getUserid() + "_" + site.getId();
     /*     */
     /* 523 */ List listClean = setupDoc.getRootElement().element("clean").elements();
     /*     */
     /* 525 */ for (i$ = listClean.iterator(); i$.hasNext(); ) {
       Object o = i$.next();
       /* 526 */ org.dom4j.Element table = (org.dom4j.Element) o;
       /* 527 */ this.daoSupport.execute(
           "truncate table " + table.getText() + tablenameperfix, new Object[0]);
       /*     */ }
     /*     */
     /*     */ }
   /*     */
   /* 532 */ String sqlPath =
       EopSetting.EOP_PATH + EopContext.getContext().getContextPath() + "/init.sql";
   /*     */
   /* 534 */ File file = new File(sqlPath);
   /* 535 */ if (file.exists()) {
     /* 536 */ String content = FileUtil.read(sqlPath, "UTF-8");
     /*     */
     /* 538 */ if ("2".equals(EopSetting.RUNMODE)) {
       /* 539 */ EopSite site = EopContext.getContext().getCurrentSite();
       /* 540 */ content = content.replaceAll("<userid>", String.valueOf(site.getUserid()));
       /*     */
       /* 542 */ content = content.replaceAll("<siteid>", String.valueOf(site.getId()));
       /*     */ }
     /*     */ else {
       /* 545 */ content = content.replaceAll("_<userid>", "");
       /* 546 */ content = content.replaceAll("_<siteid>", "");
       /* 547 */ content = content.replaceAll("/user/<userid>/<siteid>", "");
       /* 548 */ content = content.replaceAll("<userid>", "1");
       /* 549 */ content = content.replaceAll("<siteid>", "1");
       /*     */ }
     /* 551 */ this.sqlFileExecutor.execute(content);
     /*     */ } else {
     /* 553 */ throw new RuntimeException("本站点初始化脚本不存在");
     /*     */ }
   /*     */ }