[xoops-cvslog 1292] CVS update: xoops2jp/html/modules/base/admin/class

Back to archive index

Minahito minah****@users*****
2005年 12月 16日 (金) 18:56:11 JST


Index: xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php
diff -u /dev/null xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php:1.1.2.1
--- /dev/null	Fri Dec 16 18:56:11 2005
+++ xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php	Fri Dec 16 18:56:11 2005
@@ -0,0 +1,64 @@
+<?php
+
+require_once XOOPS_BASE_PATH."/admin/class/AbstractModuleInstaller.class.php";
+
+class Legacy_ModuleInstaller extends Legacy_AbstractModuleInstaller
+{
+	/**
+	 * Load xoops module object that isn't installed and return it.
+	 * @static
+	 * @access public
+	 * @param $dirname string
+	 * @return XoopsModule
+	 */
+	function &loadModuleObject($dirname)
+	{
+		$ret = null;
+
+		$moduleHandler =& xoops_gethandler('module');
+		$module =& $moduleHandler->getByDirname($dirname);
+
+		if (is_object($module))
+			return $ret;
+
+		$module =& $moduleHandler->create();
+		$module->loadInfoAsVar($this->mDirname);
+		
+		return $module;
+	}
+
+	function _installTable()
+	{
+		Legacy_ModuleUtils::installTable($this->mModule, $this->mLog);
+	}
+
+	function _installTemplate()
+	{
+		$templates = $this->mModule->getInfo('templates');
+		if ($templates != false) {
+			foreach ($templates as $template) {
+				Legacy_ModuleUtils::installTemplate($this->mModule, $template, $this->mLog);
+			}
+		}
+	}
+
+	function _installBlock()
+	{
+		$definedBlocks = $this->mModule->getInfo('blocks');
+		if($definedBlocks == false)
+			return true;
+
+		$blockHandler =& xoops_gethandler('block');
+
+		$func_num=0;
+		foreach ($definedBlocks as $block) {
+			$func_num++;
+			$newBlock =& Legacy_ModuleUtils::createBlockByInfo($this->mModule, $block);
+			$newBlock->setVar('func_num', $func_num);
+
+			Legacy_ModuleUtils::installBlock($this->mModule, $newBlock, $this->mLog);
+		}
+	}
+}
+
+?>
\ No newline at end of file
Index: xoops2jp/html/modules/base/admin/class/ModuleUninstaller.class.php
diff -u /dev/null xoops2jp/html/modules/base/admin/class/ModuleUninstaller.class.php:1.1.2.1
--- /dev/null	Fri Dec 16 18:56:11 2005
+++ xoops2jp/html/modules/base/admin/class/ModuleUninstaller.class.php	Fri Dec 16 18:56:11 2005
@@ -0,0 +1,110 @@
+<?php
+
+require_once XOOPS_BASE_PATH."/admin/class/AbstractModuleInstaller.class.php";
+
+class Legacy_ModuleUninstaller extends Legacy_AbstractModuleInstaller
+{
+	/**
+	 * Load xoops module object that isn't installed and return it.
+	 * @static
+	 * @access public
+	 * @param $dirname string
+	 * @return XoopsModule
+	 */
+	function &loadModuleObject($dirname)
+	{
+		$ret = null;
+
+		$moduleHandler =& xoops_gethandler('module');
+		$module =& $moduleHandler->getByDirname($dirname);
+
+		if (!is_object($module))
+			return $ret;
+
+		return $module;
+	}
+	
+	/**
+	 * Delete module information from XOOPS database because this class is uninstaller.
+	 */
+	function _installModule()
+	{
+		$moduleHandler =& xoops_gethandler('module');
+		if (!$moduleHandler->delete($this->mModule)) {
+			$this->mLog->addError("*Could not delete module information from XOOPS database.*");
+		}
+		else {
+			$this->mLog->addReport("*Delete module information from XOOPS database.*");
+		}
+	}
+
+	/**
+	 * Drop table because this class is uninstaller.
+	 */
+	function _installTable()
+	{
+		$root =& XCube_Root::getSingleton();
+		$db =& $root->mController->getDB();
+
+		$tables = $this->mModule->getInfo('tables');
+		if ($tables != false && is_array($tables)) {
+			foreach($tables as $table) {
+
+				// TODO Do we need to check reserved core tables?
+
+				$sql = "DROP TABLE " . $db->prefix($table);
+				if (!$db->query($sql)) {
+					$this->mLog->addError("Could not drop table " . $db->prefix($table));
+				}
+			}
+		}
+	}
+
+	/**
+	 * Delete template because this class is uninstaller.
+	 */
+	function _installTemplate()
+	{
+		$tplHandler =& xoops_gethandler('tplfile');
+
+		$deleteTemplates =& $tplHandler->find(null, 'module', $this->mModule->getVar('mid'));
+
+		foreach($deleteTemplates as $template) {
+			$tplHandler->delete($template);
+		}
+	}
+
+	/**
+	 * Delete all of module's blocks.
+	 */
+	function _installBlock()
+	{
+		$blockHandler =& xoops_gethandler('block');
+		$criteria = new Criteria('mid', $this->mModule->getVar('mid'));
+
+		$blocks =& $blockHandler->getObjects($criteria);
+
+		$gpermHandler =& xoops_gethandler('groupperm');
+		foreach ($blocks as $block) {
+			$blockHandler->delete($block);
+			$this->mLog->addReport("Uninstall block '".$block->getName('block'));
+
+			//
+			// delete permission
+			//
+			$criteria =& new CriteriaCompo();
+			$criteria->add(new Criteria('gperm_name', 'block_read'));
+			$criteria->add(new Criteria('gperm_itemid', $block->getVar('bid')));
+			$criteria->add(new Criteria('gperm_modid', 1));
+			$gpermHandler->deleteAll($criteria);
+		}
+
+		$tplHandler =& xoops_gethandler('tplfile');
+		$criteria =& new Criteria('tpl_module', $this->mModule->getVar('dirname'));
+		if(!$tplHandler->deleteAll($criteria)) {
+			$this->mLog->addError("Could not delete block templates : " . $tplHandler->db->error());
+		}
+	}
+}
+
+?>
\ No newline at end of file
Index: xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php
diff -u /dev/null xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.1
--- /dev/null	Fri Dec 16 18:56:11 2005
+++ xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php	Fri Dec 16 18:56:11 2005
@@ -0,0 +1,170 @@
+<?php
+
+require_once XOOPS_BASE_PATH."/admin/class/AbstractModuleInstaller.class.php";
+
+class Legacy_ModuleUpdater extends Legacy_AbstractModuleInstaller
+{
+	/**
+	 * @return bool
+	 */
+	function execute()
+	{
+		$this->mLog->addReport("Update started");
+		
+		parent::execute();
+	}
+	
+	/**
+	 * Load xoops module object installed and return it.
+	 * @static
+	 * @access public
+	 * @param $dirname string
+	 * @return XoopsModule
+	 */
+	function &loadModuleObject($dirname)
+	{
+		$ret = null;
+
+		$moduleHandler =& xoops_gethandler('module');
+		$module =& $moduleHandler->getByDirname($dirname);
+
+		if (!is_object($module))
+			return $ret;
+
+		$module->loadInfoAsVar($dirname);
+		
+		return $module;
+	}
+
+	/**
+	 * Remove all of installed templates and re-install all of defined templates.
+	 */
+	function _installTemplate()
+	{
+		$tplHandler =& xoops_gethandler('tplfile');
+
+		//
+		// The following processing depends on the structure of Legacy_RenderSystem.
+		//
+		$tplHandler =& xoops_gethandler('tplfile');
+		$delTemplates =& $tplHandler->find('default', 'module', $this->mModule->getVar('mid'));
+		if(is_array($delTemplates) && count($delTemplates) > 0) {
+			//
+			// clear cache
+			//
+			$xoopsTpl=new XoopsTpl();
+			$xoopsTpl->clear_cache(null, "mod_" . $this->mModule->getVar('dirname'));
+			
+			foreach ($delTemplates as $tpl) {
+				if (!$tplHandler->delete($tpl)) {
+					$this->mLog->addError(@sprintf(_MD_A_BASE_ERROR_DELETE_TEMPLATE, $tpl->getVar('tpl_file')));
+				}
+			}
+		}
+
+		//
+		// install Template All
+		//
+		$templates = $this->mModule->getInfo('templates');
+		if ($templates != false) {
+			foreach ($templates as $template) {
+				Legacy_ModuleUtils::installTemplate($this->mModule, $template, $this->mLog);
+			}
+		}
+	}
+
+	/**
+	 * @return bool
+	 */
+	function _installBlock()
+	{
+		// XoopsBlock[]
+		$installBlocks = array();
+
+		// XoopsBlock[]
+		$unInstallBlocks = array();
+
+		$definedBlocks = $this->mModule->getInfo('blocks');
+		if($definedBlocks == false)
+			return false;
+
+		$blockHandler =& xoops_gethandler('block');
+
+		$func_num=0;
+		foreach ($definedBlocks as $block) {
+			$func_num++;
+			$newBlock =& Legacy_ModuleUtils::createBlockByInfo($this->mModule, $block);
+
+			//
+			// Get a installed block by mid and name.
+			//
+			$criteria = new CriteriaCompo();
+			$criteria->add(new Criteria('mid', $this->mModule->getVar('mid')));
+			$criteria->add(new Criteria('name', $block['name']));
+			$installedBlocks =& $blockHandler->getObjectsDirectly($criteria);
+
+			//
+			// If a installed block is not found, push it to new install block list.
+			//
+			if (count($installedBlocks) == 0) {
+				$newBlock->setVar('func_num', $func_num);
+				$installedBlocks[] =& $newBlock;
+				unset($newBlock);
+
+				continue;
+			}
+
+			$oldBlock =& $installedBlocks[0];
+
+			//
+			// Check update
+			//
+			$changedFlag = false;
+			$changedFlag |= ($newBlock->getVar('name') != $oldBlock->getVar('name'));
+			$changedFlag |= ($newBlock->getVar('func_file') != $oldBlock->getVar('func_file'));
+			$changedFlag |= ($newBlock->getVar('show_func') != $oldBlock->getVar('show_func'));
+			$changedFlag |= ($newBlock->getVar('edit_func') != $oldBlock->getVar('edit_func'));
+			$changedFlag |= ($newBlock->getVar('template') != $oldBlock->getVar('template'));
+
+			if ($changedFlag) {
+				$installedBlocks[] =& $newBlock;
+			}
+			else {
+				if (!Legacy_ModuleUtils::installBlockTemplate($this->mModule, $block)) {
+					$this->mLog->addError("ERROR : Could not update block template ".$block->getVar('name'));
+				}
+			}
+
+			unset($newBlock);
+			unset($oldBlock);
+		}
+
+		$criteria = new CriteriaCompo();
+		$criteria->add(new Criteria('mid', $this->mModule->getVar('mid')));
+		$installedBlocks =& $blockHandler->getObjectsDirectly($criteria);
+		foreach ($installedBlocks as $block) {
+			$name = $block->getVar('name');
+			$findFlag = false;
+			foreach ($definedBlocks as $definedBlock) {
+				$findFlag |= ($definedBlock['name'] == $block->getVar('name'));
+			}
+
+			if (!$findFlag) {
+				$unInstallBlocks[] =& $block;
+				unset($block);
+			}
+		}
+
+		foreach ($installBlocks as $block) {
+			Legacy_ModuleUtils::installBlock($this->mModule, $block, $this->mLog);
+		}
+
+		/*
+		foreach ($unInstallBlocks as $block) {
+			Legacy_ModuleUtils::unInstallBlock($block);
+		}
+		*/
+	}
+}
+
+?>
\ No newline at end of file


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