示例#1
0
 /**
  * Send backup success delete email
  *
  * @param Mageplace_Backup_Model_Profile $profile
  * @param array|string                   $errors
  */
 public function sendErrorDeleteEmail($profile, $errors)
 {
     try {
         if (!$profile instanceof Mageplace_Backup_Model_Profile) {
             throw Mage::exception('Mageplace_Backup', Mage::helper('mpbackup')->__('Profile object is wrong'));
         }
         if (empty($errors) || !is_array($errors) && !is_string($errors)) {
             throw Mage::exception('Mageplace_Backup', Mage::helper('mpbackup')->__('Errors list is empty'));
         }
         if (!$profile->getData(Mageplace_Backup_Model_Profile::CRON_ERROR_EMAIL)) {
             Mage::log('MPBackup send error email not selected');
         } else {
             /* @var Mage_Core_Model_Translate $translate */
             $translate = Mage::getSingleton('core/translate');
             $translate->setTranslateInline(false);
             /* @var Mage_Core_Model_Email_Template $emailTemplate */
             $emailTemplate = Mage::getModel('core/email_template');
             $emailTemplate->setDesignConfig(array('area' => 'backend'))->sendTransactional($profile->getData(Mageplace_Backup_Model_Profile::CRON_ERROR_DELETE_EMAIL_TEMPLATE), $profile->getData(Mageplace_Backup_Model_Profile::CRON_ERROR_DELETE_EMAIL_IDENTITY), $profile->getData(Mageplace_Backup_Model_Profile::CRON_ERROR_DELETE_EMAIL), null, array('profile_id' => $profile->getId(), 'profile_name' => $profile->getProfileName(), 'warnings' => is_array($errors) ? join("\n", $errors) : $errors));
             $translate->setTranslateInline(true);
         }
     } catch (Exception $e) {
         Mage::logException($e);
         Mage::log('MPBackup send error email has errors: ' . $e->getMessage());
     }
 }
示例#2
0
 /**
  * Helper function to reveive on row click url
  *
  * @param Mageplace_Backup_Model_Profile $row Current rows dataset
  *
  * @return string URL for current row's onclick event
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('*/*/edit', array('backup_id' => $row->getBackupId()));
 }
示例#3
0
 public function rotationDelete()
 {
     $this->initBackupData();
     try {
         if (!$this->_profile) {
             throw Mage::exception('Mageplace_Backup', $this->_helper()->__('Select profile first'));
         }
         if ($this->_profile->getData(Mageplace_Backup_Model_Profile::CRON_DELETE_TYPE) != Mageplace_Backup_Model_Profile::CRON_DELETE_TYPE_ROTATION) {
             return;
         }
         $number = (int) $this->_profile->getData(Mageplace_Backup_Model_Profile::CRON_DELETE_TYPE_ROTATION_NUMBER);
         if ($number < 1) {
             return;
         }
         /** @var Mageplace_Backup_Model_Mysql4_Backup_Collection $collection */
         $collection = $this->getCollection()->addFilter('profile_id', $this->_profileId)->addOrder('backup_creation_date', Mageplace_Backup_Model_Mysql4_Backup_Collection::SORT_ORDER_ASC);
         $total = $collection->count();
         if ($total <= $number) {
             return;
         }
         $stat = array(Mageplace_Backup_Helper_Email::DELETE_STAT_DELETED => 0, Mageplace_Backup_Helper_Email::DELETE_STAT_BACKUPS => array(), Mageplace_Backup_Helper_Email::DELETE_STAT_ERRORS => array());
         /** @var Mageplace_Backup_Model_Backup $backup */
         foreach ($collection->getIterator() as $backup) {
             if ($total <= $number) {
                 break;
             }
             $id = $backup->getId();
             $name = $backup->getBackupName();
             $backup->deleteRecordAndFiles(false);
             if (!Mage::getModel('mpbackup/backup')->load($id)->getId()) {
                 $stat[Mageplace_Backup_Helper_Email::DELETE_STAT_DELETED]++;
                 $stat[Mageplace_Backup_Helper_Email::DELETE_STAT_BACKUPS][] = $name;
             }
             $stat[Mageplace_Backup_Helper_Email::DELETE_STAT_ERRORS] = array_merge($stat[Mageplace_Backup_Helper_Email::DELETE_STAT_ERRORS], $backup->getDeleteErrors());
             $total--;
         }
         Mage::getModel('mpbackup/cron')->sendSuccessDeleteEmail($this->_profile, $stat);
     } catch (Exception $e) {
         Mage::logException($e);
         if (isset($this->_profile)) {
             Mage::getModel('mpbackup/cron')->sendErrorDeleteEmail($this->_profile, $e->getMessage());
         }
     }
 }
