/**
  * Helper to check wether the table has been created into the DB 
  * (this table did not exist in 1.0.1 and older versions)
  */
 public static function IsInstalled()
 {
     $sTable = MetaModel::DBGetTable(__CLASS__);
     if (CMDBSource::IsTable($sTable)) {
         return true;
     } else {
         return false;
     }
     return false;
 }
 public function DoCheckToWrite()
 {
     parent::DoCheckToWrite();
     // Check that there is at least one reconciliation key defined
     if ($this->Get('reconciliation_policy') == 'use_attributes') {
         $oSet = $this->Get('attribute_list');
         $oSynchroAttributeList = $oSet->ToArray();
         $bReconciliationKey = false;
         foreach ($oSynchroAttributeList as $oSynchroAttribute) {
             if ($oSynchroAttribute->Get('reconcile') == 1) {
                 $bReconciliationKey = true;
                 // At least one key is defined
                 break;
             }
         }
         if (!$bReconciliationKey) {
             $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:AtLeastOneReconciliationKeyMustBeSpecified');
         }
     }
     // If 'update_then_delete' is specified there must be a delete_retention_period
     if ($this->Get('delete_policy') == 'update_then_delete' && $this->Get('delete_policy_retention') == 0) {
         $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DeleteRetentionDurationMustBeSpecified');
     }
     // If update is specified, then something to update must be defined
     if (($this->Get('delete_policy') == 'update_then_delete' || $this->Get('delete_policy') == 'update') && $this->Get('delete_policy_update') == '') {
         $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DeletePolicyUpdateMustBeSpecified');
     }
     // When creating the data source with a specified database_table_name, this table must NOT exist
     if ($this->IsNew()) {
         $sDataTable = $this->GetDataTable();
         if (!empty($sDataTable) && CMDBSource::IsTable($this->GetDataTable())) {
             // Hmm, the synchro_data_xxx table already exists !!
             $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DataTableAlreadyExists', $this->GetDataTable());
         }
     }
 }
示例#3
0
 public static function DBCheckViews()
 {
     $aErrors = array();
     $aSugFix = array();
     // Reporting views (must be created after any other table)
     //
     foreach (self::GetClasses('bizmodel') as $sClass) {
         $sView = self::DBGetView($sClass);
         if (CMDBSource::IsTable($sView)) {
             // Check that the view is complete
             //
             // Note: checking the list of attributes is not enough because the columns can be stable while the SELECT is not stable
             //       Example: new way to compute the friendly name
             //       The correct comparison algorithm is to compare the queries,
             //       by using "SHOW CREATE VIEW" (MySQL 5.0.1 required) or to look into INFORMATION_SCHEMA/views
             //       both requiring some privileges
             // Decision: to simplify, let's consider the views as being wrong anytime
             if (true) {
                 // Rework the view
                 //
                 $oFilter = new DBObjectSearch($sClass, '');
                 $oFilter->AllowAllData();
                 $sSQL = $oFilter->MakeSelectQuery();
                 $aErrors[$sClass]['*'][] = "Redeclare view '{$sView}' (systematic - to support an eventual change in the friendly name computation)";
                 $aSugFix[$sClass]['*'][] = "ALTER VIEW `{$sView}` AS {$sSQL}";
             }
         } else {
             // Create the view
             //
             $oFilter = new DBObjectSearch($sClass, '');
             $oFilter->AllowAllData();
             $sSQL = $oFilter->MakeSelectQuery();
             $aErrors[$sClass]['*'][] = "Missing view for class: {$sClass}";
             $aSugFix[$sClass]['*'][] = "DROP VIEW IF EXISTS `{$sView}`";
             $aSugFix[$sClass]['*'][] = "CREATE VIEW `{$sView}` AS {$sSQL}";
         }
     }
     return array($aErrors, $aSugFix);
 }