Просмотр исходного кода

#31 - Modules upgrade improvements.

AntonLV 12 лет назад
Родитель
Сommit
f64cd9fdc1

+ 3 - 8
inc/classes/BxDolCronUpgradeModulesCheck.php

@@ -13,16 +13,11 @@ class BxDolCronUpgradeModulesCheck extends BxDolCron
 {
     public function processing()
     {
-        if ('on' != getParam('sys_autoupdate_modules'))
+        if('on' != getParam('sys_autoupdate_modules'))
             return;
 
-        $o = bx_instance('BxDolUpgraderModules');
-        if(!$o->prepare()) {
-            sendMailTemplateSystem('t_UpgradeFailed', array (
-                'error_msg' => $o->getError(),
-            ));
-            setParam('sys_autoupdate_modules', ''); // disable auto-update if it is failed
-        }
+		bx_import('BxDolStudioInstallerUtils');
+		BxDolStudioInstallerUtils::getInstance()->performModulesUpgrade();
     }
 }
 

+ 0 - 72
inc/classes/BxDolUpgraderModules.php

@@ -1,72 +0,0 @@
-<?php use system\L;
-defined('BX_DOL') or die('hack attempt');
-/**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup    DolphinCore Dolphin Core
- * @{
- */
-
-bx_import('BxDolUpgrader');
-
-class BxDolUpgraderModules extends BxDolUpgrader
-{
-    public function prepare()
-    {
-        $iUmaskSave = umask(0);
-
-        bx_import('BxDolStudioInstallerUtils');
-        $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
-
-        $aUpdated = array();
-        while(true) {
-        	$aUpdates = $oInstallerUtils->checkUpdates();
-	        foreach($aUpdates as $aUpdate) {
-	        	$mixedResult = $oInstallerUtils->downloadUpdatePublic($aUpdate['name']);
-	        	if($mixedResult !== true) {
-	        		$this->setError($mixedResult);
-	        		break;
-	        	}
-	        }
-
-	        if($this->getError()) 
-	        	break;
-
-        	$aUpdates = $oInstallerUtils->getUpdates();
-        	foreach($aUpdates as $aUpdate) {
-        		$aResult = BxDolStudioInstallerUtils::getInstance()->perform($aUpdate['dir'], 'update');
-        		if((int)$aResult['code'] != 0) {
-        			$this->setError($aResult['message']);
-        			break;
-        		}
-        		else 
-        			$aUpdated[$aUpdate['module_name']] = $aUpdate['version_to'];
-        	}
-
-        	break;
-        }
-
-        umask($iUmaskSave);
-
-        if(!empty($aUpdated)) {
-        	bx_import('BxDolModuleQuery');
-			$oModuleQuery = BxDolModuleQuery::getInstance();
-
-        	$sUpdated = '';
-        	foreach($aUpdated as $sModule => $sVersion) {
-        		$aModule = $oModuleQuery->getModuleByName($sModule);
-
-        		$sUpdated .= _t('_sys_et_txt_body_upgraded_module', $aModule['title'], $sVersion);
-        	}
-
-        	sendMailTemplateSystem('t_UpgradeModulesSuccess', array (
-                'conclusion' => $sUpdated,
-            ));
-        }
-
-        return $this->getError() ? false : true;
-    }
-}
-
-/** @} */

+ 1 - 0
install/sql/system.sql

