$existing_json = json_decode($existing["manifest"], true); // Increment revision numbers $revision = $package["revision"] = intval($existing_json["revision"]) + 1; $package["sql_revisions"] = (array) $existing_json["sql_revisions"]; $package["sql_revisions"][$revision] = array(); // Diff the old tables foreach ($existing_json["components"]["tables"] as $table => $create_statement) { // If the table exists in the new manifest, we're going to see if they're identical if (isset($package["components"]["tables"][$table])) { // We're going to create a temporary table of the old structure to compare to the current table $create_statement = preg_replace("/CREATE TABLE `([^`]*)`/i", "CREATE TABLE `bigtree_extension_temp`", $create_statement); $create_statement = preg_replace("/CONSTRAINT `([^`]*)`/i", "", $create_statement); sqlquery("DROP TABLE IF EXISTS `bigtree_extension_temp`"); sqlquery($create_statement); // Compare the tables, if we have changes to make, store them in a SQL revisions portion of the manifest $transition_statements = BigTree::tableCompare("bigtree_extension_temp", $table); foreach ($transition_statements as $statement) { // Don't include changes to auto increment if (stripos($statement, "auto_increment = ") === false) { $package["sql_revisions"][$revision][] = str_replace("`bigtree_extension_temp`", "`{$table}`", $statement); } } // Table doesn't exist in the new manifest, so we're going to drop it } else { $package["sql_revisions"][$revision][] = "DROP TABLE IF EXISTS `{$table}`"; } } // Add new tables that don't exist in the old manifest foreach ($package["components"]["tables"] as $table => $create_statement) { if (!isset($existing_json["components"]["tables"][$table])) { $package["sql_revisions"][$revision][] = $create_statement;