Explorar el Código

Ticket #870 - point 3.

AntonLV hace 9 años
padre
commit
b17375ce39

+ 43 - 1
inc/classes/BxDolCmts.php

@@ -566,11 +566,39 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return true;
     }
 
+    public static function onModuleEnable ($sModuleName)
+    {
+        $aSystems = self::getSystems();
+        foreach($aSystems as $sSystem => $aSystem) {
+            if ($sModuleName !== $aSystem['module'])
+                continue;
+
+            $o = self::getObjectInstance($sSystem, 0);
+            $o->registerTranscoders();
+        }
+
+        return true;
+    }
+
+    public static function onModuleDisable ($sModuleName)
+    {
+        $aSystems = self::getSystems();
+        foreach($aSystems as $sSystem => $aSystem) {
+            if ($sModuleName !== $aSystem['module'])
+                continue;
+
+            $o = self::getObjectInstance($sSystem, 0);
+            $o->unregisterTranscoders();
+        }
+
+        return true;
+    }
+
     public static function onModuleUninstall ($sModuleName, &$iFiles = null)
     {
         $aSystems = self::getSystems();
         foreach($aSystems as $sSystem => $aSystem) {
-            if (0 !== strncasecmp($sModuleName, $sSystem, strlen($sModuleName)))
+            if ($sModuleName !== $aSystem['module'])
                 continue;
 
             $o = self::getObjectInstance($sSystem, 0);
@@ -1010,6 +1038,20 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return $aResult;
     }
 
+    /**
+     * Overwrite this method and register transcoder(s) if comments object uses custom transcoder(s), 
+     * which differs from default one 'sys_cmts_images_preview'
+     */
+    public function registerTranscoders()
+    {}
+
+	/**
+     * Overwrite this method and unregister transcoder(s) if comments object uses custom transcoder(s), 
+     * which differs from default one 'sys_cmts_images_preview'
+     */
+    public function unregisterTranscoders()
+    {}
+
     public function serviceGetSearchResultExtended($aParams)
     {
         if(empty($aParams) || !is_array($aParams))

+ 23 - 0
modules/boonex/forum/classes/BxForumCmts.php

@@ -24,6 +24,29 @@ class BxForumCmts extends BxTemplCmts
         $this->setTableNameFiles('bx_forum_files');
     }
 
+    public function registerTranscoders()
+    {
+        parent::registerTranscoders();
+
+        $aTranscoders = array(
+            $this->getTranscoderPreviewName()
+        );
+
+        BxDolTranscoderImage::registerHandlersArray($aTranscoders);
+    }
+
+    public function unregisterTranscoders()
+    {
+        parent::unregisterTranscoders();
+
+        $aTranscoders = array(
+            $this->getTranscoderPreviewName()
+        );
+
+        BxDolTranscoderImage::unregisterHandlersArray($aTranscoders);
+        BxDolTranscoderImage::cleanupObjectsArray($aTranscoders);
+    }
+
 	public function isPostReplyAllowed($isPerformAction = false)
     {
     	$aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iId);

+ 111 - 51
studio/classes/BxDolStudioInstaller.php

@@ -200,6 +200,13 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
             $oFile->copy($sSrcPath, $sDstPath);
         }
 
+        $aResultBefore = $this->_onInstallBefore();
+        if($aResultBefore !== BX_DOL_STUDIO_INSTALLER_SUCCESS)
+            return array(
+                'message' => $aResultBefore['content'],
+                'result' => false
+            );
+
         //--- Check actions ---//
         $aResult = $this->_perform('install', $aParams);
         if($aResult['result']) {
@@ -225,6 +232,8 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
             $this->cleanupMemoryAfterAction($this->_aConfig['home_uri'], $iModuleId);
 
+            $this->_onInstallAfter();
+
             if(!empty($this->_aConfig['install_success']))
             	$this->_perform('install_success', $aParams);
         }
@@ -285,6 +294,14 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
                 'result' => false
             );
 
+        //--- Process storages and comments ---//
+        $aResultBefore = $this->_onUninstallBefore();
+        if($aResultBefore !== BX_DOL_STUDIO_INSTALLER_SUCCESS)
+            return array(
+                'message' => $aResultBefore['content'],
+                'result' => false
+            );
+
         $aResult = $this->_perform('uninstall', $aParams);
         if($aResult['result']) {
             $iModuleId = $this->oDb->deleteModule($this->_aConfig);
@@ -297,6 +314,8 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
             $this->cleanupMemoryAfterAction($this->_aConfig['home_uri'], $iModuleId);
 
+            $this->_onUninstallAfter();
+
             if(!empty($this->_aConfig['uninstall_success']))
             	$this->_perform('uninstall_success', $aParams);
         }
@@ -389,12 +408,21 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
         if ($aResult && !$aResult['result'])
             return $aResult;
 
