Sidebar

Using iTop

Creating your iTop

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

You are browsing the documentation for iTop 3.1 which is not the current version.

Consider browsing to iTop 3.2 documentation

iTop objects CRUD stack

Overview

This is a map of the methods called in the iTop ORM CRUD stack (Create, Update, Delete operations).

To learn more about extensibility, see Extensibility API

Objects hierarchy

There are 3 classes in iTop core that can be extended for a new iTop object :

  • DBObject : persistent objects in DB
    • CMDBObject : adds history tracking
      • cmdbAbstractObject : editable objects

All default datamodel objects are children of cmdbAbstractObject.

Stack modification history

  • 2.7.0 : transactions (see :N°679, N°2456)
  • 3.1.0 : Events (N°4756, N°5906)

Caption

<html>In bold</html> : overridable callbacks (in the code they are marked with a overwritable-hook PHPDoc tag).
<html>In red</html> : calls that has action directly on the DB.
<html>In blue</html> : parent methods.
<html>In green</html> : event.
<html>In purple</html> : object access modification.

<html> <style> /* Formatting for method types */

.format-hooks { font-weight: bold; } .format-dbwrite { color: red; } .format-parent { color: blue; } .format-event { color: green; } .format-access { color: purple; }

/* Some styling to improve stacks readability ! */ div.level2 ul,div.level3 ul {

list-style: circle inside;

} div.level2 ul ol, div.level3 ul ol {

list-style: inherit;

}

div.level2 ul li, div.level3 ul li {

padding-left: 0.5em;
border-left: 1px dotted silver;

}

div.level2 ul li div, div.level3 ul li div {

display: inline;

} </style> </html>

DBInsert

