/**
  * Helper to complete the renaming of a class
  * The renaming is made in the datamodel definition, but the name has to be changed in the DB as well	 	 
  * Must be called after DB update, i.e within an implementation of AfterDatabaseCreation()
  * 	 
  * @param string $sFrom Original name (already INVALID in the current datamodel)	 	
  * @param string $sTo New name (valid in the current datamodel)
  * @return void	 	 	
  */
 public static function RenameClassInDB($sFrom, $sTo)
 {
     if (!MetaModel::IsStandaloneClass($sTo)) {
         $sRootClass = MetaModel::GetRootClass($sTo);
         $sTableName = MetaModel::DBGetTable($sRootClass);
         $sFinalClassCol = MetaModel::DBGetClassField($sRootClass);
         $sRepair = "UPDATE `{$sTableName}` SET `{$sFinalClassCol}` = '{$sTo}' WHERE `{$sFinalClassCol}` = BINARY '{$sFrom}'";
         CMDBSource::Query($sRepair);
         $iAffectedRows = CMDBSource::AffectedRows();
         SetupPage::log_info("Renaming class in DB - final class from '{$sFrom}' to '{$sTo}': {$iAffectedRows} rows affected");
     }
 }
 /**
  * Helper to complete the renaming of a class
  * The renaming is made in the datamodel definition, but the name has to be changed in the DB as well	 	 
  * Must be called after DB update, i.e within an implementation of AfterDatabaseCreation()
  * 	 
  * @param string $sFrom Original name (already INVALID in the current datamodel)	 	
  * @param string $sTo New name (valid in the current datamodel)
  * @return void	 	 	
  */
 public static function RenameClassInDB($sFrom, $sTo)
 {
     try {
         if (!MetaModel::IsStandaloneClass($sTo)) {
             $sRootClass = MetaModel::GetRootClass($sTo);
             $sTableName = MetaModel::DBGetTable($sRootClass);
             $sFinalClassCol = MetaModel::DBGetClassField($sRootClass);
             $sRepair = "UPDATE `{$sTableName}` SET `{$sFinalClassCol}` = '{$sTo}' WHERE `{$sFinalClassCol}` = BINARY '{$sFrom}'";
             CMDBSource::Query($sRepair);
             $iAffectedRows = CMDBSource::AffectedRows();
             SetupPage::log_info("Renaming class in DB - final class from '{$sFrom}' to '{$sTo}': {$iAffectedRows} rows affected");
         }
     } catch (Exception $e) {
         SetupPage::log_warning("Failed to rename class in DB - final class from '{$sFrom}' to '{$sTo}'. Reason: " . $e->getMessage());
     }
 }
예제 #3
0
 /**
  * Specify the subset of attributes to load (for each class of objects) before performing the SQL query for retrieving the rows from the DB
  * 
  * @param hash $aAttToLoad Format: alias => array of attribute_codes
  * 
  * @return void
  */
 public function OptimizeColumnLoad($aAttToLoad)
 {
     if (is_null($aAttToLoad)) {
         $this->m_aAttToLoad = null;
     } else {
         // Complete the attribute list with the attribute codes
         $aAttToLoadWithAttDef = array();
         foreach ($this->m_oFilter->GetSelectedClasses() as $sClassAlias => $sClass) {
             $aAttToLoadWithAttDef[$sClassAlias] = array();
             if (array_key_exists($sClassAlias, $aAttToLoad)) {
                 $aAttList = $aAttToLoad[$sClassAlias];
                 foreach ($aAttList as $sAttToLoad) {
                     $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttToLoad);
                     $aAttToLoadWithAttDef[$sClassAlias][$sAttToLoad] = $oAttDef;
                     if ($oAttDef->IsExternalKey()) {
                         // Add the external key friendly name anytime
                         $oFriendlyNameAttDef = MetaModel::GetAttributeDef($sClass, $sAttToLoad . '_friendlyname');
                         $aAttToLoadWithAttDef[$sClassAlias][$sAttToLoad . '_friendlyname'] = $oFriendlyNameAttDef;
                     }
                 }
             }
             // Add the friendly name anytime
             $oFriendlyNameAttDef = MetaModel::GetAttributeDef($sClass, 'friendlyname');
             $aAttToLoadWithAttDef[$sClassAlias]['friendlyname'] = $oFriendlyNameAttDef;
             // Make sure that the final class is requested anytime, whatever the specification (needed for object construction!)
             if (!MetaModel::IsStandaloneClass($sClass) && !array_key_exists('finalclass', $aAttToLoadWithAttDef[$sClassAlias])) {
                 $aAttToLoadWithAttDef[$sClassAlias]['finalclass'] = MetaModel::GetAttributeDef($sClass, 'finalclass');
             }
         }
         $this->m_aAttToLoad = $aAttToLoadWithAttDef;
     }
 }
예제 #4
0
/**
 * Display the list of classes from the business model
 */
function DisplayClassesList($oPage, $sContext)
{
    $oPage->add("<h1>" . Dict::S('UI:Schema:Title') . "</h1>\n");
    $oPage->add("<ul id=\"ClassesList\" class=\"treeview fileview\">\n");
    // Get all the "root" classes for display
    $aRootClasses = array();
    foreach (MetaModel::GetClasses() as $sClassName) {
        if (MetaModel::IsRootClass($sClassName)) {
            $aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
        } elseif (MetaModel::IsStandaloneClass($sClassName)) {
            $aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
        }
    }
    // Sort them alphabetically on their display name
    asort($aRootClasses);
    foreach ($aRootClasses as $sClassName => $sDisplayName) {
        if (MetaModel::IsRootClass($sClassName)) {
            $oPage->add("<li class=\"open\">" . MakeClassHLink($sClassName, $sContext) . "\n");
            DisplaySubclasses($oPage, $sClassName, $sContext);
            $oPage->add("</li>\n");
        } elseif (MetaModel::IsStandaloneClass($sClassName)) {
            $oPage->add("<li>" . MakeClassHLink($sClassName, $sContext) . "</li>\n");
        }
    }
    $oPage->add("</ul>\n");
    $oPage->add("<h1>" . Dict::S('UI:Schema:Relationships') . "</h1>\n");
    $oPage->add("<ul id=\"ClassesRelationships\" class=\"treeview\">\n");
    foreach (MetaModel::EnumRelations() as $sRelCode) {
        $oPage->add("<li>" . MakeRelationHLink($sRelCode, $sContext) . "\n");
        $oPage->add("<ul>\n");
        $oPage->add("<li>Description: " . htmlentities(MetaModel::GetRelationDescription($sRelCode), ENT_QUOTES, 'UTF-8') . "</li>\n");
        $oPage->add("<li>Verb up: " . htmlentities(MetaModel::GetRelationVerbUp($sRelCode), ENT_QUOTES, 'UTF-8') . "</li>\n");
        $oPage->add("<li>Verb down: " . htmlentities(MetaModel::GetRelationVerbDown($sRelCode), ENT_QUOTES, 'UTF-8') . "</li>\n");
        $oPage->add("</ul>\n");
        $oPage->add("</li>\n");
    }
    $oPage->add("</ul>\n");
    $oPage->add_ready_script('$("#ClassesList").treeview();');
    $oPage->add_ready_script('$("#ClassesRelationships").treeview();');
}