Skip to content

Commit

Permalink
1.3 send email with download link
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola1971 committed Sep 28, 2017
1 parent a4de880 commit 9eb165b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 7 additions & 4 deletions install/assets/plugins/AutoEvoBackup.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*
* @author Nicola Lambathakis
* @category plugin
* @version 1.2 RC3
* @version 1.3
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
* @internal @events OnBeforeManagerLogout
* @internal @disabled 1
* @internal @installset base
* @internal @modx_category Admin
* @internal @properties &allow_backup=Run Backup for:;list;All,AdminOnly,AdminExcluded,ThisRoleOnly,ThisUserOnly;All &ThisRole=Run only for this role:;string;;;(role id) &ThisUser=Run only for this user:;string;;;(username) &bkpmode= mode:;list;dbonly,light,medium,full;dbonly;;Choose a Backup type &rootfiles= rootfiles:;list;0,1;0;;add index index-ajax robots and htaccess to the backup &zipdb= zip .sql:;list;0,1;0;;include .sql db backup to the zip &deletesql= delete sql:;list;0,1;0;;after zip delete sql file from backup folder &customfiles= enable custom files:;list;0,1;0;;add custom files and folders to the backup &customfold1=Custom file or folder 1:;string;; &customfold2=Custom file or folder 2:;string;; &customfold3=Custom file or folder 3:;string;; &customfold4=Custom file or folder 4:;string;; &customfold5=Custom file or folder 5:;string;; &number_of_backups= Number of backups:;string;6;;number of incremental backups before overwrite
* @internal @properties &allow_backup=Run Backup for:;list;All,AdminOnly,AdminExcluded,ThisRoleOnly,ThisUserOnly;All &ThisRole=Run only for this role:;string;;;(role id) &ThisUser=Run only for this user:;string;;;(username) &bkpmode= mode:;list;dbonly,light,medium,full;dbonly;;Choose a Backup type &rootfiles= rootfiles:;list;0,1;0;;add index index-ajax robots and htaccess to the backup &zipdb= zip .sql:;list;0,1;0;;include .sql db backup to the zip &deletesql= delete sql:;list;0,1;0;;after zip delete sql file from backup folder &customfiles= enable custom files:;list;0,1;0;;add custom files and folders to the backup &customfold1=Custom file or folder 1:;string;; &customfold2=Custom file or folder 2:;string;; &customfold3=Custom file or folder 3:;string;; &customfold4=Custom file or folder 4:;string;; &customfold5=Custom file or folder 5:;string;; &number_of_backups= Number of backups:;string;6;;number of incremental backups before overwrite &sendEmail=Send download backup link:;menu;yes,no;no &SendTo=Send to email address:;string;;;enter email &SendToCC=Send to CC email address:;string;;;enter email &emSubject=Subject:;string;Auto Backup Done;;ie: Auto Backup Done
*/
if(!defined('MODX_BASE_PATH')){die('What are you doing? Get out of here!');}
//events
Expand All @@ -25,6 +25,10 @@ $params['zipdb'] = $zipdb;
$params['deletesql'] = $deletesql;
$params['customfiles'] = $customfiles;
$params['number_of_backups'] = $number_of_backups;
$params['sendEmail'] = $sendEmail;
$params['SendTo'] = $SendTo;
$params['subject'] = $subject;
$params['SendToCC'] = $SendToCC;
// get manager role
$internalKey = $modx->getLoginUserID();
$sid = $modx->sid;
Expand Down Expand Up @@ -59,5 +63,4 @@ $backup = '';
}
$e->output($backup);
return;
?>

?>
22 changes: 19 additions & 3 deletions install/assets/snippets/RunEvoAutoBackup.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Execute a backup of Evo
*
* @author Nicola Lambathakis
* @version 1.2 RC3
* @version 1.3
* @category snippet
* @internal @modx_category admin
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
Expand All @@ -31,7 +31,11 @@ $archive_prefix = (isset($archive_prefix)) ? $archive_prefix : $modx->config
$archive_suffix = date('Y-m-d-Hi') . '_' . $bkp_user;
$archive_file = $modx_backup_dir . $archive_prefix . '_' . $archive_suffix . '_auto_bkp.zip';
$database_filename = $archive_suffix . '_auto_db_bkp.sql';

$sendEmail = isset($sendEmail) ? $sendEmail : 'no';
$SendTo = isset($SendTo) ? $SendTo : $modx->config['emailsender'];
$subject = isset($subject) ? $subject : 'auto-backup done';
$SendToCC = isset($SendToCC) ? $SendToCC : '';

if (file_exists($archive_file)) {
} else {
$dir3 = $modx_root_dir;
Expand Down Expand Up @@ -519,7 +523,19 @@ EOD;
if (array_key_exists($number_of_backups, $files3)) {
unlink($modx_db_backup_dir . $files3[$number_of_backups]);
}
// Send email
if ($sendEmail == 'yes') {
$to = $SendTo;
$txt = "<h1>".$subject."</h1><a href=\"".$modx->config['site_url']."assets/modules/evobackup/downloadsql.php?filename=".basename($database_filename)."\">Download Backup</a>";
$msg = wordwrap($txt,255);
$headers = "From: ".$modx->config['emailsender']."" . "\r\n" .
"CC: ".$SendToCC."";
$my_file = $archive_prefix . '_' . $archive_suffix . '_auto_bkp.zip';
$my_path = $modx->config['site_url'].$modx_db_backup_dir;
mail($to,$subject,$msg,$headers);
}
// end Send email
} else {
$o->setError(1, "Unable to Backup Database");
$o->dumpError();
Expand Down

0 comments on commit 9eb165b

Please sign in to comment.