$apiResponse = new APIViewData(1, $deployment, "Unable to use contact groups name specified, detected forbidden characters " . implode('', array_unique($forbidden[0])));
        $app->halt(404, $apiResponse->returnJson());
    }
    if (!isset($contactGroupsInfo['alias']) || empty($contactGroupsInfo['alias'])) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect alias parameter (longer human readable information about contact, one simple line)");
        $app->halt(404, $apiResponse->returnJson());
    } elseif (preg_match_all('/[^\\w.-\\s]/s', $contactGroupsInfo['alias'], $forbidden)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to use contact groups alias specified, detected forbidden characters " . implode('', array_unique($forbidden[0])));
        $app->halt(404, $apiResponse->returnJson());
    }
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentContactGroup($deployment, $contactGroupsInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentContactGroup($deployment, $contactGroupsInfo['name'], $contactGroupsInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Contact Group " . $contactGroupsInfo['name']);
    } else {
        RevDeploy::createDeploymentContactGroup($deployment, $contactGroupsInfo['name'], $contactGroupsInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Contact Group " . $contactGroupsInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-contact-groups');
$app->delete('/sapi/contactgroup/:deployment/:contactgroup', function ($deployment, $contactgroup) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $contactgroup)) {
        $contactgroups = preg_split('/\\s?,\\s?/', $contactgroup);
        foreach ($contactgroups as $cgtemp) {
            RevDeploy::deleteDeploymentContactGroup($deployment, $cgtemp, $deployRev);
        }
    } else {
 private static function copyContactGroups($deployment, $revision, array $cgInfo)
 {
     if (self::$init === false) {
         self::init();
     }
     foreach ($cgInfo as $cg => $cgArray) {
         if ($cgArray['deployment'] == self::$m_commonrepo && $cgArray['deployment'] == 'common') {
             continue;
         }
         if ($cgArray['deployment'] == self::$m_commonrepo) {
             continue;
         }
         foreach ($cgArray as $key => $value) {
             if (is_array($cgArray[$key])) {
                 $cgArray[$key] = implode(',', $cgArray[$key]);
             }
         }
         unset($cgArray['deployment']);
         RevDeploy::createDeploymentContactGroup($deployment, $cg, $cgArray, $revision);
     }
 }
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_group_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cgName = $this->getParam('cgName');
     $cgInfo = $this->fetchContactInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentContactGroup($deployment, $cgName, $modrevision) === true) {
         $viewData->error = 'Contact information exists for ' . $cgName . ' in ' . $deployment . ' Deployment';
         $viewData->contactInfo = $cgInfo;
         $viewData->contactgroups = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $modrevision);
         $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
         $viewData->action = 'copy_write';
         $this->sendResponse('contact_group_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentContactGroup($deployment, $cgName, $cgInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('contact_group_error');
         $viewData->error = 'Unable to write contact information for ' . $cgName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->contact = $cgName;
     $this->sendResponse('contact_group_write', $viewData);
 }