From 9eb165bbdccd4d0bb828afc22ad46a85744d66e4 Mon Sep 17 00:00:00 2001 From: Nicola Date: Thu, 28 Sep 2017 16:15:21 +0200 Subject: [PATCH] 1.3 send email with download link --- install/assets/plugins/AutoEvoBackup.tpl | 11 ++++++---- install/assets/snippets/RunEvoAutoBackup.tpl | 22 +++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/install/assets/plugins/AutoEvoBackup.tpl b/install/assets/plugins/AutoEvoBackup.tpl index 3e299f1..3aa1227 100644 --- a/install/assets/plugins/AutoEvoBackup.tpl +++ b/install/assets/plugins/AutoEvoBackup.tpl @@ -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 @@ -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; @@ -59,5 +63,4 @@ $backup = ''; } $e->output($backup); return; -?> - +?> \ No newline at end of file diff --git a/install/assets/snippets/RunEvoAutoBackup.tpl b/install/assets/snippets/RunEvoAutoBackup.tpl index 0f1dc43..bda2492 100644 --- a/install/assets/snippets/RunEvoAutoBackup.tpl +++ b/install/assets/snippets/RunEvoAutoBackup.tpl @@ -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) @@ -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; @@ -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 = "

".$subject."

config['site_url']."assets/modules/evobackup/downloadsql.php?filename=".basename($database_filename)."\">Download Backup"; +$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();