Ejemplo n.º 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());
     }
 }
Ejemplo n.º 2
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;
 }