فهرست منبع

#109 and #114 Record modules installations in DB

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@826 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 سال پیش
والد
کامیت
50be8a51b7
2فایلهای تغییر یافته به همراه127 افزوده شده و 3 حذف شده
  1. 60 3
      setup/index.php
  2. 67 0
      setup/moduleinstallation.class.inc.php

+ 60 - 3
setup/index.php

@@ -391,6 +391,7 @@ function InitDataModel(SetupWebPage $oP, $sConfigFileName, $bModelOnly = true)
 	require_once('../core/dbobjectset.class.php');
 	require_once('../application/cmdbabstract.class.inc.php');
 	require_once('../core/userrights.class.inc.php');
+	require_once('../setup/moduleinstallation.class.inc.php');
 	$oP->log("Info - MetaModel::Startup from file '$sConfigFileName' (ModelOnly = $bModelOnly)");
 
 	MetaModel::Startup($sConfigFileName, $bModelOnly);
@@ -399,9 +400,8 @@ function InitDataModel(SetupWebPage $oP, $sConfigFileName, $bModelOnly = true)
  * Helper function to create the database structure
  * @return boolean true on success, false otherwise
  */
-function CreateDatabaseStructure(SetupWebPage $oP, Config $oConfig, $sDBName, $sDBPrefix)
+function CreateDatabaseStructure(SetupWebPage $oP, Config $oConfig, $sDBName, $sDBPrefix, $aSelectedModules)
 {
-
 	InitDataModel($oP, TMP_CONFIG_FILE, true); // Allow the DB to NOT exist since we're about to create it !
 	$oP->log('Info - CreateDatabaseStructure');
 	if (strlen($sDBPrefix) > 0)
@@ -431,6 +431,63 @@ function CreateDatabaseStructure(SetupWebPage $oP, Config $oConfig, $sDBName, $s
 		}
 		return false;
 	}
+
+	// Record main installation
+	$oInstallRec = new ModuleInstallation();
+	$oInstallRec->Set('name', 'itop');
+	$oInstallRec->Set('version', ITOP_VERSION.'.'.ITOP_REVISION);
+	$oInstallRec->Set('comment', "Done by the setup program\nBuilt on ".ITOP_BUILD_DATE);
+	$oInstallRec->Set('parent_id', 0); // root module
+	$iMainItopRecord = $oInstallRec->DBInsertNoReload();
+
+	// Record installed modules
+	//
+	$aAvailableModules = GetAvailableModules($oP);
+	foreach($aSelectedModules as $sModuleId)
+	{
+		$aModuleData = $aAvailableModules[$sModuleId];
+		if (preg_match('!^(.*)/(.*)$!', $sModuleId, $aMatches))
+		{
+			$sName = $aMatches[1];
+			$sVersion = $aMatches[2];
+		}
+		else
+		{
+			$sName = $sModuleId;
+			$sVersion = "";
+		}
+		$aComments = array();
+		$aComments[] = 'Done by the setup program';
+		if ($aModuleData['mandatory'])
+		{
+			$aComments[] = 'Mandatory';
+		}
+		else
+		{
+			$aComments[] = 'Optional';
+		}
+		if ($aModuleData['visible'])
+		{
+			$aComments[] = 'Visible (during the setup)';
+		}
+		else
+		{
+			$aComments[] = 'Hidden (selected automatically)';
+		}
+		foreach ($aModuleData['dependencies'] as $sDependOn)
+		{
+			$aComments[] = "Depends on module: $sDependOn";
+		}
+		$sComment = implode("\n", $aComments);
+
+		$oInstallRec = new ModuleInstallation();
+		$oInstallRec->Set('name', $sName);
+		$oInstallRec->Set('version', $sVersion);
+		$oInstallRec->Set('comment', $sComment);
+		$oInstallRec->Set('parent_id', $iMainItopRecord);
+		$oInstallRec->DBInsertNoReload();
+	}
+	// Database is created, installation has been tracked into it
 	return true;
 }
 
@@ -884,7 +941,7 @@ function AdminAccountDefinition(SetupWebPage $oP, $aParamValues, $iCurrentStep,
 	$oConfig->SetDBSubname($sDBPrefix);
 	BuildConfig($oP, $oConfig, $aParamValues); // Load all the includes based on the modules selected
 	$oConfig->WriteToFile(TMP_CONFIG_FILE);
-	if (CreateDatabaseStructure($oP, $oConfig, $sDBName, $sDBPrefix))
+	if (CreateDatabaseStructure($oP, $oConfig, $sDBName, $sDBPrefix, $aParamValues['module']))
 	{
 		$sRedStar = "<span class=\"hilite\">*</span>";
 		$oP->add("<h2>Default language for the application:</h2>\n");

+ 67 - 0
setup/moduleinstallation.class.inc.php

@@ -0,0 +1,67 @@
+<?php
+// Copyright (C) 2010 Combodo SARL
+//
+//   This program is free software; you can redistribute it and/or modify
+//   it under the terms of the GNU General Public License as published by
+//   the Free Software Foundation; version 3 of the License.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//   GNU General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; if not, write to the Free Software
+//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+/**
+ * Persistent class Event and derived
+ * Log of module installations
+ *
+ * @author      Erwan Taloc <erwan.taloc@combodo.com>
+ * @author      Romain Quetiez <romain.quetiez@combodo.com>
+ * @author      Denis Flaven <denis.flaven@combodo.com>
+ * @license     http://www.opensource.org/licenses/gpl-3.0.html LGPL
+ */
+
+class ModuleInstallation extends cmdbAbstractObject
+{
+	public static function Init()
+	{
+		$aParams = array
+		(
+			"category" => "core,view_in_gui",
+			"key_type" => "autoincrement",
+			"name_attcode" => "",
+			"state_attcode" => "",
+			"reconc_keys" => array(),
+			"db_table" => "priv_module_install",
+			"db_key_field" => "id",
+			"db_finalclass_field" => "",
+			"display_template" => "",
+		);
+		MetaModel::Init_Params($aParams);
+		//MetaModel::Init_InheritAttributes();
+		MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeString("version", array("allowed_values"=>null, "sql"=>"version", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeDateTime("installed", array("allowed_values"=>null, "sql"=>"installed", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeText("comment", array("allowed_values"=>null, "sql"=>"comment", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeExternalKey("parent_id", array("targetclass"=>"ModuleInstallation", "jointype"=> "", "allowed_values"=>null, "sql"=>"parent_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
+
+
+		// Display lists
+		MetaModel::Init_SetZListItems('details', array('name', 'version', 'installed', 'comment', 'parent_id')); // Attributes to be displayed for the complete details
+		MetaModel::Init_SetZListItems('list', array('name', 'version', 'installed', 'parent_id')); // Attributes to be displayed for a list
+		// Search criteria
+//		MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
+//		MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
+	}
+
+	protected function OnInsert()
+	{
+		$this->Set('installed', time());
+		parent::OnInsert();
+	}
+}
+
+?>