/**
  * @see GamificationUtil::logAndNotifyOnDuplicateGameModel($logContent for an explanation of why you would
  * use this method.
  */
 public function actionRepairGamification()
 {
     $duplicateModelsData = array();
     //Check GameCoin for duplication person models
     $gameCoinDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByPersonKey(GameCoin::getTableName());
     $duplicateModelsData['GameCoin'] = $gameCoinDuplicateData;
     //Check GameCollection, GameLevel, GamePoint, and GameScore for duplicate type/person models
     $gameCollectionDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GameCollection::getTableName());
     $duplicateModelsData['GameCollection'] = $gameCollectionDuplicateData;
     $gameLevelDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GameLevel::getTableName());
     $duplicateModelsData['GameLevel'] = $gameLevelDuplicateData;
     $gamePointDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GamePoint::getTableName());
     $duplicateModelsData['GamePoint'] = $gamePointDuplicateData;
     $gameScoreDuplicateData = GamificationUtil::findGameTableRowsThatAreDuplicatedByTypePersonKey(GameScore::getTableName());
     $duplicateModelsData['GameScore'] = $gameScoreDuplicateData;
     foreach ($duplicateModelsData as $modelClassName => $duplicatesData) {
         if (empty($duplicatesData)) {
             echo 'No duplicates found for ' . $modelClassName . "<BR>";
         } else {
             echo 'Duplicates discovered for ' . $modelClassName . "<BR>";
             foreach ($duplicatesData as $typePersonKeyDuplicateData) {
                 $searchAttributeData = array();
                 if ($modelClassName == 'GameCoin') {
                     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $typePersonKeyDuplicateData['person_item_id']));
                     $searchAttributeData['structure'] = '1';
                 } else {
                     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $typePersonKeyDuplicateData['type']), 2 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $typePersonKeyDuplicateData['person_item_id']));
                     $searchAttributeData['structure'] = '1 and 2';
                 }
                 $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
                 $where = RedBeanModelDataProvider::makeWhere($modelClassName, $searchAttributeData, $joinTablesAdapter);
                 $models = $modelClassName::getSubset($joinTablesAdapter, null, null, $where, null);
                 if ($modelClassName == 'GameCoin') {
                     echo $modelClassName . ' --- Quantity of duplicates: ' . count($models) . ' --- for person_item_id: ' . $typePersonKeyDuplicateData['person_item_id'] . "<BR>";
                 } else {
                     echo $modelClassName . ' --- Quantity of duplicates: ' . count($models) . ' --- for person_item_id: ' . $typePersonKeyDuplicateData['person_item_id'] . ' with type: ' . $typePersonKeyDuplicateData['type'] . "<BR>";
                 }
                 $messageContent = null;
                 GamificationUtil::removeDuplicatesByModels($models, $messageContent);
                 echo $messageContent;
             }
         }
     }
     echo "<BR>" . 'Repair complete.' . "<BR>";
 }
 public function testFindGameTableRowsThatAreDuplicatedByPersonKey()
 {
     $this->assertEmpty(GamificationUtil::findGameTableRowsThatAreDuplicatedByPersonKey('gamecoin'));
 }