Starting from DBObject::DBInsert :

  • cmdbAbstractObject::DBInsertNoReload
    • <html>DBObject::DBInsertNoReload</html>
      • DBObject::DoComputeValues
        • cmdbAbstractObject::FireEventComputeValues
          • EventService::FireEvent(<html>EVENT_DB_COMPUTE_VALUES</html>) Since 3.1.0 N°4756
        • <html>DBObject::ComputeValues</html>
      • <html>DBObject::OnInsert</html>
      • cmdbAbstractObject::FireEventBeforeWrite
        • EventService::FireEvent(<html>EVENT_DB_BEFORE_WRITE, ['is_new' ⇒ true]</html>) Since 3.1.0 N°6324
      • DBObject::CheckToWrite
        • if MetaModel::SkipCheckToWrite return
        • <html>DBObject::SetReadOnly</html> : No DBObject::Set allowed from here Since 3.1.0 N°4756
        • cmdbAbstractObject::FireEventCheckToWrite
          • EventService::FireEvent(<html>EVENT_DB_CHECK_TO_WRITE, ['is_new' ⇒ true]</html>) Since 3.1.0 N°4756
        • <html>DBObject::SetReadWrite</html> : DBObject::Set are allowed from here Since 3.1.0 N°4756
        • <html>cmdbAbstractObject::DoCheckToWrite</html> : see dedicated chapter below
        • if CheckToWrite returned false then throw CoreCannotSaveObjectException
      • DBObject::GetState
      • foreach MetaModel::ListAttributeDefs, if ($oAttDef instanceof AttributeStopWatch)
        • ormStopWatch::Start
        • ormStopWatch::ComputeDeadlines
        • DBObject::Set : set attdef with the modified value
      • <html>CMDBSource::Query('START TRANSACTION');</html> : since 2.7.0 (N°679)
      • <html>DBObject::DBInsertSingleTable($sRootClass)</html>
      • <html>DBObject::DBInsertSingleTable($sClass)</html> : calls insert on leaf class
      • foreach MetaModel::EnumParentClasses
        • <html>DBObject::DBInsertSingleTable($sParentClass)</html> : calls insert on class hierarchy
      • <html>cmdbAbstractObject::OnObjectKeyReady</html>
        • <html>InlineImage::FinalizeInlineImages</html>
      • DBObject::DBWriteLinks
        • for each modified linkset
          • ormLinkSet::DBWrite
      • DBObject::WriteExternalAttributes
        • \AttributeCustomFields::WriteExternalValues
      • CMDBObject::RecordObjCreation
        • remove the deletion record(s)
        • any other change tracking information left prior to 2.0.3
        • DBObject::RecordObjCreation
          • DBObject::RecordLinkSetListChange
        • create a new CMDBChangeOpCreate
      • <html>CMDBSource::Query('COMMIT');</html> ROLLBACK if exception occurs
      • reset meta informations : m_bIsInDB = true, m_bDirty = false, sets m_aOrigValues[$sAttCode]
      • <html>MetaModel::StartReentranceProtection()</html> Since 3.1.0 N°4756
      • cmdbAbstractObject::PostInsertActions
        • DBObject::PostInsertActions
          • cmdbAbstractObject::FireEventAfterWrite
            • \cmdbAbstractObject::NotifyAttachedObjectsOnLinkClassModification since 3.1.0 N°5906
            • \cmdbAbstractObject::FireEventDbLinksChangedForCurrentObject <html>EVENT_DB_LINKS_CHANGED</html> since 3.1.0 N°5906
            • EventService::FireEvent(<html>EVENT_DB_AFTER_WRITE, ['changes' ⇒ [], 'is_new' ⇒ true]</html>) Since 3.1.0 N°6324
          • <html>DBObject::AfterInsert</html>
          • search for triggers :
            • $sClassList = MetaModel::EnumParentClasses
            • SELECT TriggerOnObjectCreate AS t WHERE t.target_class IN ('$sClassList')
            • loop on query results
              • <html>Trigger::DoActivate</html>
          • DBObject::ActivateOnMentionTriggers
        • foreach iApplicationObjectExtension (dans cmdbAbstractObject::DBInsert)
          • <html>iApplicationObjectExtension::OnDBInsert</html>
      • <html>MetaModel::StopReentranceProtection(REENTRANCE_TYPE_UPDATE)</html> Since 3.1.0 N°4756
      • if the object is modified DBObject::DBUpdate Since 3.1.0 N°4756
    • finally
      • if (static::IsCrudStackEmpty())
        • \cmdbAbstractObject::FireEventDbLinksChangedForAllObjects <html>EVENT_DB_LINKS_CHANGED</html> since 3.1.0 N°5906
  • return DBObject::$m_iKey

