Пример #1
0
func Revert() (result interface{}, err error) {
	switch viper.Get("app_type") {
	case "drupal":
		result, err = drupalRevert()
		//	case "wpress":
		//		result, err = wpressMigrate()
	default:
		result, err = nil, errors.New("Not implemented", 0)
	}

	return result, err
}
Пример #2
0
func Update(coreOnly bool, securityOnly bool, checkDisabled bool) (result interface{}, err error) {
	switch viper.Get("app_type") {
	case "drupal":
		result, err = drupalUpdate(coreOnly, securityOnly, checkDisabled)
	case "wpress":
		result, err = wpressUpdate(coreOnly)
	default:
		result, err = nil, errors.New("Not implemented", 0)
	}

	return result, err
}
Пример #3
0
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
}
Пример #4
0
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
}
Пример #5
0
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
}
Пример #6
0
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
}
Пример #7
0
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
}
Пример #8
0
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
}
Пример #9
0
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
}