61 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
62 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
63 $this->DatabaseAlgorithms =
get_package(
'database::database_algorithms' ,
'last' , __FILE__ );
64 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
98 $ListOfTables = $DumpCreationConfig->get_setting(
'tables' );
100 if( $ListOfTables ===
'all' )
102 return( $this->DatabaseAlgorithms->get_list_of_tables() );
106 return( explode(
',' , $ListOfTables ) );
109 catch( Exception $e )
145 if( $TableDumpCreationConfig->get_setting(
'delete_existing' ,
false ) )
147 $TableName = $this->Security->get( $TableName ,
'command' );
150 $ClearTableName = str_replace(
151 array( $this->Database->TablenamePrefix ,
'umx_' ) , array(
'' ,
'' ) , $TableName
154 return(
"DROP TABLE IF EXISTS `[lfb]prefix[rfb]$ClearTableName`;\n" );
161 catch( Exception $e )
193 private function get_field_script( $FieldInfo , &$Fields )
197 $FieldName =
'`'.get_field( $FieldInfo ,
'Field' ).
'` ';
198 $FieldType =
get_field( $FieldInfo ,
'Type' ).
' ';
199 $Null =
get_field( $FieldInfo ,
'Null' ) ==
'NO' ?
'NOT NULL ' :
'';
200 $Default =
get_field( $FieldInfo ,
'Default' );
201 $Default = strlen( $Default ) ?
"default '$Default' " :
'';
202 $Extra =
get_field( $FieldInfo ,
'Extra' );
203 if( $Extra ==
'auto_increment' )
205 $Fields[] =
" PRIMARY KEY ( $FieldName)";
207 $Extra = strlen( $Extra ) ?
"$Extra " :
'';
208 return(
" $FieldName$FieldType$Null$Default$Extra" );
210 catch( Exception $e )
246 $TableName = $this->Security->get( $TableName ,
'command' );
247 $Fields = $this->DatabaseAlgorithms->get_list_of_fields( $TableName );
249 foreach( $Fields as $i => $FieldInfo )
251 $Fields[ $i ] = $this->get_field_script( $FieldInfo , $Fields );
254 return( implode(
",\n" , $Fields ) );
256 catch( Exception $e )
292 $TableName = $this->Security->get( $TableName ,
'command' );
294 $Fields = $this->DatabaseAlgorithms->get_list_of_fields( $TableName );
296 foreach( $Fields as $i => $FieldInfo )
298 $Extra =
get_field( $FieldInfo ,
'Extra' );
300 if( $Extra ==
'auto_increment' )
302 $FieldName =
get_field( $FieldInfo ,
'Field' );
303 $MaxValue = $this->Database->select(
"MAX( $FieldName ) AS max_field_value" ,
"`$TableName`" );
304 $MaxValue = intval(
get_field( $MaxValue[ 0 ] ,
'max_field_value' ) ) + 1;
306 return(
"AUTO_INCREMENT=$MaxValue" );
312 catch( Exception $e )
348 $TableName = $this->Security->get( $TableName ,
'command' );
351 $ClearTableName = str_replace(
352 array( $this->Database->TablenamePrefix ,
'umx_' ) , array(
'' ,
'' ) , $TableName
354 $Dump =
"CREATE TABLE `[lfb]prefix[rfb]$ClearTableName` (\n";
356 $Dump .= $this->
get_fields_dump( $TableDumpCreationConfig , $TableName );
358 $Encoding = $TableDumpCreationConfig->get_setting(
'encoding' ,
'utf8' );
360 $Dump .=
"\n) $Autoincrement DEFAULT CHARSET=$Encoding;\n\n";
364 catch( Exception $e )
400 if( $TableDumpCreationConfig->get_setting(
'delete_existing' ,
false ) )
402 $Dump = $this->
get_drop_dump( $TableDumpCreationConfig , $TableName );
404 $Dump .= $this->
get_create_dump( $TableDumpCreationConfig , $TableName );
413 catch( Exception $e )
441 private function prepare_record( $Record )
445 $PlaceHolders = array(
"\r" ,
"\n" ,
'[r]' ,
'[n]' ,
"'" );
447 $Data = array(
'\r' ,
'\n' ,
'\r' ,
'\n' ,
''' );
449 $Record = str_replace( $PlaceHolders , $Data , $Record );
451 return(
"( '".implode(
"' , '" , $Record ).
"' )" );
453 catch( Exception $e )
495 if( isset( $Records[ 0 ] ) )
497 if( strpos( $TableName , $this->Database->TablenamePrefix ) === 0 )
499 $ClearTableName = substr( $TableName , strlen( $this->Database->TablenamePrefix ) );
501 $ClearTableName = str_replace(
'umx_' ,
'', $ClearTableName );
502 $Dump =
"INSERT INTO `[lfb]prefix[rfb]$ClearTableName` ( $Fields ) VALUES \n";
504 foreach( $Records as $i => $Record )
506 $Records[ $i ] = $this->prepare_record( $Record );
509 $Dump .= implode(
",\n" , $Records ).
";\n\n";
514 catch( Exception $e )
552 if( $TableDumpCreationConfig->get_setting(
'records' ,
false ) )
554 $Fields =
get_field_ex( $this->DatabaseAlgorithms->get_list_of_fields( $TableName ) ,
'Field' );
555 $Fields =
'`'.implode(
'` , `' , $Fields ).
'`';
556 $this->Database->query_as(
DB_ARRAY );
557 $Records = $this->Database->select(
'*' ,
"`$TableName`" );
564 catch( Exception $e )
600 $DefaultConfig =
'records;structure;enecoding=utf8;delete_existing';
601 $TableDumpCreationConfig =
get_package_object(
'settings::settings' ,
'last' , __FILE__ );
602 $TableDumpCreationConfig->load_settings(
603 $DumpCreationConfig->get_setting( $TableName , $DefaultConfig )
608 $Dump .= $this->
get_data_dump( $TableDumpCreationConfig , $TableName );
612 catch( Exception $e )
645 $DumpName = $this->Security->get( $DumpName ,
'command' );
646 $DumpCreationConfig->load_file( dirname( __FILE__ ).
"/conf/$DumpName" ,
'#' );
650 foreach( $Tables as $i => $TableName )
655 return( rtrim( $Dump ,
"\n" ) );
657 catch( Exception $e )
689 if( $Options->get_setting(
'dump_settings_form' , 0 ) == 1 )
692 elseif( $Options->get_setting(
'dump' , 0 ) == 1 )
694 $Dump = $this->
get_dump(
'full_dump' );
696 header(
'HTTP/1.0 200 OK' );
697 header(
'Content-type: application/octet-stream' );
698 header(
"Content-Length: ".strlen( $Dump ) );
699 header(
"Content-Disposition: attachment; filename=\"data.sql\"" );
700 header(
'Connection: close' );
709 catch( Exception $e )