DBUpdate

  • cmdbAbstractObject::DBUpdate
    • if no change return
    • <html>DBObject::DBUpdate</html>
      • <html>MetaModel::StartReentranceProtection</html> exit if already in update ( Since 3.1.0 N°4756 )
      • DBObject::DoComputeValues
        • cmdbAbstractObject::FireEventComputeValues
          • EventService::FireEvent(<html>EVENT_DB_COMPUTE_VALUES</html>) Since 3.1.0 N°4756
        • <html>DBObject::ComputeValues</html>
      • DBObject::GetState
      • if ($sState != '')
        • foreach(MetaModel::ListAttributeDefs)
          • if ($oAttDef instanceof AttributeStopWatch)
            • ormStopWatch::ComputeDeadlines
      • <html>DBObject::OnUpdate</html>
      • cmdbAbstractObject::FireEventBeforeWrite
        • EventService::FireEvent(<html>EVENT_DB_BEFORE_WRITE, ['is_new' ⇒ false]</html>) Since 3.1.0 N°6324
      • DBObject::InitPreviousValuesForUpdatedAttributes : since 2.7.0 N°2293, set data for DBObject::ListPreviousValuesForUpdatedAttributes
      • save $this→ListChanges() to $aChanges Freeze changes
      • if (count($this→ListChanges()) == 0)
        • <html>MetaModel::StopReentranceProtection(REENTRANCE_TYPE_UPDATE)</html> Since 3.1.0 N°4756
        • return DBObject::$m_iKey;
      • DBObject::CheckToWrite
        • if MetaModel::SkipCheckToWrite return
        • <html>DBObject::SetReadOnly</html> : No DBObject::Set allowed from here ( Since 3.1.0 N°4756 )
          • cmdbAbstractObject::FireEventCheckToWrite
            • EventService::FireEvent(<html>EVENT_DB_CHECK_TO_WRITE, ['is_new' ⇒ false]</html>) Since 3.1.0 N°4756
        • <html>DBObject::SetReadWrite</html> : DBObject::Set are allowed from here ( Since 3.1.0 N°4756 )
        • <html>cmdbAbstractObject::DoCheckToWrite</html> : see dedicated chapter below
      • if returns false then throws a CoreCannotSaveObjectException
      • save original values : DBObject::$m_aOrigValues into $aOriginalValues variable
      • set $aDBChanges from $aChanges for fields having \AttributeDefinition::IsBasedOnDBColumns == true
      • <html>CMDBSource::Query('START TRANSACTION');</html> since 2.7.0 (N°679)
      • if (!MetaModel::DBIsReadOnly())
        • Update the left & right indexes for each hierarchical key
        • Update scalar attributes
          • new DBObjectSearch with current class name and id, and AllowAllData()
          • DBObjectSearch::MakeUpdateQuery using $aDBChanges
          • <html>\CMDBSource::Query</html> execute the update query
      • DBObject::DBWriteLinks
      • DBObject::WriteExternalAttributes
        • \AttributeCustomFields::WriteExternalValues
      • attributes reset : m_bDirty (to false), m_aTouchedAtt, m_aModifiedAtt ⇒ this leads to ListChanges() returning an empty array
      • DBObject::RecordAttChanges using $aChanges
      • <html>CMDBSource::Query('COMMIT');</html> ROLLBACK if exception
      • cmdbAbstractObject::PostUpdateActions
        • DBObject::PostUpdateActions
          • cmdbAbstractObject::FireEventAfterWrite
            • \cmdbAbstractObject::NotifyAttachedObjectsOnLinkClassModification since 3.1.0 N°5906
            • \cmdbAbstractObject::FireEventDbLinksChangedForCurrentObject <html>EVENT_DB_LINKS_CHANGED</html> since 3.1.0 N°5906
            • EventService::FireEvent(<html>EVENT_DB_AFTER_WRITE, ['changes' ⇒ $aChanges, 'is_new' ⇒ false]</html>) Since 3.1.0 N°6324
          • <html>DBObject::AfterUpdate</html> : since 2.7.0 N°2293 changes can be accessed using DBObject::ListPreviousValuesForUpdatedAttributes
          • reset DBObject::$m_aOrigValues
          • TriggerOnObjectUpdate : for all triggers using current class or one of its parent
            • <html>TriggerOnObjectUpdate::DoActivate</html> : Since 3.0.0 N°3245 & 3.0.2 N°5389 TriggerOnObjectUpdate is moved AFTER the database update
          • re-entrant call (N°1073) : unset(DBObject.aUpdateReentrance[$sKey]);
          • DBObject::ActivateOnMentionTriggers
        • search for iApplicationObjectExtension implementations
          • <html>iApplicationObjectExtension::OnDBUpdate</html> : since 2.7.0 N°2293 changes can be accessed using DBObject::ListPreviousValuesForUpdatedAttributes
      • <html>MetaModel::StopReentranceProtection()</html> Since 3.1.0 N°4756
      • if the object is modified and not an infinite loop Since 3.1.0
        • DBObject::DBUpdate Since 3.1.0 N°4756
      • return $this→m_iKey;
    • $this→SetWarningsAsSessionMessages('update');
    • finally
      • if (static::IsCrudStackEmpty())
        • \cmdbAbstractObject::FireEventDbLinksChangedForAllObjects <html>EVENT_DB_LINKS_CHANGED</html> since 3.1.0 N°5906
    • return $res;

