[xoops-cvslog 5543] CVS update: xoops2jp/html/modules/legacy/admin/class

Back to archive index

Minahito minah****@users*****
2006年 11月 1日 (水) 20:54:56 JST


Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php
diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.1
--- /dev/null	Wed Nov  1 20:54:56 2006
+++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php	Wed Nov  1 20:54:56 2006
@@ -0,0 +1,183 @@
+<?php
+
+if (!defined('XOOPS_ROOT_PATH')) exit();
+
+/**
+ * This class is collection of static utility functions for module installation.
+ * These functions are useful for Legacy modules' system-fixed-installer and
+ * modules' custom-installer. All functions for the custom-installer are added
+ * notes as "FOR THE CUSTOM-ISNTALLER".
+ * 
+ * For more attentions, see base classes for the custom-installer.
+ * 
+ * @see Legacy_PhasedUpgrader
+ */
+class Legacy_ModuleInstallUtils
+{
+	/**
+	 * Installs all of module templates $module specify. This function is
+	 * usefull for installer and updater. In the case of updater, you should
+	 * uninstall all of module templates before this function.
+	 * 
+	 * This function gets informations about templates from xoops_version.
+	 * 
+	 * @section Attention
+	 * 
+	 * This function depends the specific spec of Legacy_RenderSystem, but this
+	 * static function is needed by the 2nd installer of Legacy System.
+	 * 
+	 * @static
+	 * @param XoopsModule $module
+	 * @param Legacy_ModuleUtilsSimpleLog $log
+	 * @note FOR THE CUSTOM-INSTALLER
+	 * @see Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates()
+	 */	
+	function installAllOfModuleTemplates(&$module, &$log)
+	{
+        $templates = $module->getInfo('templates');
+        if ($templates != false) {
+            foreach ($templates as $template) {
+                Legacy_ModuleUtils::installModuleTemplate($module, $template, $log);
+            }
+        }
+	}
+
+	/**
+	 * Uninstalls all of module templates $module specify. This function is
+	 * usefull for uninstaller and updater. In the case of update, you should
+	 * call this function before installAllOfModuleTemplates(). In the case of
+	 * uninstall, you must set 'false' to $defaultOnly.
+	 * 
+	 * This function gets informations about templates from the database.
+	 * 
+	 * @section Attention
+	 * 
+	 * This function depends the specific spec of Legacy_RenderSystem, but this
+	 * static function is needed by the 2nd installer of Legacy System.
+	 * 
+	 * @static
+	 * @param XoopsModule $module
+	 * @param Legacy_ModuleUtilsSimpleLog $log
+	 * @param bool $defaultOnly Indicates whether this function deletes templates from all of tplsets.
+	 * @note FOR THE CUSTOM-INSTALLER
+	 * @see Legacy_ModuleInstallUtils::installAllOfModuleTemplates()
+	 */	
+	function uninstallAllOfModuleTemplates(&$module, &$log, $defaultOnly = true)
+	{
+		$tplHandler =& xoops_gethandler('tplfile');
+
+		//
+		// The following processing depends on the structure of Legacy_RenderSystem.
+		//
+		$tplHandler =& xoops_gethandler('tplfile');
+		$delTemplates = null;
+		
+		if ($defaultOnly) {
+			$delTemplates =& $tplHandler->find('default', 'module', $module->get('mid'));
+		}
+		else {
+			$delTemplates =& $tplHandler->find(null, 'module', $module->get('mid'));
+		}
+		
+		if (is_array($delTemplates) && count($delTemplates) > 0) {
+			//
+			// clear cache
+			//
+			$xoopsTpl =& new XoopsTpl();
+			$xoopsTpl->clear_cache(null, "mod_" . $module->get('dirname'));
+			
+			foreach ($delTemplates as $tpl) {
+				if (!$tplHandler->delete($tpl)) {
+					$log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_TEMPLATE_UNINSTALLED, $tpl->get('tpl_file')));
+				}
+			}
+		}
+	}
+	
+	/**
+	 * Installs all of blocks $module specify.
+	 * 
+	 * This function gets informations about blocks from xoops_version.
+	 * 
+	 * @static
+	 * @param XoopsModule $module
+	 * @param Legacy_ModuleUtilsSimpleLog $log
+	 * @note FOR THE CUSTOM-INSTALLER
+	 * @see Legacy_ModuleInstallUtils::uninstallAllOfBlocks()
+	 */	
+	function installAllOfBlocks(&$module, &$log)
+	{
+		$definedBlocks = $module->getInfo('blocks');
+		if($definedBlocks == false) {
+			return true;
+		}
+		
+		$handler =& xoops_gethandler('block');
+
+		$func_num = 0;
+		foreach ($definedBlocks as $block) {
+			$func_num++;
+			$newBlock =& Legacy_ModuleUtils::createBlockByInfo($module, $block, $func_num);
+			Legacy_ModuleUtils::installBlock($module, $newBlock, $block, $this->mLog);
+        }
+	}
+
+	/**
+	 * Uninstalls all of blocks which $module specifies, and its permissions.
+	 * 
+	 * This function gets informations about templates from the database.
+	 * 
+	 * @static
+	 * @param XoopsModule $module
+	 * @param Legacy_ModuleUtilsSimpleLog $log
+	 * @return bool
+	 * 
+	 * @note FOR THE CUSTOM-INSTALLER
+	 * @see Legacy_ModuleInstallUtils::installAllOfBlocks()
+	 * @see Legacy_ModuleInstallUtils::uninstallBlock()
+	 */	
+	function uninstallAllOfBlocks(&$module, &$log)
+	{
+		$handler =& xoops_gethandler('block');
+		$criteria = new Criteria('mid', $module->get('mid'));
+
+		$blockArr =& $handler->getObjectsDirectly($criteria);
+		
+		$successFlag = true;
+		
+		foreach (array_keys($blockArr) as $idx) {
+			$successFlag &= Legacy_ModuleInstallUtils::uninstallBlock($blockArr[$idx], $log);
+		}
+		
+		return $successFlag;
+	}
+	
+	/**
+	 * Uninstalls a block which $block specifies. In the same time, deletes
+	 * permissions for the block.
+	 * 
+	 * @param XoopsBlock $block
+	 * @param Legacy_ModuleUtilsSimpleLog $log
+	 * @note FOR THE CUSTOM-INSTALLER
+	 * 
+	 * @todo error handling & delete the block's template.
+	 */
+	function uninstallBlock(&$block, &$log)
+	{
+		$blockHandler =& xoops_gethandler('block');
+		$blockHandler->delete($block);
+		$log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $block->get('name')));
+		
+		//
+		// Deletes permissions
+		//
+		$gpermHandler =& xoops_gethandler('groupperm');
+		$criteria =& new CriteriaCompo();
+		$criteria->add(new Criteria('gperm_name', 'block_read'));
+		$criteria->add(new Criteria('gperm_itemid', $block->get('bid')));
+		$criteria->add(new Criteria('gperm_modid', 1));
+		$gpermHandler->deleteAll($criteria);
+    }
+}
+
+?>
\ No newline at end of file


xoops-cvslog メーリングリストの案内
Back to archive index