示例#4
0
 /**
  * @param Mageplace_Backup_Model_Profile $profile
  * @param Mageplace_Backup_Model_Cron_Schedule $schedule
  * @param bool $test
  *
  * @return bool
  * @throws Exception
  * @throws Zend_Http_Client_Exception
  * @throws Mage_Core_Exception
  * @throws Mageplace_Backup_Exception
  */
 public function backupRun($profile, $schedule, $test = false)
 {
     $profileId = $profile->getId();
     if ($test) {
         $backupName = Mage::helper('mpbackup')->__('TEST Backup - %s', Mage::app()->getLocale()->storeDate(null, null, true));
         $backupDescription = Mage::helper('mpbackup')->__('Current backup was automatically created by TEST script');
     } else {
         $backupName = Mage::helper('mpbackup')->__('Backup - %s', Mage::app()->getLocale()->storeDate(null, null, true));
         $backupDescription = Mage::helper('mpbackup')->__('Current backup was automatically created by cron script');
     }
     $timeout = (int) $profile->getData(Mageplace_Backup_Model_Profile::COLUMN_MULTIPROCESS_CRON_TIME);
     Mage::setIsDeveloperMode(true);
     ini_set('display_errors', 1);
     /** @var $backupItem Mageplace_Backup_Model_Backup_Item */
     $backupItem = Mage::getModel('mpbackup/backup')->setProfile($profileId)->setBackupName($backupName)->setBackupFilename('cron_')->setBackupDescription($backupDescription)->setBackupCron(1)->initialize();
     if (!($secret = $backupItem->getSecret())) {
         throw Mage::exception('Mageplace_Backup', Mage::helper('mpbackup')->__('Backup secret code is wrong.'));
     }
     $schedule->setBackupId($backupItem->getBackup()->getId());
     $sid = null;
     $error = null;
     $params = $backupItem->toArray();
     if ($profile->getData(Mageplace_Backup_Model_Profile::COLUMN_MULTIPROCESS_CRON_ENABLE)) {
         try {
             Mage::helper('mpbackup')->request(Mage::helper('mpbackup/url')->getWrapperUrl(null, null, $profileId), $params, $profile, 1);
         } catch (Exception $e) {
             throw $e;
         }
         return false;
     }
     if (!@class_exists('Mageplace_Backup_BackupController')) {
         require_once 'Mageplace/Backup/controllers/BackupController.php';
     }
     do {
         try {
             Mage::app()->getRequest()->setParam(Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM, $sid);
             Mage::app()->getRequest()->setPost($params);
             $controller = new Mageplace_Backup_BackupController(Mage::app()->getRequest(), Mage::app()->getResponse());
             $request = $controller->getRequest();
             $response = $controller->getResponse();
             $step = $controller->backupAction(true);
         } catch (Exception $e) {
             Mage::logException($e);
             $error = $e->getMessage();
             break;
         }
         if (!$step instanceof Mageplace_Backup_Model_Backup_Step) {
             $error = strval($step);
             break;
         }
         $sid = $step->getSid();
         $params = $step->toArray();
     } while (!$step->isFinished());
     $backup = Mage::getModel('mpbackup/backup')->loadBySecret($secret);
     if ($error !== null) {
         if (empty($error)) {
             $error = Mage::helper('mpbackup')->__('Empty error body');
         }
         try {
             if (!$backup->isFinished() || $backup->isSuccessFinished()) {
                 $backup->finishBackupProcess($error);
             }
         } catch (Exception $e) {
             Mage::logException($e);
             $error .= PHP_EOL . $e->getMessage();
             $backup->criticalSave($error);
         }
         throw Mage::exception('Mageplace_Backup', $error);
     }
     $this->sendSuccessEmail($profile, $backup);
     return true;
 }
示例#5
0
 /**
  * Helper function to reveive on row click url
  *
  * @param Mageplace_Backup_Model_Profile $row Current rows dataset
  * @return string URL for current row's onclick event
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('*/*/edit', array('profile_id' => $row->getProfileId()));
 }