public function exec_create_full()
{
if (!defined('MW_BACKUP_STARTED')) {
define('MW_BACKUP_STARTED', 1);
} else {
return false;
}
$start = microtime_float();
if (defined('MW_CRON_EXEC')) {
} else {
only_admin_access();
}
@ob_end_clean();
ignore_user_abort(true);
$back_log_action = 'Preparing to zip';
$this->log_action($back_log_action);
ini_set('memory_limit', '512M');
set_time_limit(0);
$here = $this->get_bakup_location();
$filename = $here . 'full_backup_' . date('Y-M-d-His') . '_' . uniqid() . '' . '.zip';
$userfiles_folder = userfiles_path();
$locations = array();
$locations[] = userfiles_path();
//$locations[] = $filename2;
$fileTime = date('D, d M Y H:i:s T');
$db_file = $this->create();
$zip = new \Microweber\Utils\Zip($filename);
$zip->setZipFile($filename);
$zip->setComment("Microweber backup of the userfiles folder and db.\n \n The Microweber version at the time of backup was {MW_VERSION}\n \nCreated on " . date('l jS \\of F Y h:i:s A'));
if (isset($db_file['filename'])) {
$filename2 = $here . $db_file['filename'];
if (is_file($filename2)) {
$back_log_action = 'Adding sql restore to zip';
$this->log_action($back_log_action);
$zip->addLargeFile($filename2, 'mw_sql_restore.sql', filectime($filename2), 'SQL Restore file');
// $zip->addFile(file_get_contents($filename2), 'mw_sql_restore.sql', filectime($filename2));
}
}
$this->log_action(false);
$back_log_action = 'Adding files to zip';
$this->log_action($back_log_action);
$zip->addDirectoryContent(userfiles_path(), '', true);
$back_log_action = 'Adding userfiles to zip';
$this->log_action($back_log_action);
// $zip = $zip->finalize();
$filename_to_return = $filename;
$end = microtime_float();
$end = round($end - $start, 3);
$back_log_action = "Backup was created for {$end} sec!";
$this->log_action($back_log_action);
sleep(5);
$back_log_action = 'reload';
$this->log_action($back_log_action);
sleep(5);
$this->log_action(false);
return array('success' => "Backup was created for {$end} sec! {$filename_to_return}", 'filename' => $filename_to_return, 'runtime' => $end);
}