\n"; echo "DEBUG: \$_SERVER\n"; print_r($_SERVER); echo "\n"; exit; } if (!UserRights::Login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { header('WWW-Authenticate: Basic realm="iTop"'); header('HTTP/1.0 401 Unauthorized'); echo 'Authentication failed !'; exit; } $oPage = new iTopWebPage("iTop Data Generator", $currentOrganization); $oPage->no_cache(); // From now on the context is limited to the the selected organization ?? // Retrieve the root node for the menu $oSearchFilter = $oContext->NewFilter("menuNode"); $oSearchFilter->AddCondition('parent_id', 0, '='); // There may be more criteria added later to have a specific menu based on the user's profile $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true)); while ($oRootMenuNode = $oSet->Fetch()) { $oRootMenuNode->DisplayMenu($oPage, $oContext, $iActiveNodeId, null, $oAppContext->GetAsHash()); } /** * The (ordered) list of classes for which to generate objects * * Each class in this list must implement a non-static Generate(cmdbDataGenerator $oGenerator) method */ //$aClassesToGenerate = array('bizOrganization' /* This one is special and must go first */, 'bizService', 'bizContact', 'bizPC', 'bizNetworkDevice'); $aClassesToGenerate = array('bizOrganization' /* This one is special and must go first */, 'bizLocation', 'bizPC', 'bizNetworkDevice', 'bizPerson', 'bizIncidentTicket', 'bizInfraGroup', 'bizInfraInfra'); ///////////////////////////////////////////////////////////////////////////////////// // Actual actions of the page ///////////////////////////////////////////////////////////////////////////////////// /** * Populate an organization with objects of each class listed in the (global) $aClassesToGenerate array * * @param WebPage $oPage The object used for the HTML output * @param cmdbGenerator $oGenerator The object used for the generation of the objects * @param string $sSize An enum specifying (roughly) how many objects of each class to create: one of 'small', 'medium', 'big', 'huge' or 'max' */ function PopulateOrganization(CMDBChange $oMyChange, WebPage $oPage, cmdbDataGenerator $oGenerator, $sSize = 'small') { global $aClassesToGenerate; for ($i=1 /* skip the first one (i=0) which is the org itself */; $iGenerate($oGenerator); // By rom // $oObject->DBInsert(); $oObject->DBInsertTracked($oMyChange); //$oObject->DisplayDetails($oPage); } } $oPage->p("$nbObjects $sClass objects created."); } } /** * Delete an organization and all the instances of 'Object' belonging to this organization * * @param WebPage $oPage The object used for the HTML output * @param string $sOrganizationCode The code (pkey) of the organization to delete */ function DeleteOrganization($oMyChange, $oPage, $sOrganizationCode) { $oOrg = MetaModel::GetObject('bizOrganization', $sOrganizationCode); if ($oOrg == null) { $oPage->p("Organization '$sOrganizationCode' already deleted!!"); } else { // Delete all the objects linked to this organization $oFilter = new CMDBSearchFilter('logRealObject'); $oFilter->AddCondition('organization', $sOrganizationCode, '='); $oSet = new CMDBObjectSet($oFilter); $countDeleted = $oSet->Count(); MetaModel::BulkDeleteTracked($oMyChange, $oFilter); // Should do a one by one delete to let the objects do their own cleanup ! $oPage->p("$countDeleted object(s) deleted!!"); $oOrg->DBDeleteTracked($oMyChange); $oPage->p("Ok, organization '$sOrganizationCode' deleted!"); } } ///////////////////////////////////////////////////////////////////////////////////////////////// // // M a i n P r o g r a m // ///////////////////////////////////////////////////////////////////////////////////////////////// $operation = utils::ReadParam('operation', ''); $oPage->add("
\n"); $oPage->add("
\n"); switch($operation) { case 'specify_generate': // Display a form to specify what to generate $oPage->p("iTop Data Generator\n"); $oPage->add("
\n"); $oPage->add("Number of organizations to generate: \n"); $oPage->add(" (max ".count($aCompanies).") \n"); $oPage->add("Size of the organizations\n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->add("
\n"); break; case 'generate': // perform the actual generation $iOrgCount = utils::ReadParam('org_count', 0); $sOrgSize = utils::ReadParam('org_size', 'small'); // By rom $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); $oMyChange->Set("userinfo", "Made by data generator ($iOrgCount orgs of size '$sOrgSize')"); $oMyChange->DBInsert(); while($iOrgCount > 0) { set_time_limit(5*60); // let it run for 5 minutes for each organization $oGenerator = new cmdbDataGenerator(); // Create the new organization $oOrg = MetaModel::NewObject('bizOrganization'); $oOrg->Generate($oGenerator); // By rom // $oOrg->DBInsert(); $oOrg->DBInsertTracked($oMyChange); $oGenerator->SetOrganizationId($oOrg->GetKey()); $oPage->p("Organization '".$oOrg->GetKey()."' created\n"); $oOrg->DisplayDetails($oPage); $oPage->add("
\n"); PopulateOrganization($oMyChange, $oPage, $oGenerator, $sOrgSize); $oPage->add("
\n"); unset($oGenerator); $iOrgCount--; } break; case 'specify_update': // Specify which organization to update $oPage->add("
\n"); $oPage->add("Select the organization to update: \n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->p(""); $oPage->add("Quantity of of objects to add in each class: \n"); $oPage->add("\n"); $oPage->p(""); $oPage->add("  \n"); $oPage->add("\n"); $oPage->add("
\n"); break; case 'update': // perform the actual update set_time_limit(5*60); // let it run for 5 minutes $sOrganizationCode = utils::ReadParam('org', ''); $sOrgSize = utils::ReadParam('org_size', 'small'); if ($sOrganizationCode == '') { $oPage->p("Error: please specify an organization (org)."); } else { // By rom $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); $oMyChange->Set("userinfo", "Made by data generator (update org '$sOrganizationCode', size '$sOrgSize')"); $oMyChange->DBInsert(); $oPage->p("Organization '$sOrganizationCode' updated."); $oGenerator = new cmdbDataGenerator($sOrganizationCode); PopulateOrganization($oMyChange, $oPage, $oGenerator, $sOrgSize); } break; case 'specify_delete': // Select an organization to be deleted $oPage->add("
\n"); $oPage->add("Select the organization to delete: \n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->p(""); $oPage->add("  \n"); $oPage->add("\n"); $oPage->add("
\n"); break; case 'confirm_delete': // confirm the dangerous action $sOrganizationCode = ReadParam('org', ''); $oPage->p("iTop Data Generator\n"); $oPage->p("Warning: you are about to delete the organization '$sOrganizationCode' and all its related objects\n"); $oPage->add("
\n"); $oPage->add("\n"); $oPage->add("\n"); $oPage->add("  \n"); $oPage->add("\n"); $oPage->add("
\n"); break; case 'delete': // perform the actual deletion $sOrganizationCode = ReadParam('org', ''); if ($sOrganizationCode == '') { $oPage->p("Error: please specify an organization (org)."); } else { // By rom $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); $oMyChange->Set("userinfo", "Made by data generator (delete org '$sOrganizationCode'"); $oMyChange->DBInsert(); $oPage->p("Deleting '$sOrganizationCode'\n"); DeleteOrganization($oMyChange, $oPage, $sOrganizationCode); } break; // display the menu of actions case 'menu': default: $oPage->p("Data Generator Menu"); $oPage->p("Generate one or more organizations"); $oPage->p("Add more objects into an organization"); $oPage->p("Delete an organization"); } $oPage->add("
\n"); $oPage->add("
\n"); $oPage->p("Return to the data generator menu"); $oPage->output(); ?>