Ver Fonte

#73 - add setting options for auto-update

Alex Trofimov há 12 anos atrás
pai
commit
626bb1dee0

+ 4 - 2
inc/classes/BxDolCronUpgradeCheck.php

@@ -13,8 +13,10 @@ class BxDolCronUpgradeCheck extends BxDolCron
 {
     public function processing()
     {
-        bx_import('BxDolUpgrader');
-        $o = new BxDolUpgrader();
+        if ('on' != getParam('sys_autoupdate_system'))
+            return;
+
+        $o = bx_instance('BxDolUpgrader');
         $o->prepare();
     }
 }

+ 5 - 2
inc/classes/BxDolInstallerHasher.php

@@ -75,10 +75,13 @@ class BxDolInstallerHasher extends BxDolInstallerUtils
         return true;
     }
 
-    public function checkSystemFilesHash () 
+    public function checkSystemFilesHash (&$fChangedFilesPercent) 
     {
         $aFiles = $this->getSystemFilesHash ();
-        return $this->hashCheck($aFiles, $this->_iSystemModuleId);
+        $aFilesChanged = $this->hashCheck($aFiles, $this->_iSystemModuleId);
+        if (null !== $fChangedFilesPercent && 0 != count($aFiles))
+            $fChangedFilesPercent = count($aFilesChanged) / count($aFiles);
+        return $aFilesChanged;
     }
 }
 

+ 15 - 6
inc/classes/BxDolUpgrader.php

@@ -7,6 +7,8 @@
  * @{
  */
 
+define('BX_FORCE_AUTOUPDATE_MAX_CHANGED_FILES_PERCENT', 0.05);
+
 class BxDolUpgrader extends BxDol
 {
     protected $_sUrlVersionCheck = 'http://rss.boonex.com/u/';
@@ -28,14 +30,21 @@ class BxDolUpgrader extends BxDol
             if (!$this->isUpgradeAvailable($aVersionUpdateInfo))
                 break;
 
-            // TODO: check db version and files version (files version file need to be added)
+            if (BX_DOL_VERSION != bx_get_ver()) {
+                $this->setError(_t('_sys_upgrade_db_and_files_versions_different'));
+                break;
+            }
 
-            // TODO: add setting opton to force update even if some of the files were modified (3%-5%)
-            $aFailedFiles = $this->checkFilesChecksums ();
-            if (!empty($aFailedFiles)) {
+            $fChangedFilesPercent = 1;
+            $aFailedFiles = $this->checkFilesChecksums ($fChangedFilesPercent);
+            $bAutoupdateForceModifiedFiles = ('on' == getParam('sys_autoupdate_force_modified_files'));
+            if (!empty($aFailedFiles) && !$bAutoupdateForceModifiedFiles) {
                 $this->setError(_t('_sys_upgrade_files_checksum_failed', implode(',', $aFailedFiles)));
                 break;
             }
+            elseif ($fChangedFilesPercent > BX_FORCE_AUTOUPDATE_MAX_CHANGED_FILES_PERCENT && $bAutoupdateForceModifiedFiles) {
+                $this->setError(_t('_sys_upgrade_files_checksum_failed_too_many', round($fChangedFilesPercent * 100)));
+            }
 
             if (!($sPatchPath = $this->downloadPatch ($aVersionUpdateInfo))) {
                 $this->setError(_t('_sys_upgrade_patch_download_failed'));
@@ -144,10 +153,10 @@ class BxDolUpgrader extends BxDol
         return $sRootFolder ? $sTmpFolder . '/' . trim($sRootFolder, '/') . '/' : false;
     }
 
-    protected function checkFilesChecksums ()
+    protected function checkFilesChecksums (&$fChangedFilesPercent)
     {
         $oHasher = bx_instance('BxDolInstallerHasher');
-        return $oHasher->checkSystemFilesHash();
+        return $oHasher->checkSystemFilesHash($fChangedFilesPercent);
     }
 
     protected function isValidPatch ($sUnpackedPath, $aVersionUpdateInfo)

+ 1 - 1
inc/utils.inc.php

@@ -1066,7 +1066,7 @@ function bx_trigger_error ($sMsg, $iNumLevelsBack = 0)
 }
 
 /**
- * Get dolphin version
+ * Get Dolphin system DB version, for files version @see BX_DOL_VERSION, these versions must match
  */
 function bx_get_ver ()
 {

+ 1 - 1
inc/version.inc.php

@@ -7,6 +7,6 @@
  * @{
  */
 
-define('BX_DOL_VERSION', '8.0.0-DEV2');
+define('BX_DOL_VERSION', '8.0.0-DEV2'); ///< Dolphin system files version, for DB version @see bx_get_ver, DB and files version must match
 
 /** @} */

+ 4 - 1
install/sql/system.sql

@@ -340,8 +340,11 @@ SET @iCategoryId = LAST_INSERT_ID();
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'site_title', '_adm_stg_cpt_option_site_title', 'Community', 'digit', '', '', '', 1),
 (@iCategoryId, 'site_email', '_adm_stg_cpt_option_site_email', 'admin@example.com', 'digit', '', '', '', 2),
-(@iCategoryId, 'site_email_notify', '_adm_stg_cpt_option_site_email_notify', 'admin@example.com', 'digit', '', '', '', 3);
+(@iCategoryId, 'site_email_notify', '_adm_stg_cpt_option_site_email_notify', 'admin@example.com', 'digit', '', '', '', 3),
 
+(@iCategoryId, 'sys_autoupdate_system', '_adm_stg_cpt_option_sys_autoupdate_system', 'on', 'checkbox', '', '', '', 10),
+(@iCategoryId, 'sys_autoupdate_modules', '_adm_stg_cpt_option_sys_autoupdate_modules', 'on', 'checkbox', '', '', '', 11),
+(@iCategoryId, 'sys_autoupdate_force_modified_files', '_adm_stg_cpt_option_sys_autoupdate_force_modified_files', '', 'checkbox', '', '', '', 12);
 
 --
 -- CATEGORY: Storage

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

@@ -1114,6 +1114,9 @@
 	<string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Automatic account activation after creation]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_default_acl_level"><![CDATA[Default member's level to assign after account creation]]></string>
 	<string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Add "nofollow" attribute for external links]]></string>
