diff --git a/e107_admin/cron.php b/e107_admin/cron.php index 96d128a79..f45702547 100644 --- a/e107_admin/cron.php +++ b/e107_admin/cron.php @@ -47,7 +47,7 @@ class cron_admin extends e_admin_dispatcher protected $adminMenu = array( 'main/list' => array('caption'=> 'Manage', 'perm' => '0'), - // 'main/create' => array('caption'=> LAN_CREATE, 'perm' => '0'), + 'main/refresh' => array('caption'=> "Refresh", 'perm' => '0','url'=>'cron.php'), // 'main/prefs' => array('caption'=> 'Settings', 'perm' => '0'), // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0') ); @@ -151,9 +151,16 @@ class cron_admin_ui extends e_admin_ui 'description' => 'Process bounce retriggers
Only needed if retriggering of bans enabled.', 'available' => e107::getPref('ban_retrigger') ), + 4 => array( + 'name' => 'Database Backup', + 'category' => 'backup', + 'function' => 'dbBackup', + 'description' => 'Backup the system database to '.e_SYSTEM.'backups/', + 'available' => e107::getPref('ban_retrigger') + ), ); - if(!$_GET['action']) + if(!$_GET['action'] || $_GET['action'] == 'refresh') { $this->cronImport($cronDefaults); // import Core Crons (if missing) diff --git a/e107_handlers/cron_class.php b/e107_handlers/cron_class.php index f7c663bf4..ccd1e3812 100644 --- a/e107_handlers/cron_class.php +++ b/e107_handlers/cron_class.php @@ -93,6 +93,64 @@ class _system_cron } } + // Very basic and needs improvement. (for large DBs) + function dbBackup() + { + require(e_BASE."e107_config.php"); + + $sql = e107::getDb(); + $dbtable = $mySQLdefaultdb; // TODO - retrieve this in a better way. (without including e107_config) + + $backupFile = e_SYSTEM."backups/".SITENAME."_".date("Y-m-d-H-i-s").".sql"; + $result = mysql_list_tables($dbtable); + + while ($tab = mysql_fetch_array($result, MYSQL_NUM)) + { + $table = $tab[0]; + $text = ""; + + $sql->db_Select_gen("SHOW CREATE TABLE `".$table."`"); + $row2 = $sql->db_Fetch(); + $text .= $row2['Create Table']; + $text .= ";\n\n"; + + $sql->db_Select_gen("SELECT * FROM `".$table."`"); + $data_array = array(); + + while($row = $sql->db_Fetch()) + { + if(!$fields) + { + $fields = array_keys($row); + } + + $d = array(); + foreach($fields as $val) + { + $d[] = "'".mysql_real_escape_string($row[$val])."'"; + } + + $data_array[] = "(".implode(", ",$d).")"; + + } + + + $text .= "\nINSERT INTO `".$table."` (`".implode("` ,`",$fields)."`) VALUES \n"; + $text .= implode(",\n",$data_array); + $text .= ";\n\n\n"; + $c++; + + file_put_contents($backupFile,$text,FILE_APPEND); + unset($fields); + + } + + + + } + + + }