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 saveCabinets(array $cabinets, $vkUserId, $vkAccountId)
 {
     if (!$cabinets) {
         return false;
     }
     $cabinetEntity = false;
     foreach ($cabinets as $cabinet) {
         $vkCabinet = $this->getObjectManager()->getRepository('\\Socnet\\Entity\\Cabinets')->findBy(['account_id' => $cabinet->account_id, 'vk_user_id' => $vkUserId]);
         if (!$vkCabinet) {
             $cabinetEntity = new Cabinets();
             foreach ($cabinet as $key => $value) {
                 $cabinetEntity->set($key, $value);
             }
             $cabinetEntity->setVkUserId($vkUserId);
             $cabinetEntity->setVkAccountId($vkAccountId);
             $this->getObjectManager()->persist($cabinetEntity);
         }
     }
     $this->getObjectManager()->flush();
     return $cabinetEntity->getId();
 }