/** * When the new datasource has been created, let's create the synchro_data table * that will hold the data records and the correspoding triggers which will maintain * both tables in sync */ protected function AfterInsert() { parent::AfterInsert(); $sTable = $this->GetDataTable(); $sReplicaTable = MetaModel::DBGetTable('SynchroReplica'); $aColumns = $this->GetSQLColumns(); $aFieldDefs = array(); // Allow '0', otherwise mysql will render an error when the id is not given // (the trigger is expected to set the value, but it is not executed soon enough) $aFieldDefs[] = "id INTEGER(11) NOT NULL DEFAULT 0 "; $aFieldDefs[] = "`primary_key` VARCHAR(255) NULL DEFAULT NULL"; foreach ($aColumns as $sColumn => $ColSpec) { $aFieldDefs[] = "`{$sColumn}` {$ColSpec} NULL DEFAULT NULL"; } $aFieldDefs[] = "INDEX (id)"; $aFieldDefs[] = "INDEX (primary_key)"; $sFieldDefs = implode(', ', $aFieldDefs); $sCreateTable = "CREATE TABLE `{$sTable}` ({$sFieldDefs}) ENGINE = " . MYSQL_ENGINE . " CHARACTER SET utf8 COLLATE utf8_unicode_ci;"; CMDBSource::Query($sCreateTable); $aTriggers = $this->GetTriggersDefinition(); foreach ($aTriggers as $key => $sTriggerSQL) { CMDBSource::Query($sTriggerSQL); } }
protected function AfterInsert() { $this->AddConnectedNetworkDevice(); parent::AfterInsert(); }