public function adsCheckerAction()
 {
     ini_set('ignore_user_abort', 1);
     ini_set('max_execution_time', 120);
     /**@var $campaign VkCampaigns*/
     /**@var $vkAd VkAds*/
     /**@var $vkAccount VkAccounts*/
     /**@var $cabinet Cabinets*/
     if (date('i') % 29 === 0 || date('i') % 30 === 0) {
         $vkAccounts = $this->vkAccountsRepository->findAll();
         foreach ($vkAccounts as $vkAccount) {
             $vkApi = Vk\Core::getInstance()->apiVersion('5.5')->setToken($vkAccount->getAccessKey());
             $cabinetsInVk = $vkApi->request('ads.getAccounts')->getResponse();
             foreach ($cabinetsInVk as $cabinetInVk) {
                 $vkCabinetCheck = $this->getObjectManager()->getRepository('\\Socnet\\Entity\\Cabinets')->findBy(['account_id' => $cabinetInVk->account_id, 'vk_account_id' => $vkAccount->getId()]);
                 if (!$vkCabinetCheck) {
                     $vkCabinetEntity = new Cabinets();
                     foreach ($cabinetInVk as $key => $value) {
                         $vkCabinetEntity->set($key, $value);
                     }
                     $vkCabinetEntity->setVkUserId($vkAccount->getVkUserId());
                     $vkCabinetEntity->setVkAccountId($vkAccount->getId());
                     $this->getObjectManager()->persist($vkCabinetEntity);
                     $params = ['account_id' => $cabinetInVk->account_id];
                     $clientsInVk = $vkApi->request('ads.getClients', $params)->getResponse();
                     foreach ($clientsInVk as $client) {
                         $vkClientCheck = $this->getObjectManager()->getRepository('\\Socnet\\Entity\\VkClients')->findBy(['id' => $client->id]);
                         if (!$vkClientCheck) {
                             $vkClientsEntity = new VkClients();
                             $vkClientsEntity->setAccountId($cabinetInVk->account_id);
                             $vkClientsEntity->setBidderAccountId($vkAccount->getId());
                             foreach ($client as $key => $value) {
                                 $vkClientsEntity->set($key, $value);
                             }
                             $this->getObjectManager()->persist($vkClientsEntity);
                         }
                     }
                 }
             }
         }
         $this->getObjectManager()->flush();
     }
     return true;
 }
 private function saveVkClients(array $clients, $cabinetId, $bidderAccountId)
 {
     foreach ($clients as $client) {
         $vkClient = $this->getObjectManager()->getRepository('\\Socnet\\Entity\\VkClients')->findBy(['id' => $client->id]);
         if (!$vkClient) {
             $vkClientsEntity = new VkClients();
             $vkClientsEntity->setAccountId($cabinetId);
             $vkClientsEntity->setBidderAccountId($bidderAccountId);
             foreach ($client as $key => $value) {
                 $vkClientsEntity->set($key, $value);
             }
             $this->getObjectManager()->persist($vkClientsEntity);
         }
     }
     $this->getObjectManager()->flush();
 }