public function permitDatasetStorageTruncation(DataControllerCallContext $callcontext, DatasetMetaData $logicalDataset) { parent::permitDatasetStorageTruncation($callcontext, $logicalDataset); if (!self::isLookupDataset($logicalDataset)) { return; } $dataQueryController = data_controller_get_instance(); $metamodel = data_controller_get_metamodel(); // checking of the reference datasets have any NOT NULL data in reference columns $populatedReferenceDatasetPublicNames = NULL; foreach ($metamodel->datasets as $dataset) { foreach ($dataset->getColumns(FALSE, TRUE) as $column) { if ($column->persistence != ColumnMetaData::PERSISTENCE__STORAGE_CREATED) { continue; } if ($column->type->getReferencedDatasetName() == $logicalDataset->name) { $recordCount = $dataQueryController->countDatasetRecords( $dataset->name, array($column->name => OperatorFactory::getInstance()->initiateHandler(NotEmptyOperatorHandler::OPERATOR__NAME))); if ($recordCount > 0) { $populatedReferenceDatasetPublicNames[] = $dataset->publicName; break; } } } } // we should not allow to truncate the dataset if there is any data in any reference datasets if (isset($populatedReferenceDatasetPublicNames)) { throw new IllegalArgumentException(t( "%datasetName dataset is referenced by other datasets. The dataset truncation is not permitted unless records in %referenceDatasetNames datasets are deleted first", array( '%datasetName' => $logicalDataset->publicName, '%referenceDatasetNames' => ArrayHelper::serialize($populatedReferenceDatasetPublicNames)))); } }