+	<string name="_adm_stg_cpt_option_sys_autoupdate_force_modified_files"><![CDATA[Force site and module auto-update, even if some files were modified]]></string>
+	<string name="_adm_stg_cpt_option_sys_autoupdate_modules"><![CDATA[Extensions auto-update]]></string>
+	<string name="_adm_stg_cpt_option_sys_autoupdate_system"><![CDATA[System files auto-update]]></string>
 	<string name="_adm_stg_cpt_option_sys_cache_memcache_host"><![CDATA[Memcached server host]]></string>
 	<string name="_adm_stg_cpt_option_sys_cache_memcache_port"><![CDATA[Memcached server port]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Enable DB cache]]></string>
@@ -1972,15 +1975,14 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_txt_unsubscribe_error_occured"><![CDATA[Error occured, please login to your account and update email references there or contact site administrator to unsubscribe you manually.]]></string>
 	<string name="_sys_txt_unsubscribe_info"><![CDATA[Update email preferences for <b>{0}</b>]]></string>
 	<string name="_sys_txt_unsubscribe_wrong_link"><![CDATA[Unsubscribe link is wrong.]]></string>
-
+	<string name="_sys_upgrade_db_and_files_versions_different"><![CDATA[Database and files versions are different, probably porevious patch wasn't applied correctly.]]></string>
+	<string name="_sys_upgrade_files_checksum_failed"><![CDATA[Can't apply apgrade becase the following files were modified: {0}]]></string>
+	<string name="_sys_upgrade_files_checksum_failed_too_many"><![CDATA[Can't apply upgrade becase too many files({0}%) were modified]]></string>
 	<string name="_sys_upgrade_get_version_info_failed"><![CDATA[Get version info failed, please check internet connection on the web-server or web-server firewall]]></string>
-	<string name="_sys_upgrade_patch_download_failed"><![CDATA[Patch download failed, or downloaded file can't be saved]]></string>
-	<string name="_sys_upgrade_patch_unpack_failed"><![CDATA[Patch unpack failed]]></string>
 	<string name="_sys_upgrade_patch_checksum_failed"><![CDATA[Downloaded patch file checksum is invalid]]></string>
-	<string name="_sys_upgrade_files_checksum_failed"><![CDATA[Can't apply script becase the following files were modified: {0}]]></string>
+	<string name="_sys_upgrade_patch_download_failed"><![CDATA[Patch download failed, or downloaded file can't be saved]]></string>
 	<string name="_sys_upgrade_patch_invalid"><![CDATA[Invalid patch, it can't be applied to your version or incorrect files structure in the patch.]]></string>
-
-
+	<string name="_sys_upgrade_patch_unpack_failed"><![CDATA[Patch unpack failed]]></string>
 	<string name="_sys_uploader_close"><![CDATA[Close]]></string>
 	<string name="_sys_uploader_confirm_close_popup"><![CDATA[Oh no! Are you sure? This may discard uploading files, seriously.]]></string>
 	<string name="_sys_uploader_confirm_leaving_page"><![CDATA[Upload is in progress! Stay cool and don't close this page, or it will cut off half-way.]]></string>

+ 3 - 0
periodic/cron.php

@@ -133,6 +133,9 @@ if (!empty($aJobsTransient)) {
         exit;
 }
 
+if (bx_check_maintenance_mode()) // don't run regular cron jobs when site is in maintenance mode
+    exit;
+
 // run regular cron jobs
 
 bx_import('BxDolLanguages');