function fully_interactive($argv)
{
    if (!is_dir('app')) {
        error("Couldn't find \"app\" folder in path, please run from a Magento sub-directory.");
    }
    $code_pool = trim(input("What code pool?"));
    $package = trim(input("What package?"));
    $module = trim(input("What module?"));
    $path = get_config_path($code_pool, $package, $module);
    echo "Loading: " . $path . "\n";
    $xml = simplexml_load_file($path);
    $xVersion = $xml->modules->{$package . '_' . $module}->version;
    $version = (string) $xVersion;
    echo "Current Version: " . $version . "\n";
    //list($major, $minor, $bugfix) = explode(".", $version);
    $parts = explode(".", $version);
    $index = get_version_index();
    $parts[$index]++;
    $version_new = implode(".", $parts);
    $xVersion[0] = $version_new;
    $xml = $xml->asXml();
    if (simplexml_load_string($xml)) {
        file_put_contents($path, $xml);
    }
    echo "Updated {$path} to {$version_new}\n";
}
Esempio n. 2
0
function &xml_to_graph_template($hash, &$xml_array, &$hash_cache, $hash_version)
{
    global $struct_graph, $struct_graph_item, $fields_graph_template_input_edit, $hash_version_codes;
    /* import into: graph_templates */
    $_graph_template_id = db_fetch_cell("select id from graph_templates where hash='{$hash}'");
    $save["id"] = empty($_graph_template_id) ? "0" : $_graph_template_id;
    $save["hash"] = $hash;
    $save["name"] = $xml_array["name"];
    $graph_template_id = sql_save($save, "graph_templates");
    $hash_cache["graph_template"][$hash] = $graph_template_id;
    /* import into: graph_templates_graph */
    unset($save);
    $save["id"] = empty($_graph_template_id) ? "0" : db_fetch_cell("select graph_templates_graph.id from (graph_templates,graph_templates_graph) where graph_templates.id=graph_templates_graph.graph_template_id and graph_templates.id={$graph_template_id} and graph_templates_graph.local_graph_id=0");
    $save["graph_template_id"] = $graph_template_id;
    reset($struct_graph);
    while (list($field_name, $field_array) = each($struct_graph)) {
        /* make sure this field exists in the xml array first */
        if (isset($xml_array["graph"]["t_" . $field_name])) {
            $save["t_" . $field_name] = $xml_array["graph"]["t_" . $field_name];
        }
        /* make sure this field exists in the xml array first */
        if (isset($xml_array["graph"][$field_name])) {
            /* Cacti pre 0.8.5 did handle a unit_exponent=0 differently
             * so we need to know the version of the current hash code we're just working on */
            if ($field_name == "unit_exponent_value" && get_version_index($hash_version) < get_version_index("0.8.5") && $xml_array["graph"][$field_name] == "0") {
                /* backwards compatability */
                $save[$field_name] = "";
            } else {
                $save[$field_name] = addslashes(xml_character_decode($xml_array["graph"][$field_name]));
            }
        }
    }
    $graph_template_graph_id = sql_save($save, "graph_templates_graph");
    /* import into: graph_templates_item */
    if (is_array($xml_array["items"])) {
        while (list($item_hash, $item_array) = each($xml_array["items"])) {
            /* parse information from the hash */
            $parsed_hash = parse_xml_hash($item_hash);
            /* invalid/wrong hash */
            if ($parsed_hash == false) {
                return false;
            }
            unset($save);
            $_graph_template_item_id = db_fetch_cell("select id from graph_templates_item where hash='" . $parsed_hash["hash"] . "' and graph_template_id={$graph_template_id} and local_graph_id=0");
            $save["id"] = empty($_graph_template_item_id) ? "0" : $_graph_template_item_id;
            $save["hash"] = $parsed_hash["hash"];
            $save["graph_template_id"] = $graph_template_id;
            reset($struct_graph_item);
            while (list($field_name, $field_array) = each($struct_graph_item)) {
                /* make sure this field exists in the xml array first */
                if (isset($item_array[$field_name])) {
                    /* is the value of this field a hash or not? */
                    if (preg_match("/hash_([a-f0-9]{2})([a-f0-9]{4})([a-f0-9]{32})/", $item_array[$field_name])) {
                        $save[$field_name] = resolve_hash_to_id($item_array[$field_name], $hash_cache);
                    } elseif ($field_name == "color_id" && preg_match("/^[a-fA-F0-9]{6}\$/", $item_array[$field_name]) && get_version_index($parsed_hash["version"]) >= get_version_index("0.8.5")) {
                        /* treat the 'color' field differently */
                        $color_id = db_fetch_cell("select id from colors where hex='" . $item_array[$field_name] . "'");
                        if (empty($color_id)) {
                            db_execute("insert into colors (hex) values ('" . $item_array[$field_name] . "')");
                            $color_id = db_fetch_insert_id();
                        }
                        $save[$field_name] = $color_id;
                    } else {
                        $save[$field_name] = addslashes(xml_character_decode($item_array[$field_name]));
                    }
                }
            }
            $graph_template_item_id = sql_save($save, "graph_templates_item");
            $hash_cache["graph_template_item"][$parsed_hash["hash"]] = $graph_template_item_id;
        }
    }
    /* import into: graph_template_input */
    if (is_array($xml_array["inputs"])) {
        while (list($item_hash, $item_array) = each($xml_array["inputs"])) {
            /* parse information from the hash */
            $parsed_hash = parse_xml_hash($item_hash);
            /* invalid/wrong hash */
            if ($parsed_hash == false) {
                return false;
            }
            unset($save);
            $_graph_template_input_id = db_fetch_cell("select id from graph_template_input where hash='" . $parsed_hash["hash"] . "' and graph_template_id={$graph_template_id}");
            $save["id"] = empty($_graph_template_input_id) ? "0" : $_graph_template_input_id;
            $save["hash"] = $parsed_hash["hash"];
            $save["graph_template_id"] = $graph_template_id;
            reset($fields_graph_template_input_edit);
            while (list($field_name, $field_array) = each($fields_graph_template_input_edit)) {
                /* make sure this field exists in the xml array first */
                if (isset($item_array[$field_name])) {
                    $save[$field_name] = addslashes(xml_character_decode($item_array[$field_name]));
                }
            }
            $graph_template_input_id = sql_save($save, "graph_template_input");
            $hash_cache["graph_template_input"][$parsed_hash["hash"]] = $graph_template_input_id;
            /* import into: graph_template_input_defs */
            $hash_items = explode("|", $item_array["items"]);
            if (!empty($hash_items[0])) {
                for ($i = 0; $i < count($hash_items); $i++) {
                    /* parse information from the hash */
                    $parsed_hash = parse_xml_hash($hash_items[$i]);
                    /* invalid/wrong hash */
                    if ($parsed_hash == false) {
                        return false;
                    }
                    if (isset($hash_cache["graph_template_item"][$parsed_hash["hash"]])) {
                        db_execute("replace into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values ({$graph_template_input_id}," . $hash_cache["graph_template_item"][$parsed_hash["hash"]] . ")");
                    }
                }
            }
        }
    }
    /* status information that will be presented to the user */
    $_SESSION["import_debug_info"]["type"] = empty($_graph_template_id) ? "new" : "update";
    $_SESSION["import_debug_info"]["title"] = $xml_array["name"];
    $_SESSION["import_debug_info"]["result"] = empty($graph_template_id) ? "fail" : "success";
    return $hash_cache;
}
Esempio n. 3
0
function &xml_to_graph_template($hash, &$xml_array, &$hash_cache) {
	global $struct_graph, $struct_graph_item, $fields_graph_template_input_edit, $hash_version_codes;

	/* import into: graph_templates */
	$_graph_template_id = db_fetch_cell("select id from graph_templates where hash='$hash'");
	$save["id"] = (empty($_graph_template_id) ? 0 : $_graph_template_id);
	$save["hash"] = $hash;
	$save["name"] = $xml_array["name"];
	$graph_template_id = sql_save($save, "graph_templates");

	$hash_cache["graph_template"][$hash] = $graph_template_id;

	/* import into: graph_templates_graph */
	unset($save);
	$save["id"] = (empty($_graph_template_id) ? 0 : db_fetch_cell("select graph_templates_graph.id from (graph_templates cross join graph_templates_graph) where graph_templates.id=graph_templates_graph.graph_template_id and graph_templates.id=$graph_template_id and graph_templates_graph.local_graph_id=0"));
	$save["graph_template_id"] = $graph_template_id;

	/* parse information from the hash */
	$parsed_hash = parse_xml_hash($hash);

	reset($struct_graph);
	while (list($field_name, $field_array) = each($struct_graph)) {
		/* make sure this field exists in the xml array first */
		if (isset($xml_array["graph"]{"t_" . $field_name})) {
			$save{"t_" . $field_name} = $xml_array["graph"]{"t_" . $field_name};
		}

		/* make sure this field exists in the xml array first */
		if (isset($xml_array["graph"][$field_name])) {
			if (($field_name == "unit_exponent_value") && (get_version_index($parsed_hash["version"]) < get_version_index("0.8.5")) && ($xml_array["graph"][$field_name] == "0")) { /* backwards compatability */
				$save[$field_name] = "";
			}else{
				$save[$field_name] = addslashes(xml_character_decode($xml_array["graph"][$field_name]));
			}
		}
	}

	$graph_template_graph_id = sql_save($save, "graph_templates_graph");

	/* import into: graph_templates_item */
	if (is_array($xml_array["items"])) {
		while (list($item_hash, $item_array) = each($xml_array["items"])) {
			/* parse information from the hash */
			$parsed_hash = parse_xml_hash($item_hash);

			/* invalid/wrong hash */
			if ($parsed_hash == false) { return false; }

			unset($save);
			$_graph_template_item_id = db_fetch_cell("select id from graph_templates_item where hash='" . $parsed_hash["hash"] . "' and graph_template_id=$graph_template_id and local_graph_id=0");
			$save["id"] = (empty($_graph_template_item_id) ? "0" : $_graph_template_item_id);
			$save["hash"] = $parsed_hash["hash"];
			$save["graph_template_id"] = $graph_template_id;

			reset($struct_graph_item);
			while (list($field_name, $field_array) = each($struct_graph_item)) {
				/* make sure this field exists in the xml array first */
				if (isset($item_array[$field_name])) {
					/* is the value of this field a hash or not? */
					if (ereg("hash_([a-f0-9]{2})([a-f0-9]{4})([a-f0-9]{32})", $item_array[$field_name])) {
						$save[$field_name] = resolve_hash_to_id($item_array[$field_name], $hash_cache);
					}elseif (($field_name == "color_id") && (ereg("^[a-fA-F0-9]{6}$", $item_array[$field_name])) && (get_version_index($parsed_hash["version"]) >= get_version_index("0.8.5"))) { /* treat the 'color' field differently */
						$color_id = db_fetch_cell("select id from colors where hex='" . $item_array[$field_name] . "'");

						if (empty($color_id)) {
							db_execute("insert into colors (hex) values ('" . $item_array[$field_name] . "')");
							$color_id = db_fetch_insert_id();
						}

						$save[$field_name] = $color_id;
					}else{
						$save[$field_name] = addslashes(xml_character_decode($item_array[$field_name]));
					}
				}
			}

			$graph_template_item_id = sql_save($save, "graph_templates_item");

			$hash_cache["graph_template_item"]{$parsed_hash["hash"]} = $graph_template_item_id;
		}
	}

	/* import into: graph_template_input */
	if (is_array($xml_array["inputs"])) {
		while (list($item_hash, $item_array) = each($xml_array["inputs"])) {
			/* parse information from the hash */
			$parsed_hash = parse_xml_hash($item_hash);

			/* invalid/wrong hash */
			if ($parsed_hash == false) { return false; }

			unset($save);
			$_graph_template_input_id = db_fetch_cell("select id from graph_template_input where hash='" . $parsed_hash["hash"] . "' and graph_template_id=$graph_template_id");
			$save["id"] = (empty($_graph_template_input_id) ? "0" : $_graph_template_input_id);
			$save["hash"] = $parsed_hash["hash"];
			$save["graph_template_id"] = $graph_template_id;

			reset($fields_graph_template_input_edit);
			while (list($field_name, $field_array) = each($fields_graph_template_input_edit)) {
				/* make sure this field exists in the xml array first */
				if (isset($item_array[$field_name])) {
					$save[$field_name] = addslashes(xml_character_decode($item_array[$field_name]));
				}
			}

			$graph_template_input_id = sql_save($save, "graph_template_input");

			$hash_cache["graph_template_input"]{$parsed_hash["hash"]} = $graph_template_input_id;

			/* import into: graph_template_input_defs */
			$hash_items = explode("|", $item_array["items"]);

			if (!empty($hash_items[0])) {
				for ($i=0; $i<count($hash_items); $i++) {
					/* parse information from the hash */
					$parsed_hash = parse_xml_hash($hash_items[$i]);

					/* invalid/wrong hash */
					if ($parsed_hash == false) { return false; }

					if (isset($hash_cache["graph_template_item"]{$parsed_hash["hash"]})) {
						/* db_replace() doesn't replace primary key, delete then insert */
						db_execute("delete from graph_template_input_defs where graph_template_input_id=$graph_template_input_id and graph_template_item_id = ".$hash_cache["graph_template_item"]{$parsed_hash["hash"]});
						db_execute("insert into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values($graph_template_input_id,".$hash_cache["graph_template_item"]{$parsed_hash["hash"]}.")");
					}
				}
			}
		}
	}

	/* status information that will be presented to the user */
	$_SESSION["import_debug_info"]["type"] = (empty($_graph_template_id) ? "new" : "update");
	$_SESSION["import_debug_info"]["title"] = $xml_array["name"];
	$_SESSION["import_debug_info"]["result"] = (empty($graph_template_id) ? "fail" : "success");

	return $hash_cache;
}