DBDelete

  • cmdbAbstractObject::DBDelete
    • cmdbAbstractObject::DBDeleteTracked_Internal
      • search for iApplicationObjectExtension implementations
        • <html>iApplicationObjectExtension::OnDBDelete</html>
      • <html>CMDBObject::DBDeleteTracked_Internal</html>
        • <html>DBObject::DBDelete</html>
          • DBObject::MakeDeletionPlan
            • DeletionPlan::AddToDelete : add current object to objects to delete list
            • EventService::FireEvent(<html>EVENT_DB_CHECK_TO_DELETE, ['deletion_plan' ⇒ $oDeletionPlan]</html>) Since 3.1.0 N°4756
            • cmdbAbstractObject::DoCheckToDelete
              • <html>DBObject::DoCheckToDelete</html> : @internal but has the DeletionPlan as parameter
                • Some actions if $this→InSyncScope()
              • <html>iApplicationObjectExtension::OnCheckToDelete</html> : overridable hook but we can't access the DeletionPlan instance :(
              • UserRights::IsActionAllowed
            • DeletionPlan::SetDeletionIssues
            • DBObject::GetReferencingObjects
            • foreach ($aDependentObjects as $sRemoteClass ⇒ $aPotentialDeletes)
              • DeletionPlan::AddToUpdate : if ext key has is_null_allowed=true parameter
              • DBObject::MakeDeletionPlan : else
          • DeletionPlan::ComputeResults
          • if ($oDeletionPlan→FoundStopper())
            • EventService::FireEvent(<html>EVENT_DB_CHECK_TO_DELETE_FAILED</html>) Since 3.1.0 N°4756
            • throw throw new DeleteException
          • foreach ($oDeletionPlan→ListDeletes() as $sClass ⇒ $aToDelete)
            • DBObject::DBDeleteSingleObject
              • <html>DBObject::OnDelete</html>
              • $aParams = array('class_list' ⇒ MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
              • SELECT TriggerOnObjectDelete AS t WHERE t.target_class IN (:class_list)
                • Trigger::DoActivate
              • CMDBObject::RecordObjDeletion
                • <html>Remove CMDBChangeOp objects</html>
                • <html>DBObject::RecordObjDeletion</html>
                  • \DBObject::RecordLinkSetListChange
                • <html>Create and persist new CMDBChangeOpDelete</html>
              • foreach (MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode ⇒ $oAttDef)
                • if ($oAttDef→IsHierarchicalKey())
                  • Update the left & right indexes for each hierarchical key
                • elseif (!$oAttDef→LoadFromDB())
                  • AttributeCustomFields::DeleteValue
                    • TemplateFieldsHandler::DeleteValues
                      • DBObject::DBDelete
              • <html>CMDBSource::Query('START TRANSACTION');</html> since 2.7.0 (N°679)
              • foreach (MetaModel::EnumParentClasses(get_class($this), ENUM_PARENT_CLASSES_ALL) as $sParentClass)
                • <html>DBObject::DBDeleteSingleTable</html>
              • <html>CMDBSource::Query('COMMIT');</html> ROLLBACK if exception
              • cmdbAbstractObject::FireEventAfterDelete
                • \cmdbAbstractObject::NotifyAttachedObjectsOnLinkClassModification since 3.1.0 N°5906
                • \cmdbAbstractObject::FireEventDbLinksChangedForCurrentObject <html>EVENT_DB_LINKS_CHANGED</html> since 3.1.0 N°5906
                • EventService::FireEvent(<html>EVENT_DB_AFTER_DELETE</html>) Since 3.1.0 N°6324
              • <html>DBObject::AfterDelete</html>
          • foreach ($oDeletionPlan→ListUpdates() as $sClass ⇒ $aToUpdate)
            • DBObject::Set : reset ext key
            • DBObject::DBUpdate
    • finally
      • if (static::IsCrudStackEmpty())
        • \cmdbAbstractObject::FireEventDbLinksChangedForAllObjects <html>EVENT_DB_LINKS_CHANGED</html> since 3.1.0 N°5906

ApplyStimulus

There are no overloads, the start is in DBObject

  • DBObject::ApplyStimulus
    • if stimulus has no effect in the current state : return true
    • DBObject::Set : set the new state
    • EventService::FireEvent(<html>EVENT_DB_BEFORE_APPLY_STIMULUS</html>) Since 3.1.0 N°4756
    • foreach ($aTransitionDef['actions'] as $actionHandler)
      • if (is_string($actionHandler))
        • call_user_func($aActionCallSpec, $sStimulusCode); : pref 2.1.0 module : call method directly
      • else
        • foreach($actionHandler['params'] as $aDefinition)
          • set $value depending of parameter type
          • $bRet = call_user_func_array($aCallSpec, $aParams);
          • if ($bRet === false) IssueLog::Info + $bSuccess = false
    • if ($bSuccess)
      • Stop watches : start or stop
      • <html>if (!$bDoNotWrite) DBObject::DBWrite</html>
        • <html>if ($this→m_bIsInDB) DBObject::DBUpdate</html>
        • <html>else DBObject::DBInsert</html>
      • Search all TriggerOnStateLeave for current class and its parent
        • Trigger::DoActivate
      • Search all TriggerOnStateEnter for current class and its parent
        • Trigger::DoActivate
      • if Ok then EventService::FireEvent(<html>EVENT_DB_AFTER_APPLY_STIMULUS</html>) Since 3.1.0 N°4756
      • if not Ok then EventService::FireEvent(<html>EVENT_DB_APPLY_STIMULUS_FAILED</html>) Since 3.1.0 N°4756
    • return $bSuccess;

DoCheckToWrite

  • <html>cmdbAbstractObject::DoCheckToWrite</html> : warning not empty, do not forget to call parent when overriding !
    • <html>\DBObject</html>::<html>DoCheckToWrite</html>
      • DBObject::DoComputeValues
        • Set the “null-not-allowed” datetimes (and dates) whose value is not initialized
        • <html>DBObject::ComputeValues</html>
      • <html>DBObject::DoCheckUniqueness</html> : see dedicated chapter below
      • DBObject::ListChanges
      • foreach $aChanges
        • DBObject::CheckValue
      • <html>DBObject::CheckConsistency</html>
      • if DBObject::$m_bIsInDB && DBObject::InSyncScope && (count($aChanges) > 0)
        • add error in DBObject::$m_aCheckIssues for each attribute locked because of datasynchro (OPT_ATT_SLAVE)
    • foreach iApplicationObjectExtension
      • <html>iApplicationObjectExtension::OnCheckToWrite</html>
    • if (!$this→bAllowWrite)
      • UserRights::IsActionAllowedOnAttribute : for each change check if it is allowed (if not add error to DBObject::$m_aCheckIssues)
  • ExecutionKPI::ComputeStats

DoCheckUniqueness call hierarchy

Uniqueness rules were added in 2.6.0 with N°659.

Documentation in the XML reference

  • <html>DBObject::DoCheckToWrite</html>
    • <html>DBObject::DoCheckUniqueness</html>
      • MetaModel::GetUniquenessRules
      • foreach $aUniquenessRules
        • <html>DBObject::HasObjectsInDbForUniquenessRule</html>
          • <html>DBObject::GetSearchForUniquenessRule</html>
        • if ($bHasDuplicates)
          • <html>DBObject::GetUniquenessRuleMessage</html>
3_1_0/customization/sequence_crud.txt · Last modified: 2023/07/21 10:19 by 127.0.0.1
Back to top
Contact us