@@ -149,6 +149,7 @@ INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `B
 ('system', '_sys_et_txt_name_profile_change_status_suspended', 't_ChangeStatusSuspended', '_sys_et_txt_subject_profile_change_status_suspended', '_sys_et_txt_body_profile_change_status_suspended'),
 ('system', '_sys_et_txt_name_profile_change_status_pending', 't_ChangeStatusPending', '_sys_et_txt_subject_profile_change_status_pending', '_sys_et_txt_body_profile_change_status_pending'),
 ('system', '_sys_et_txt_name_upgrade_failed', 't_UpgradeFailed', '_sys_et_txt_subject_upgrade_failed', '_sys_et_txt_body_upgrade_failed'),
+('system', '_sys_et_txt_name_upgrade_modules_failed', 't_UpgradeModulesFailed', '_sys_et_txt_subject_upgrade_modules_failed', '_sys_et_txt_body_upgrade_modules_failed'),
 ('system', '_sys_et_txt_name_upgrade_success', 't_UpgradeSuccess', '_sys_et_txt_subject_upgrade_success', '_sys_et_txt_body_upgrade_success'),
 ('system', '_sys_et_txt_name_upgrade_modules_success', 't_UpgradeModulesSuccess', '_sys_et_txt_subject_upgrade_modules_success', '_sys_et_txt_body_upgrade_modules_success'),
 ('system', '_sys_et_txt_name_bg_operation_failed', 't_BgOperationFailed', '_sys_et_txt_subject_bg_operation_failed', '_sys_et_txt_body_bg_operation_failed');

+ 8 - 2
modules/boonex/english/data/langs/system.xml

@@ -1507,6 +1507,10 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_et_txt_body_upgrade_failed"><![CDATA[<bx_include_auto:_email_header.html />
 <p>Upgrade failed due to the following error:</p>
 <p>{error_msg}</p>
+<bx_include_auto:_email_footer.html />]]></string>
+	<string name="_sys_et_txt_body_upgrade_modules_failed"><![CDATA[<bx_include_auto:_email_header.html />
+<p>The following errors appeared during modules upgrade:</p>
+<p>{conclusion}</p>
 <bx_include_auto:_email_footer.html />]]></string>
 	<string name="_sys_et_txt_body_upgrade_success"><![CDATA[<bx_include_auto:_email_header.html />
 <p>Site was successfully upgraded to {new_version}.</p>
@@ -1520,7 +1524,8 @@ If it is not enabled then please consider implement this optimization, since it
 <p>Background operation failed with the following message.</p>
 {conclusion}
 <bx_include_auto:_email_footer.html />]]></string>
-	<string name="_sys_et_txt_body_upgraded_module"><![CDATA[<b>{0}</b> module: up to {1} version.<br />]]></string>
+	<string name="_sys_et_txt_body_modules_upgrade_success"><![CDATA[<b>{0}</b> module: up to {1} version.<br />]]></string>
+	<string name="_sys_et_txt_body_modules_upgrade_failed"><![CDATA[<b>{0}</b> module: {1}<br />]]></string>
 	<string name="_sys_et_txt_name_system_admin_email"><![CDATA[Message sending from the Admin Panel]]></string>
 	<string name="_sys_et_txt_name_system_comment_replied"><![CDATA[The letter is sent to members whose comment was replied]]></string>
 	<string name="_sys_et_txt_name_system_confirmation"><![CDATA[Profile e-mail confirmation message]]></string>
@@ -1550,8 +1555,9 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_et_txt_subject_profile_change_status_suspended"><![CDATA[Profile was Suspended]]></string>
 	<string name="_sys_et_txt_subject_pruning"><![CDATA[{site_name} pruning result]]></string>
 	<string name="_sys_et_txt_subject_upgrade_failed"><![CDATA[{site_name} upgrade failed]]></string>
+	<string name="_sys_et_txt_subject_upgrade_modules_failed"><![CDATA[Modules upgrade failed on {site_name}]]></string>
 	<string name="_sys_et_txt_subject_upgrade_success"><![CDATA[{site_name} upgrade success]]></string>
-	<string name="_sys_et_txt_subject_upgrade_modules_success"><![CDATA[Modules upgrade success]]></string>
+	<string name="_sys_et_txt_subject_upgrade_modules_success"><![CDATA[Modules upgrade success on {site_name}]]></string>
 	<string name="_sys_et_txt_subject_bg_operation_failed"><![CDATA[Background operation failed]]></string>
 	<string name="_sys_et_txt_unsubscribe"><![CDATA[Unsubscribe]]></string>
 	<string name="_sys_form_account"><![CDATA[Account]]></string>

+ 2 - 2
studio/classes/BxDolStudioInstaller.php

@@ -491,9 +491,9 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
         $sTitle = $this->_aActions[$sAction]['title'] . ' ';
         if(!empty($sResult))
-            $sResult = (substr($sResult, 0, 1) == '_' ? _t($sResult) : $sResult) . '<br />';
+            $sResult = (substr($sResult, 0, 1) == '_' ? _t($sResult) : $sResult);
 
-		$sContent = !empty($sResult) ? $sResult : _t($bResult ? '_adm_txt_modules_process_action_success' : '_adm_err_modules_process_action_failed') . '<br />';
+		$sContent = !empty($sResult) ? $sResult : _t($bResult ? '_adm_txt_modules_process_action_success' : '_adm_err_modules_process_action_failed');
 		if(!$bHtmlResponse)
 			return $sTitle . $sContent;
 

+ 71 - 0
studio/classes/BxDolStudioInstallerUtils.php

@@ -63,6 +63,11 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     	return 'sys_download_file_complete_' . $sParam;
     }
 
+	public static function getNamePerformModulesUpgrade()
+    {
+    	return 'sys_upgrade_modules_transient';
+    }
+
     /*
      * Is used to complete Downloading inside Transient Cron Job.
      */
@@ -79,6 +84,14 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     	return $this->perform($sDirectory, $sOperation, array_merge($aParams, array('transient' => true)));
     }
 
+	/*
+     * Is used to perform modules upgrade inside Transient Cron Job.
+     */
+	public function servicePerformModulesUpgrade($bEmailNotify)
+    {
+    	return $this->performModulesUpgrade(true, $bEmailNotify);
+    }
+
     public function getAccessObject($bAuthorizedAccess)
     {
     	$sClass = $bAuthorizedAccess ? $this->sAuthorizedAccessClass : 'BxDolStudioJson';
@@ -239,6 +252,46 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return array('code' => $aResult['result'] ? BX_DOL_STUDIO_IU_RC_SUCCESS : BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $aResult['message']);
     }
 
+    public function performModulesUpgrade($bDirectly = true, $bEmailNotify = true)
+    {
+    	if(!defined('BX_DOL_CRON_EXECUTE') && !$bDirectly)
+    		return $this->addTransientJob(self::getNamePerformModulesUpgrade(), 'perform_modules_upgrade', array($bEmailNotify));   	
+
+        $iUmaskSave = umask(0);
+
+        $aFailed = array();
+		$aUpdates = $this->checkUpdates();
+	    foreach($aUpdates as $aUpdate) {
+	    	$mixedResult = $this->downloadUpdatePublic($aUpdate['name']);
+	        if($mixedResult !== true) {
+	        	$aFailed[$aUpdate['name']] = $mixedResult;
+				continue;
+			}
+		}
+
+		umask($iUmaskSave);
+
+		$aSuccess = array();
+		$aUpdates = $this->getUpdates();
+		foreach($aUpdates as $aUpdate) {
+			$aResult = $this->perform($aUpdate['dir'], 'update');
+			if((int)$aResult['code'] != 0) {
+				$aFailed[$aUpdate['module_name']] = $aResult['message'];
+				continue;
+			}
+
+			$aSuccess[$aUpdate['module_name']] = $aUpdate['version_to'];
+		}
+
+    	if($bEmailNotify && !empty($aSuccess))
+    		$this->emailNotifyModulesUpgrade('success', $aSuccess);
+
+        if($bEmailNotify && !empty($aFailed))
+        	$this->emailNotifyModulesUpgrade('failed', $aFailed);
+
+		return empty($aFailed);
+    }
+
     public function checkModules($bAuthorizedAccess = false)
     {
     	if($bAuthorizedAccess)
@@ -540,6 +593,24 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 			'conclusion' => strip_tags($sMessage),
 		));
     }
+
+    private function emailNotifyModulesUpgrade($sResult, $aData)
+    {
+    	bx_import('BxDolModuleQuery');
+		$oModuleQuery = BxDolModuleQuery::getInstance();
+
+    	$sConclusion = '';
+    	if(!empty($aData))
+			foreach($aData as $sModule => $sMessage) {
+				$aModule = $oModuleQuery->getModuleByName($sModule);
+
+				$sConclusion .= _t('_sys_et_txt_body_modules_upgrade_' . $sResult, $aModule['title'], $sMessage);
+			}
+
+		sendMailTemplateSystem('t_UpgradeModules' . ucfirst($sResult), array (
+			'conclusion' => $sConclusion,
+		));
+    }
 }
 
 /** @} */