예제 #1
0
파일: drupal.go 프로젝트: Wodby/wcli
func drupalMigrate() (interface{}, error) {
	var err error
	cmd := "drush"
	args := []string{}
	args = append(args, strings.Join([]string{"--root=", viper.GetString("docroot")}, ""))
	args = append(args, "updb")
	args = append(args, "-y")
	_, stdErr, err := exec.Command(cmd, args...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(stdErr), 0)
	}
	return "ok", err
}
예제 #2
0
파일: wordpress.go 프로젝트: Wodby/wcli
func wpressMigrate() (interface{}, error) {
	var err error
	cmd := "wp"
	args := []string{}
	args = append(args, strings.Join([]string{"--path=", viper.GetString("docroot")}, ""))
	args = append(args, "--allow-root")
	args = append(args, "core")
	args = append(args, "update-db")
	_, stdOut, err := exec.Command(cmd, args...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(stdOut), 0)
	}
	return "ok", err
}
예제 #3
0
파일: wordpress.go 프로젝트: Wodby/wcli
func wpressUpdate(coreOnly bool) (interface{}, error) {
	var err error

	cmd := "wp"

	coreArgs := []string{}
	coreArgs = append(coreArgs, strings.Join([]string{"--path=", viper.GetString("docroot")}, ""))
	coreArgs = append(coreArgs, "--allow-root")
	coreArgs = append(coreArgs, "core")
	_, updErrOut, err := exec.Command(cmd, append(coreArgs, "update")...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(updErrOut), 0)
	}

	_, dbUpdErrOut, err := exec.Command(cmd, append(coreArgs, "update-db")...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(dbUpdErrOut), 0)
	}

	if !coreOnly {
		packagesArgs := []string{}
		packagesArgs = append(packagesArgs, strings.Join([]string{"--path=", viper.GetString("docroot")}, ""))
		packagesArgs = append(packagesArgs, "update")
		packagesArgs = append(packagesArgs, "--all")

		_, packageErrOut, err := exec.Command(cmd, append([]string{"plugin"}, packagesArgs...)...).SeparateOutput()
		if err != nil {
			return nil, errors.New(string(packageErrOut), 0)
		}
		_, themeErrOut, err := exec.Command(cmd, append([]string{"theme"}, packagesArgs...)...).SeparateOutput()
		if err != nil {
			return nil, errors.New(string(themeErrOut), 0)
		}
	}

	return "ok", err
}
예제 #4
0
파일: drupal.go 프로젝트: Wodby/wcli
func drupalRevert() (interface{}, error) {
	var err error
	if !isModuleEnabled("features") {
		return "ok", err
	}
	cmd := "drush"
	args := []string{}
	args = append(args, strings.Join([]string{"--root=", viper.GetString("docroot")}, ""))
	args = append(args, "fra")
	args = append(args, "-y")
	_, stdErr, err := exec.Command(cmd, args...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(stdErr), 0)
	}
	return "ok", err
}
예제 #5
0
파일: drupal.go 프로젝트: Wodby/wcli
func isModuleEnabled(m string) bool {
	var err error
	cmd := "drush"
	args := []string{}
	args = append(args, strings.Join([]string{"--root=", viper.GetString("docroot")}, ""))
	args = append(args, "pm-list")
	args = append(args, "--pipe")
	args = append(args, "--type=module")
	args = append(args, "--status=enabled")
	args = append(args, "--no-core")
	//	args = append(args, "--package="+m)
	stdOut, _, err := exec.Command(cmd, args...).SeparateOutput()
	if err != nil {
		return false
	}
	s := strings.Split(string(stdOut), "\n")
	for _, v := range s {
		if strings.ToLower(m) == strings.ToLower(v) {
			return true
		}
	}
	return false
}
예제 #6
0
파일: drupal.go 프로젝트: Wodby/wcli
func drupalUpdate(coreOnly bool, securityOnly bool, checkDisabled bool) (interface{}, error) {
	var err error
	cmd := "drush"
	args := []string{}
	args = append(args, strings.Join([]string{"--root=", viper.GetString("docroot")}, ""))
	args = append(args, "pm-update")
	args = append(args, "-y")
	if coreOnly {
		args = append(args, "drupal")
	}
	if securityOnly {
		args = append(args, "--security-only")
	}
	if checkDisabled {
		args = append(args, "--check-disabled")
	}

	_, updErrOut, err := exec.Command(cmd, args...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(updErrOut), 0)
	}

	return "ok", err
}
예제 #7
0
파일: wordpress.go 프로젝트: Wodby/wcli
func wpressStatus(coreOnly bool, checkDisabled bool) (interface{}, error) {
	var result statusResponse
	var err error

	cmd := "wp"

	coreArgs := []string{}
	coreArgs = append(coreArgs, strings.Join([]string{"--path=", viper.GetString("docroot")}, ""))
	coreArgs = append(coreArgs, "--allow-root")
	coreArgs = append(coreArgs, "core")
	coreArgs = append(coreArgs, "check-update")
	coreArgs = append(coreArgs, "--format=json")
	coreOut, coreErr, err := exec.Command(cmd, coreArgs...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(coreErr), 0)
	}

	if len(coreOut) > 0 {
		var coreResponse []map[string]string
		err = json.Unmarshal(coreOut, &coreResponse)
		if err != nil {
			return nil, errors.New(err.Error(), 0)
		}

		verArgs := []string{}
		verArgs = append(verArgs, strings.Join([]string{"--path=", viper.GetString("docroot")}, ""))
		verArgs = append(verArgs, "--allow-root")
		verArgs = append(verArgs, "core")
		verArgs = append(verArgs, "version")
		coreVersionOut, coreVersionErr, err := exec.Command(cmd, verArgs...).SeparateOutput()
		if err != nil {
			return nil, errors.New(string(coreVersionErr), 0)
		}

		result.Updates = append(result.Updates, updateRecord{
			Title: "wordpress",
			Name:  "Wordpress",
			Current: currentReleaseInfo{
				Version: strings.TrimSpace(string(coreVersionOut)),
			},
			Update: updateReleaseInfo{
				Version: coreResponse[0]["version"],
			},
		})
	}

	if !coreOnly {
		packagesArgs := []string{}
		packagesArgs = append(packagesArgs, strings.Join([]string{"--path=", viper.GetString("docroot")}, ""))
		packagesArgs = append(packagesArgs, "--allow-root")
		packagesArgs = append(packagesArgs, "update")
		packagesArgs = append(packagesArgs, "--all")
		packagesArgs = append(packagesArgs, "--dry-run")

		pluginOut, pluginErr, err := exec.Command(cmd, append([]string{"plugin"}, packagesArgs...)...).SeparateOutput()
		if err != nil {
			return nil, errors.New(string(pluginErr), 0)
		}
		themeOut, themeErr, err := exec.Command(cmd, append([]string{"theme"}, packagesArgs...)...).SeparateOutput()
		if err != nil {
			return nil, errors.New(string(themeErr), 0)
		}

		for _, update := range append(parseTableOutput(pluginOut), parseTableOutput(themeOut)...) {
			if !checkDisabled && update["status"] == "inactive" {
				continue
			}

			result.Updates = append(result.Updates, updateRecord{
				Title: update["name"],
				Name:  update["name"],
				Current: currentReleaseInfo{
					Version: update["version"],
				},
				Update: updateReleaseInfo{
					Version: update["update_version"],
				},
			})
		}
	}

	return result, err
}
예제 #8
0
파일: drupal.go 프로젝트: Wodby/wcli
func drupalStatus(coreOnly bool, securityOnly bool, checkDisabled bool) (interface{}, error) {
	var result statusResponse
	var err error
	var response drupalUpdateResponse

	cmd := "drush"
	args := []string{}
	args = append(args, strings.Join([]string{"--root=", viper.GetString("docroot")}, ""))
	args = append(args, "pm-updatestatus")
	if coreOnly {
		args = append(args, "drupal")
	}
	if securityOnly {
		args = append(args, "--security-only")
	}
	if checkDisabled {
		args = append(args, "--check-disabled")
	}
	args = append(args, "--pipe")
	args = append(args, "--format=json")

	cmdOut, cmdErr, err := exec.Command(cmd, args...).SeparateOutput()
	if err != nil {
		return nil, errors.New(string(cmdErr), 0)
	}

	if len(cmdOut) > 0 {
		err = json.Unmarshal(cmdOut, &response)
		if err != nil {
			return nil, errors.New("JSON parse error", 0)
		}

		for _, drupalRecord := range response {
			var releases []drupalUpdateRelease
			for _, drupalRelease := range drupalRecord.Releases {
				releases = append(releases, drupalRelease)
			}
			sort.Sort(drupalUpdateReleaseByTimestamp(releases))

			for _, release := range releases {
				if release.Version == drupalRecord.Version {
					break
				}

				if release.Version[len(release.Version)-3:] == "dev" {
					continue
				}

				result.Updates = append(result.Updates, updateRecord{
					Title: drupalRecord.Title,
					Name:  drupalRecord.Name,
					Current: currentReleaseInfo{
						Version: drupalRecord.Version,
					},
					Update: updateReleaseInfo{
						Security: isSecurity(release),
						Version:  release.Version,
						Url:      release.Url,
					},
				})
			}
		}
	}

	return result, err
}