Index: branches/RC/core/units/sections/sections_config.php =================================================================== diff -u -N -r10455 -r10718 --- branches/RC/core/units/sections/sections_config.php (.../sections_config.php) (revision 10455) +++ branches/RC/core/units/sections/sections_config.php (.../sections_config.php) (revision 10718) @@ -289,16 +289,6 @@ 'SectionPrefix' => 'adm', ), - 'in-portal:backup' => Array ( - 'parent' => 'in-portal:tools', - 'icon' => 'in-portal:tool_backup', - 'label' => 'la_tab_Backup', - 'url' => Array ('index_file' => 'backup/backup1.php', 'pass' => 'm'), - 'permissions' => Array ('view'), - 'priority' => 2, - 'type' => stTREE, - ), - 'in-portal:restore' => Array ( 'parent' => 'in-portal:tools', 'icon' => 'in-portal:tool_restore', Index: branches/RC/core/units/admin/admin_config.php =================================================================== diff -u -N -r10665 -r10718 --- branches/RC/core/units/admin/admin_config.php (.../admin_config.php) (revision 10665) +++ branches/RC/core/units/admin/admin_config.php (.../admin_config.php) (revision 10718) @@ -20,6 +20,8 @@ 'tree_tools' => Array('format' => '!la_section_overview!'), 'system_tools' => Array('format' => '!la_title_SystemTools!'), + + 'backup' => Array('format' => '!la_performing_backup!'), 'no_permissions' => Array('format' => '!la_title_NoPermissions!'), @@ -52,6 +54,27 @@ 'show_mode' => smDEBUG, 'type' => stTREE, ), + + 'in-portal:backup_new' => Array ( + 'parent' => 'in-portal:tools', + 'icon' => 'in-portal:tool_backup', + 'label' => 'la_tab_Backup', + 'url' => Array ('t' => 'tools/backup1', 'pass' => 'm'), + 'permissions' => Array ('view'), + 'priority' => 2.5, + 'type' => stTREE, + ), + + 'in-portal:service' => Array( + 'parent' => 'in-portal:tools', + 'icon' => 'conf_general', + 'label' => 'la_tab_Service', + 'url' => Array('t' => 'tools/system_tools', 'pass' => 'm'), + 'permissions' => Array('view'), + 'priority' => 10, + 'show_mode' => smDEBUG, + 'type' => stTREE, + ), ), 'Fields' => Array(), // we need empty array because kernel doesn't use virtual fields else Index: branches/RC/kernel/units/sections/sections_config.php =================================================================== diff -u -N -r10455 -r10718 --- branches/RC/kernel/units/sections/sections_config.php (.../sections_config.php) (revision 10455) +++ branches/RC/kernel/units/sections/sections_config.php (.../sections_config.php) (revision 10718) @@ -289,16 +289,6 @@ 'SectionPrefix' => 'adm', ), - 'in-portal:backup' => Array ( - 'parent' => 'in-portal:tools', - 'icon' => 'in-portal:tool_backup', - 'label' => 'la_tab_Backup', - 'url' => Array ('index_file' => 'backup/backup1.php', 'pass' => 'm'), - 'permissions' => Array ('view'), - 'priority' => 2, - 'type' => stTREE, - ), - 'in-portal:restore' => Array ( 'parent' => 'in-portal:tools', 'icon' => 'in-portal:tool_restore', Index: branches/RC/core/units/admin/admin_events_handler.php =================================================================== diff -u -N -r10580 -r10718 --- branches/RC/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 10580) +++ branches/RC/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 10718) @@ -519,4 +519,245 @@ $event->status = erSTOP; return ; } + + + /** + * Backup all data + * + * @param kEvent $event + */ + function OnBackup(&$event) + { + + $a_tables = $this->Conn->GetCol('SHOW TABLES'); // array_keys($tables); + $TableNames = Array(); + for($x=0;$x"; print_r($TableNames); echo ""; +// exit; + + $backupProgress = Array ( + 'table_num' => 0, + 'table_names' => $TableNames, + 'table_count' => count($TableNames), + 'record_count' => 0, + 'file_name' => $this->Application->ConfigValue('Backup_Path')."/dump".adodb_mktime().".txt", + ); + $this->Application->RemoveVar('adm.backupcomplete_filename'); + $this->Application->RemoveVar('adm.backupcomplete_filesize'); + + $out = array(); + + for($x=0;$xGetTableCreate($TableNames[$x]); + } + } + + $fp = fopen($backupProgress['file_name'], 'a'); + + $sql = "SELECT Name, Version FROM ".TABLE_PREFIX."Modules"; + $r = $this->Conn->Query($sql); + foreach ($r AS $a_module) { + $version = $a_module['Version']; + fwrite($fp, "# ".$a_module['Name']." Version: $version;\n"); + } + fwrite($fp, "#------------------------------------------\n\n"); + + fwrite($fp,implode("\n",$out)); + fwrite($fp,"\n"); + + fclose($fp); + + $this->Application->StoreVar('adm.backup_status', serialize($backupProgress)); + $event->redirect = 'tools/backup2'; + } + + /** + * Perform next backup step + * + * @param kEvent $event + */ + function OnBackupProgress(&$event) + { + $done_percent = $this->performBackup(); + + if ($done_percent == 100) { + $event->redirect = 'tools/backup3'; + return ; + } + + echo $done_percent; + $event->status = erSTOP; + } + + /** + * Stops users import & redirect to import template + * + * @param kEvent $event + */ + function OnBackupCancel(&$event) + { + $event->redirect = 'tools/backup1'; + } + + function performBackup() + { + $backupProgress = unserialize($this->Application->RecallVar('adm.backup_status')); +// echo "
"; print_r($backupProgress); echo "
"; +// exit; + $CurrentTable = $backupProgress['table_names'][$backupProgress['table_num']]; + + // get records + $a_records = $this->insert_data($CurrentTable,$backupProgress['record_count'],50,""); +// echo "
"; print_r($a_records); echo "
"; +// exit; + + if ($a_records['num'] < 50) { + $backupProgress['table_num']++; + } else { + $backupProgress['record_count']+=50; + } + + if ($a_records['sql']) { + $fp = fopen($backupProgress['file_name'], 'a'); + fwrite($fp, $a_records['sql']); + fclose($fp); + } + $percent = ($backupProgress['table_num'] / $backupProgress['table_count']) * 100; + if ($percent >= 100) { + $percent = 100; + $this->Application->StoreVar('adm.backupcomplete_filename', $backupProgress['file_name']); + $this->Application->StoreVar('adm.backupcomplete_filesize', filesize($backupProgress['file_name'])); + } else { + $this->Application->StoreVar('adm.backup_status', serialize($backupProgress)); + } + + return round($percent); + + } + + //extracts the rows of data from tables using limits + function insert_data($table, $start, $limit, $mywhere) + { +// global $out; + + if ($mywhere !="") + { + $whereclause= " WHERE ".$mywhere." "; + } + else + { + $whereclause = ""; + } + + $a_data = $this->Conn->Query("SELECT * from $table $whereclause LIMIT $start, $limit"); +// echo "SELECT * from $table $whereclause LIMIT $start, $limit"; +// echo "
"; print_r($a_records); echo "
"; +// exit; + if (!$a_data) { + return Array( + 'num' => 0, + 'sql' => '', + ); + } +// $prefix = GetTablePrefix(); + $rowcount = 0; + $a_fields = array_keys($a_data[0]); + $fields_sql = ''; + foreach ($a_fields AS $field_name) { + $fields_sql .= '`'.$field_name.'`,'; + } + $fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql); + $temp = ''; + foreach ($a_data AS $a_row) + { + $values_sql = ''; + foreach ($a_row as $field_name => $field_value) { + $values_sql .= $this->Conn->qstr($field_value).','; + } + $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql); + $temp .= 'INSERT INTO '.$table.' ('.$fields_sql.') VALUES ('.$values_sql.')'; + } + + $temp=ereg_replace("\n","\\n", $temp); + $temp=ereg_replace("\r","\\r", $temp); + if(strlen(TABLE_PREFIX)) + { + $temp = str_replace("INSERT INTO $prefix","INSERT INTO ",$temp); + } + + return Array( + 'num' => count($a_data), + 'sql' => $temp, + ); + } + + + + function GetTableCreate($table, $crlf="\n") + { + $schema_create = 'DROP TABLE IF EXISTS ' . $table . ';' . $crlf; + $schema_create .="# --------------------------------------------------------".$crlf; + $this->Conn->Query("SET SQL_QUOTE_SHOW_CREATE = 0"); + $tmpres = $this->Conn->Query("SHOW CREATE TABLE $table"); +// echo "
"; print_r($tmpres); echo "
"; +// exit; + if(is_array($tmpres) && isset($tmpres[0])) + { + $tmpres = $tmpres[0]; + $pos = strpos($tmpres["Create Table"], ' ('); + $pos2 = strpos($tmpres["Create Table"], '('); + if ($pos2 != $pos + 1) + { + $pos = $pos2; + $tmpres["Create Table"] = str_replace(",", ",\n ", $tmpres["Create Table"]); + } + + $tmpres["Create Table"] = substr($tmpres["Create Table"], 0, 13) + . (($use_backquotes) ? $tmpres["Table"] : $tmpres["Table"]) + . substr($tmpres["Create Table"], $pos); + $tmpres["Create Table"] = str_replace("\n", $crlf, $tmpres["Create Table"]); + if (preg_match_all('((,\r?\n[\s]*(CONSTRAINT|FOREIGN[\s]*KEY)[^\r\n,]+)+)', $tmpres["Create Table"], $regs)) { + if (!isset($sql_constraints)) { + if (isset($GLOBALS['no_constraints_comments'])) { + $sql_constraints = ''; + } else { + $sql_constraints = $crlf . '#' . $crlf + . '# ' . $GLOBALS['strConstraintsForDumped'] . $crlf + . '#' . $crlf; + } + } + if (!isset($GLOBALS['no_constraints_comments'])) { + $sql_constraints .= $crlf .'#' . $crlf .'# ' . $GLOBALS['strConstraintsForTable'] . ' ' . $table . $crlf . '#' . $crlf; + } + $sql_constraints .= 'ALTER TABLE $table $crlf ' + . preg_replace('/(,\r?\n|^)([\s]*)(CONSTRAINT|FOREIGN[\s]*KEY)/', '\1\2ADD \3', substr($regs[0][0], 2)) + . ";\n"; + $tmpres["Create Table"] = preg_replace('((,\r?\n[\s]*(CONSTRAINT|FOREIGN[\s]*KEY)[^\r\n,]+)+)', '', $tmpres["Create Table"]); + } + $schema_create .= $tmpres["Create Table"]; + } + if(strlen($schema_create)) + { + $schema_create = str_replace("DROP TABLE IF EXISTS ".TABLE_PREFIX,"DROP TABLE ",$schema_create); + $schema_create = str_replace("CREATE TABLE ".TABLE_PREFIX,"CREATE TABLE ",$schema_create); + while(strlen($schema_create && substr($schema_create,-1)!=")")) + { + $schema_create = substr($schema_create,0,-1); + } + } + $schema_create .= "\n# --------------------------------------------------------\n"; + return $schema_create; + } + + + } \ No newline at end of file Index: branches/RC/core/units/configuration/configuration_event_handler.php =================================================================== diff -u -N -r9355 -r10718 --- branches/RC/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 9355) +++ branches/RC/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 10718) @@ -184,7 +184,7 @@ $this->Application->StoreVar('ModuleRootCategory', $selected_ids['c']); $this->finalizePopup($event); } - + } Index: branches/RC/core/units/configuration/configuration_tag_processor.php =================================================================== diff -u -N -r8929 -r10718 --- branches/RC/core/units/configuration/configuration_tag_processor.php (.../configuration_tag_processor.php) (revision 8929) +++ branches/RC/core/units/configuration/configuration_tag_processor.php (.../configuration_tag_processor.php) (revision 10718) @@ -203,6 +203,12 @@ return $cached_ids[$var_name]; } + + function IsWritablePath($params) + { + return is_writable($this->ConfigValue($params)); + } + } ?> \ No newline at end of file