+        $aResultBefore = $this->_onEnableBefore();
+        if($aResultBefore !== BX_DOL_STUDIO_INSTALLER_SUCCESS)
+            return array(
+                'message' => $aResultBefore['content'],
+                'result' => false
+            );
+
         $aResult = $this->_perform('enable', $aParams);
         if($aResult['result']) {
             $this->oDb->enableModuleByUri($aModule['uri']);
 
             $this->cleanupMemoryAfterAction($aModule['uri'], $aModule['id']);
 
+		    $this->_onEnableAfter();
+
             if(!empty($this->_aConfig['enable_success']))
             	$this->_perform('enable_success', $aParams);
         }
@@ -456,12 +484,21 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
                 'result' => false
             );
 
+        $aResultBefore = $this->_onDisableBefore();
+        if($aResultBefore !== BX_DOL_STUDIO_INSTALLER_SUCCESS)
+            return array(
+                'message' => $aResultBefore['content'],
+                'result' => false
+            );
+
         $aResult = $this->_perform('disable', $aParams);
         if($aResult['result']) {
             $this->oDb->disableModuleByUri($aModule['uri']);
 
             $this->cleanupMemoryAfterAction($aModule['uri'], $aModule['id']);
 
+            $this->_onDisableAfter();
+
             if(!empty($this->_aConfig['disable_success']))
             	$this->_perform('disable_success', $aParams);
         }
@@ -765,57 +802,6 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
         return BX_DOL_STUDIO_INSTALLER_SUCCESS;
     }
 
-    /**
-     * 
-     * Storage objects to automatically delete files from upon module uninstallation.
-     * Note. Don't add storage objects used in transcoder objects.
-     * @param string $sOperation - operation type.
-     */
-    protected function actionProcessStorages($sOperation)
-    {
-    	if(empty($this->_aConfig['storages'])) 
-        	return BX_DOL_STUDIO_INSTALLER_FAILED;
-
-		// check if module is already waiting while files are deleting
-        if(self::isModulePendingUninstall($this->_aConfig['home_uri']))
-			return array(
-				'code' => BX_DOL_STUDIO_INSTALLER_FAILED,
-				'content' => _t('_adm_err_modules_pending_uninstall_already'),
-            );
-
-		$bSetModulePendingUninstall = false;
-
-        // queue for deletion storage files        
-        foreach($this->_aConfig['storages'] as $s)
-			if(($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject())
-                $bSetModulePendingUninstall = true;
-
-        // delete comments and queue for deletion comments attachments
-        $iFiles = 0;
-        BxDolCmts::onModuleUninstall($this->_aConfig['name'], $iFiles);
-        if($iFiles)
-			$bSetModulePendingUninstall = true;
-
-        // if some files were added to the queue, set module as pending uninstall
-        if ($bSetModulePendingUninstall) {
-            self::setModulePendingUninstall($this->_aConfig['home_uri']);
-            return array(
-            	'code' => BX_DOL_STUDIO_INSTALLER_FAILED,
-                'content' => _t('_adm_err_modules_pending_uninstall'),
-            );
-        }
-
-		return BX_DOL_STUDIO_INSTALLER_SUCCESS;
-    }
-
-	protected function actionProcessStoragesFailed($mixedResult)
-    {
-    	if(is_int($mixedResult))
-    		return $this->actionOperationFailed($mixedResult);
-
-        return $mixedResult['content'];
-    }
-
 	/**
      * 
      * Process the list of extended search forms provided in config array. 
@@ -886,6 +872,80 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
         return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
     }
 
+    protected function _onInstallBefore()
+    {
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onInstallAfter()
+    {
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onEnableBefore()
+    {
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onEnableAfter()
+    {
+        BxDolCmts::onModuleEnable($this->_aConfig['name']);
+
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onDisableBefore()
+    {
+        BxDolCmts::onModuleDisable($this->_aConfig['name']);
+
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onDisableAfter()
+    {
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onUninstallBefore()
+    {
+		// check if module is already waiting while files are deleting
+        if(self::isModulePendingUninstall($this->_aConfig['home_uri']))
+			return array(
+				'code' => BX_DOL_STUDIO_INSTALLER_FAILED,
+				'content' => _t('_adm_err_modules_pending_uninstall_already'),
+            );
+
+		$bSetModulePendingUninstall = false;
+
+		// delete comments and queue for deletion comments attachments
+        $iFiles = 0;
+        BxDolCmts::onModuleUninstall($this->_aConfig['name'], $iFiles);
+        if($iFiles)
+			$bSetModulePendingUninstall = true;
+
+        // queue for deletion storage files
+        if(!empty($this->_aConfig['storages']) && is_array($this->_aConfig['storages']))        
+            foreach($this->_aConfig['storages'] as $s)
+    			if(($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject())
+                    $bSetModulePendingUninstall = true;       
+
+        // if some files were added to the queue, set module as pending uninstall
+        if ($bSetModulePendingUninstall) {
+            self::setModulePendingUninstall($this->_aConfig['home_uri']);
+            return array(
+            	'code' => BX_DOL_STUDIO_INSTALLER_FAILED,
+                'content' => _t('_adm_err_modules_pending_uninstall'),
+            );
+        }
+
+		return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
+    protected function _onUninstallAfter()
+    {
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
 	protected function _perform($sOperationName, $aParams = array())
     {
     	$bHtmlResponce = isset($aParams['html_response']) && (bool)$aParams['html_response'];