Add a missing file sip_profile_copy.php to the dev branch.

This commit is contained in:
Mark Crane
2012-06-04 14:58:40 +00:00
commit af103e9c41
1240 changed files with 164946 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
<?php
//application details
$apps[$x]['name'] = "Upgrade Schema";
$apps[$x]['uuid'] = '8b1d7eb5-1009-052c-e1a8-d1f4887a3f5c';
$apps[$x]['category'] = 'Core';
$apps[$x]['subcategory'] = '';
$apps[$x]['version'] = '';
$apps[$x]['url'] = 'http://www.fusionpbx.com';
$apps[$x]['description']['en'] = 'Upgrade the database schema.';
//menu details
$apps[$x]['menu'][0]['title']['en'] = 'Upgrade Schema';
$apps[$x]['menu'][0]['uuid'] = '8c826e92-be3c-0944-669a-24e5b915d562';
$apps[$x]['menu'][0]['parent_uuid'] = '594d99c5-6128-9c88-ca35-4b33392cec0f';
$apps[$x]['menu'][0]['category'] = 'internal';
$apps[$x]['menu'][0]['path'] = '/core/upgrade/upgrade_schema.php';
$apps[$x]['menu'][0]['groups'][] = 'superadmin';
//permission details
$apps[$x]['permissions'][0]['name'] = 'upgrade_schema';
$apps[$x]['permissions'][0]['groups'][] = 'superadmin';
$apps[$x]['permissions'][1]['name'] = 'upgrade_svn';
//schema details
/*
$y = 0; //table array index
$z = 0; //field array index
$apps[$x]['db'][$y]['table'] = 'v_src';
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'id';
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'src_id';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'serial';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'integer';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'src_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'v_id';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'type';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'last_mod';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'path';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
*/
?>
+132
View File
@@ -0,0 +1,132 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
//if the resource scripts resource directory does not exist then create it
if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) { mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true); }
//get odbc information
$sql = "select count(*) as num_rows from v_databases ";
$sql .= "where database_type = 'odbc' ";
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$odbc_num_rows = $row['num_rows'];
$sql = "select * from v_databases ";
$sql .= "where database_type = 'odbc' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$dsn_name = $row["database_name"];
$dsn_username = $row["database_username"];
$dsn_password = $row["database_password"];
break; //limit to 1 row
}
unset ($prep_statement);
}
else {
$odbc_num_rows = '0';
}
}
//config.lua
$fout = fopen($_SESSION['switch']['scripts']['dir']."/resources/config.lua","w");
$tmp = "\n";
$tmp .= "--switch directories\n";
if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
$tmp .= " sounds_dir = \"".$_SESSION['switch']['sounds']['dir']."\";\n";
}
if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
$tmp .= " recordings_dir = \"".$_SESSION['switch']['recordings']['dir']."\";\n";
}
$tmp .= "\n";
$tmp .= "--database connection info\n";
if (strlen($db_type) > 0) {
$tmp .= " db_type = \"".$db_type."\";\n";
}
if (strlen($db_name) > 0) {
$tmp .= " db_name = \"".$db_name."\";\n";
}
if (strlen($db_path) > 0) {
$tmp .= " db_path = \"".$db_path."\";\n";
}
if (strlen($dsn_name) > 0) {
$tmp .= " dsn_name = \"".$dsn_name."\";\n";
}
if (strlen($dsn_username) > 0) {
$tmp .= " dsn_username = \"".$dsn_username."\";\n";
}
if (strlen($dsn_password) > 0) {
$tmp .= " dsn_password = \"".$dsn_password."\";\n";
}
$tmp .= "\n";
$tmp .= "--additional info\n";
$tmp .= " tmp_dir = \"".$tmp_dir."\";\n";
fwrite($fout, $tmp);
unset($tmp);
fclose($fout);
//config.js
$fout = fopen($_SESSION['switch']['scripts']['dir']."/resources/config.js","w");
$tmp = "\n";
$tmp .= "//switch directories\n";
$tmp .= " var admin_pin = \"".$row["admin_pin"]."\";\n";
$tmp .= " var sounds_dir = \"".$_SESSION['switch']['sounds']['dir']."\";\n";
$tmp .= " var recordings_dir = \"".$_SESSION['switch']['recordings']['dir']."\";\n";
$tmp .= "\n";
$tmp = "//database connection info\n";
if (strlen($db_type) > 0) {
$tmp .= " var db_type = \"".$db_type."\";\n";
}
if (strlen($db_name) > 0) {
$tmp .= " var db_name = \"".$db_name."\";\n";
}
if (strlen($db_path) > 0) {
$tmp .= " var db_path = \"".$db_path."\";\n";
}
if (strlen($dsn_name) > 0) {
$tmp .= " var dsn_name = \"".$dsn_name."\";\n";
}
if (strlen($dsn_username) > 0) {
$tmp .= " var dsn_username = \"".$dsn_username."\";\n";
}
if (strlen($dsn_password) > 0) {
$tmp .= " var dsn_password = \"".$dsn_password."\";\n";
}
$tmp .= "\n";
$tmp .= "//additional info\n";
$tmp .= " var tmp_dir = \"".$tmp_dir."\";\n";
fwrite($fout, $tmp);
unset($tmp);
fclose($fout);
}
?>
+50
View File
@@ -0,0 +1,50 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
// make sure the PATH_SEPARATOR is defined
if (!defined("PATH_SEPARATOR")) {
if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); }
}
// make sure the document_root is set
$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]);
$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
//echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."<br />\n";
//echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."<br />\n";
//echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."<br />\n";
// if the project directory exists then add it to the include path otherwise add the document root to the include path
if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){
if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); }
set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' );
}
else {
if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); }
set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] );
}
?>
+101
View File
@@ -0,0 +1,101 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//check the permission
if(defined('STDIN')) {
$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
$document_root = $matches[1];
set_include_path($document_root);
require_once "includes/require.php";
$_SERVER["DOCUMENT_ROOT"] = $document_root;
$display_type = 'text'; //html, text
}
else {
include "root.php";
require_once "includes/require.php";
require_once "includes/checkauth.php";
if (permission_exists('upgrade_schema') || permission_exists('upgrade_svn') || if_group("superadmin")) {
//echo "access granted";
}
else {
echo "access denied";
exit;
}
}
//set the default
if (!isset($display_results)) {
$display_results = false;
}
//include the header
if ($display_results) {
require_once "includes/header.php";
}
if ($display_type == 'text') {
echo "\n";
echo "Upgrade\n";
echo "-----------------------------------------\n";
echo "\n";
echo "Database\n";
}
//upgrade the database schema
require_once "core/upgrade/upgrade_schema.php";
//show the content
if ($display_type == 'html') {
echo "<div align='center'>\n";
echo "<table width='40%'>\n";
echo "<tr>\n";
echo "<th align='left'>Message</th>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='row_style1'><strong>Upgrade Completed</strong></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "<br />\n";
echo "<br />\n";
echo "<br />\n";
echo "<br />\n";
echo "<br />\n";
echo "<br />\n";
echo "<br />\n";
}
if ($display_type == 'text') {
echo "\n";
}
//include the footer
if ($display_results) {
require_once "includes/footer.php";
}
?>
+188
View File
@@ -0,0 +1,188 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//check the permission
if(defined('STDIN')) {
$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
$document_root = $matches[1];
set_include_path($document_root);
require_once "includes/require.php";
$_SERVER["DOCUMENT_ROOT"] = $document_root;
$display_type = 'text'; //html, text
}
else {
include "root.php";
require_once "includes/require.php";
require_once "includes/checkauth.php";
if (permission_exists('upgrade_schema') || permission_exists('upgrade_svn') || if_group("superadmin")) {
//echo "access granted";
}
else {
echo "access denied";
exit;
}
}
//copy the files and directories from includes/install
require_once "includes/classes/install.php";
$install = new install;
$install->domain_uuid = $domain_uuid;
$install->domain_name = $domain;
$install->switch_conf_dir = $_SESSION['switch']['conf']['dir'];
$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
$install->switch_sounds_dir = $_SESSION['switch']['sounds']['dir'];
$install->copy();
//print_r($install->result);
//get the list of installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$x=0;
foreach ($config_list as &$config_path) {
include($config_path);
$x++;
}
//get the domain_uuid
$sql = "select * from v_domains ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach($result as $row) {
if (count($result) == 0) {
$_SESSION["domain_uuid"] = $row["domain_uuid"];
$_SESSION["domain_name"] = $row['domain_name'];
}
else {
if ($row['domain_name'] == $domain_array[0] || $row['domain_name'] == 'www.'.$domain_array[0]) {
$_SESSION["domain_uuid"] = $row["domain_uuid"];
$_SESSION["domain_name"] = $row['domain_name'];
}
$_SESSION['domains'][$row['domain_uuid']]['domain_uuid'] = $row['domain_uuid'];
$_SESSION['domains'][$row['domain_uuid']]['domain_name'] = $row['domain_name'];
}
}
unset($result, $prep_statement);
//get the default settings
$sql = "select * from v_default_settings ";
$sql .= "where default_setting_enabled = 'true' ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$result_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
//get the default recordings directory
foreach($result_default_settings as $row) {
$name = $row['default_setting_name'];
$category = $row['default_setting_category'];
$subcategory = $row['default_setting_subcategory'];
if ($category == 'switch' && $subcategory == 'recordings' && $name == 'dir') {
$switch_recordings_dir = $row['default_setting_value'];
}
}
//loop through all domains
$sql = "select * from v_domains ";
$v_prep_statement = $db->prepare(check_sql($sql));
$v_prep_statement->execute();
$main_result = $v_prep_statement->fetchAll(PDO::FETCH_ASSOC);
$domain_count = count($main_result);
foreach ($main_result as &$row) {
//get the values from database and set them as php variables
$domain_uuid = $row["domain_uuid"];
$domain_name = $row["domain_name"];
//get the context
if ($domain_count == 1) {
$context = "default";
}
else {
$context = $domain_name;
}
//show the domain when display_type is set to text
if ($display_type == "text") {
echo "\n";
echo $domain_name;
echo "\n";
}
//get the default settings - this needs to be done to reset the session values back to the defaults for each domain in the loop
foreach($result_defaults_settings as $row) {
$name = $row['default_setting_name'];
$category = $row['default_setting_category'];
$subcategory = $row['default_setting_subcategory'];
if (strlen($subcategory) == 0) {
$_SESSION[$category][$name] = $row['default_setting_value'];
}
else {
$_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
}
}
//get the domains settings
$sql = "select * from v_domain_settings ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= "and domain_setting_enabled = 'true' ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach($result as $row) {
$name = $row['domain_setting_name'];
$category = $row['domain_setting_category'];
$subcategory = $row['domain_setting_subcategory'];
if (strlen($subcategory) == 0) {
//$$category[$name] = $row['domain_setting_value'];
$_SESSION[$category][$name] = $row['domain_setting_value'];
}
else {
//$$category[$subcategory][$name] = $row['domain_setting_value'];
$_SESSION[$category][$subcategory][$name] = $row['domain_setting_value'];
}
}
//set the recordings directory
if (strlen($switch_recordings_dir) > 1 && count($_SESSION["domains"]) > 1) {
$_SESSION['switch']['recordings']['dir'] = $switch_recordings_dir."/".$domain_name;
}
//get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php
$default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
foreach ($default_list as &$default_path) {
include($default_path);
}
// synchronize the dialplan
if (function_exists('save_dialplan_xml')) {
save_dialplan_xml();
}
}
unset ($v_prep_statement);
//clear the session variables
unset($_SESSION['domain']);
unset($_SESSION['switch']);
?>
+71
View File
@@ -0,0 +1,71 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//check the permission
if(defined('STDIN')) {
$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
$document_root = $matches[1];
set_include_path($document_root);
require_once "includes/require.php";
$_SERVER["DOCUMENT_ROOT"] = $document_root;
$display_type = 'text'; //html, text
}
else {
include "root.php";
require_once "includes/require.php";
require_once "includes/checkauth.php";
if (permission_exists('upgrade_schema') || if_group("superadmin")) {
//echo "access granted";
}
else {
echo "access denied";
exit;
}
require_once "includes/header.php";
$display_type = 'html'; //html, text
}
//set the default
if (!isset($display_results)) {
$display_results = true;
}
//load the default database into memory and compare it with the active database
require_once "includes/lib_schema.php";
db_upgrade_schema ($db, $db_type, $db_name, $display_results);
unset($apps);
//upgrade the domains
require_once "core/upgrade/upgrade_domains.php";
if ($display_results && $display_type == "html") {
echo "<br />\n";
echo "<br />\n";
require_once "includes/footer.php";
}
?>
+296
View File
@@ -0,0 +1,296 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
/*
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$start_time = $mtime;
*/
include "root.php";
require_once "includes/require.php";
require_once "includes/phpsvnclient/phpsvnclient.php";
if (!isset($display_results)) {
$display_results = true;
}
if (strlen($_SERVER['HTTP_USER_AGENT']) > 0) {
require_once "includes/checkauth.php";
if (permission_exists('upgrade_svn') || if_group("superadmin")) {
//echo "access granted";
}
else {
echo "access denied";
exit;
}
}
else {
$display_results = false; //true false
//$display_type = 'csv'; //html, csv
}
ini_set('display_errors', '0');
ini_set(max_execution_time,3600);
clearstatcache();
if ($display_results) {
require_once "includes/header.php";
}
$svn_url = 'http://fusionpbx.googlecode.com/svn/';
$svn_path = '/trunk/fusionpbx/';
//set path_array
$sql = "";
$sql .= "select * from v_src ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$path = trim($row["path"]);
$path_array[$path][type] = $row["type"];
$path_array[$path][last_mod] = $row["last_mod"];
}
unset ($prep_statement);
$svn = new phpsvnclient($svn_url);
//$svn_version = $svn->getVersion();
$svn_directory_tree = $svn->getDirectoryTree($svn_path);
if ($display_results) {
echo "<table width='100%' border='0' cellpadding='20' cellspacing='0'>\n";
echo "<tr>\n";
echo "<th>Type</th>\n";
echo "<th>Last Modified</th>\n";
echo "<th>Path</th>\n";
echo "<th>Status/Size</th>\n";
echo "<th>MD5 file</th>\n";
echo "<th>MD5 xml</th>\n";
echo "<th>Action</th>\n";
echo "<tr>\n";
}
//$db->beginTransaction();
foreach ($svn_directory_tree as &$row) {
$md5_match = false;
$xml_type = $row[type];
$xml_relative_path = trim(str_replace(trim($svn_path,'/'),"",$row[path]));
$xml_last_mod = $row[last_mod];
$new_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH . $xml_relative_path;
if (file_exists($new_path)) {
$exists = true;
}
else {
$exists = false;
}
if ( $xml_type == 'file' ) {
$xml_file_path = trim($row[path]); //we need this to download the file from svn
$md5_xml = $row[md5];
if ($exists) {
$md5_file = md5_file($new_path);
if ($md5_xml == $md5_file){
$md5_match = true;
}
}
else {
$md5_match = false;//???
$md5_file = '';
}
}
else {
$md5_xml = '';//directory has no md5
}
if (strlen($xml_relative_path) > 0) {
if ($display_results) {
if ($xml_type == 'file' && !$md5_match) {
echo "<tr>\n";
echo "<td class='row_style1'>$xml_type</td>\n";
echo "<td class='row_style1'>$xml_last_mod</td>\n";
echo "<td class='row_style1'>$xml_relative_path</td>\n";
echo "<td class='row_style1'>$exists</td>\n";
//echo "<td class='row_style1'>$xml_size</td>\n";
echo "<td class='row_style1'>$md5_file</td>\n";
echo "<td class='row_style1'>$md5_xml</td>\n";
echo "<td class='row_style1'>$md5_match </td>\n";
//file_get_contents($svn_url.$svn_path.$xml_relative_path);</td>\n";
echo "<td class='row_style1'>\n";
}
}
//update the v_scr data
if ($xml_type=='file' && strlen($path_array[$xml_relative_path]['type']) == 0) {
//insert a new record into the src table
$sql ="";
$sql .= "insert into v_src ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "type, ";
$sql .= "last_mod, ";
$sql .= "path ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'$xml_type', ";
$sql .= "'$xml_last_mod', ";
$sql .= "'$xml_relative_path' ";
$sql .= ")";
//echo "$sql<br />\n";
}
else {
if ($xml_type=='file' && !$md5_match) {//update changed files
//update the src table
$sql ="";
$sql .= "update v_src set ";
$sql .= "type = '$xml_type', ";
$sql .= "last_mod = '$xml_last_mod' ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and path = '$xml_relative_path' ";
}
}
//if the path exists and is a file
if ($exists && $xml_type == 'file') {
//the md5 of the xml file and the local file do not match
if ($md5_match) {
if ($display_results) {
//echo "current "; //the file is up to date
}
}
else {
/* if ($xml_file_path == '/core/upgrade/upgrade_svn.php' ) {
if ($display_results) {
echo "white list"; //the file is up to date
}
continue;
}
*/ //get the remote file contents
$file_content = $svn->getFile($xml_file_path);
//the md5 of the local file and the remote content match
if (md5_file($new_path) == md5($file_content)) {
if ($display_results) {
//echo "current 2 "; //the file is up to date
}
}
else {
//make sure the string matches the file md5 that was recorded.
if (strlen($file_content) > 0) {
$tmp_fh = fopen($new_path, 'w');
fwrite($tmp_fh, $file_content);
fclose($tmp_fh);
}
//display the results
if ($display_results) {
echo "<strong style='color: #FF0000;'> ";
if (is_writable($new_path)) {
echo "updated ";
}
else {
echo "not writable ";
}
echo "</strong>";
}
}
}
//unset the variable
unset($file_content);
}
else {
//if the path does not exist create it and then add it to the database
//echo "file is missing |";
if ($xml_type == 'directory' && !$exists) {
//make sure the directory exists
mkdir (dirname($new_path), 0755, true);
}
if ($xml_type == 'file') {
//make sure the directory exists
if (!is_dir(dirname($new_path))){
mkdir (dirname($new_path), 0755, true);
}
//get the remote file contents
$file_content = $svn->getFile($xml_file_path);
//make sure we got some data.
if (strlen($file_content) > 0) {
$tmp_fh = fopen($new_path, 'w');
fwrite($tmp_fh, $file_content);
fclose($tmp_fh);
}
if ($display_results) {
echo "<strong style='color: #FF0000;'> ";
if (is_writable($new_path)) {
echo "added/restored";
}
else {
echo "not writable ";
}
echo "</strong>";
//echo "<br />\n";
}
//unset the variable
unset($file_content);
}
}
if ($display_results) {
if ($xml_type == 'file' && !$md5_match) {
echo "&nbsp;";
echo "</td>\n";
echo "<tr>\n";
}
}
//update the database
if (strlen($sql) > 0) {
$db->exec(check_sql($sql));
//echo "$sql<br />\n";
}
unset($sql);
}
}
//$db->commit();
//clearstatcache();
if ($display_results) {
echo "</table>\n";
require_once "includes/footer.php";
}
/*
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$end_time = $mtime;
$total_time = ($end_time - $start_time);
echo "This page was created in ".$total_time." seconds";
*/
?>