src/Controller/DefaultController.php line 173

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. //use App\Config;
  4. //use App\Controller\MongoClient;
  5. //use App\Entity\AffiliateInfo;
  6. //use App\Entity\AffiliateOfferBlock;
  7. //use App\Entity\Alerts;
  8. //use App\Entity\AppInfo;
  9. //use App\Entity\AppsflyerWatcher;
  10. //use App\Entity\Employees;
  11. //use App\Entity\HoAffiliateMmpPartnerMapping;
  12. //use App\Entity\HyperAffiliateData;
  13. //use App\Entity\MmpAdvertisers;
  14. //use App\Entity\MmpMobileApps;
  15. //use App\Entity\MmpNotifications;
  16. //use App\Entity\MmpOffers;
  17. //use App\Entity\MmpPartnerRules;
  18. //use App\Entity\MmpPartners;
  19. //use App\Entity\MmpReports;
  20. //use App\Entity\OfferInfo;
  21. //use App\Entity\OfferTagRelationship;
  22. //use App\Entity\PayoutControl;
  23. //use App\Entity\PayoutControlAffiliateHyperData;
  24. //use App\Entity\PayoutTotal;
  25. //use App\Entity\RevenueControl;
  26. //use App\Entity\RevenueControlAdvertiserHyperData;
  27. //use App\Entity\RevenueTotal;
  28. //use App\Entity\SkadNetworkPostbackLogs;
  29. //use App\Entity\OfferScheduledChangesLogs;
  30. //use App\Entity\UsersHierarchy;
  31. use App\Config;
  32. use App\Entity\AdvertiserInfo;
  33. use App\Entity\AffiliateInfo;
  34. use App\Entity\AffiliateRating;
  35. use App\Entity\AppInfo;
  36. use App\Entity\AppsflyerDatalocker;
  37. use App\Entity\Employees;
  38. use App\Entity\HyperClientInfo;
  39. use App\Entity\MafoAdvertisers;
  40. use App\Entity\MafoAdvertisersMapping;
  41. use App\Entity\MafoAffiliatesMapping;
  42. use App\Entity\MmpFraudReports;
  43. use App\Entity\MmpMobileApps;
  44. use App\Entity\MmpReports;
  45. use App\Entity\ObjectMappingWithTuneWebAccount;
  46. use App\Entity\OfferInfo;
  47. use App\Entity\OfferTagRelationship;
  48. use App\Entity\RecommendationsByObject;
  49. use App\Entity\Tag;
  50. use App\Entity\UsersHierarchy;
  51. use App\Entity\HoAffiliateMmpPartnerMapping;
  52. use App\Entity\MafoAffiliateMmpPartnerMapping;
  53. use App\Services\AdjustAPI;
  54. use App\Services\AffiliateHasofferAPI;
  55. use App\Services\Alerts;
  56. use App\Services\AppsflyerAPI;
  57. use App\Services\Aws\ElasticCache;
  58. use App\Services\Aws\S3;
  59. use App\Services\BrandHasofferAPI;
  60. use App\Services\Common;
  61. use App\Services\FinancialToolsComponents;
  62. use App\Services\HyperApis;
  63. use App\Services\ImpressionsApis;
  64. use App\Services\Integrations\CjAPI;
  65. use App\Services\Mailer;
  66. use App\Services\Metrics24APICalls;
  67. use App\Services\MmpComponents;
  68. use App\Services\MysqlQueries;
  69. use App\Services\Scraper;
  70. use App\Services\UsersComponents;
  71. use Doctrine\Persistence\ManagerRegistry;
  72. use Exception;
  73. use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
  74. use MongoClient;
  75. use MongoDB\Client as Mongo;
  76. use Ramsey\Uuid\Uuid;
  77. use Symfony\Component\HttpKernel\KernelInterface;
  78. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  79. use Symfony\Component\Mailer\Header\MetadataHeader;
  80. use Symfony\Component\Mailer\MailerInterface;
  81. use Symfony\Component\Mercure\Authorization;
  82. use Symfony\Component\Mercure\Discovery;
  83. use Symfony\Component\Mercure\HubInterface;
  84. use Symfony\Component\Mercure\Publisher;
  85. use Symfony\Component\Mercure\Update;
  86. use Symfony\Component\Mime\Email;
  87. use Symfony\Component\Mime\Part\DataPart;
  88. use Symfony\Component\Mime\Part\File;
  89. use Symfony\Component\Routing\Annotation\Route;
  90. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  91. use Symfony\Component\HttpFoundation\JsonResponse;
  92. use Symfony\Component\HttpFoundation\Request;
  93. use Symfony\Component\HttpFoundation\Response;
  94. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  95. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  96. use App\Services\NewAdjustAPI;
  97. use Symfony\Contracts\HttpClient\HttpClientInterface;
  98. use Twig\Environment;
  99. //use Ramsey\Uuid\Uuid;
  100. class DefaultController extends AbstractController
  101. {
  102.     private $commonCalls;
  103.     private $doctrine;
  104.     private $brandHasofferApi;
  105.     private $tuneApi;
  106.     private $projectDir;
  107.     private $mmpComponents;
  108.     private $financialToolsComponents;
  109.     private $gearmanClientInterface;
  110.     private $alerts;
  111.     private $rootPath;
  112.     private $afApi;
  113.     private $s3;
  114.     private AdjustAPI $adjustApi;
  115.     public function __construct(GearmanClientInterface $gearmanClientInterfaceCommon $commonCallsManagerRegistry $doctrineBrandHasofferApi $brandHasofferApistring $projectDirMmpComponents $mmpComponentsAlerts $alertsParameterBagInterface $paramsAppsflyerAPI $afApiAdjustAPI $adjustApiFinancialToolsComponents $financialToolsComponentsS3 $s3)
  116.     {
  117.         $this->commonCalls $commonCalls;
  118.         $this->doctrine $doctrine;
  119.         $this->brandHasofferApi $brandHasofferApi;
  120.         $this->tuneApi $brandHasofferApi;
  121.         $this->projectDir $projectDir;
  122.         $this->mmpComponents $mmpComponents;
  123.         $this->financialToolsComponents $financialToolsComponents;
  124.         $this->gearmanClientInterface $gearmanClientInterface;
  125.         $this->alerts $alerts;
  126.         $this->rootPath $params->get('kernel.project_dir');
  127.         $this->afApi $afApi;
  128.         $this->s3 $s3;
  129.         $this->adjustApi $adjustApi;
  130.     }
  131.     /**
  132.      * @Route("/", name="agent_homepage", host="%agents_subdomain%")
  133.      */
  134.     public function indexAgentAction(Request $request)
  135.     {
  136.         return $this->render('base_agent.html.twig', [
  137.             'template' => '/templates/dashboard.html.twig',
  138.         ]);
  139.     }
  140.     /**
  141.      * @Route("/", name="mafo_publisher_homepage", host="%publishers_subdomain%")
  142.      */
  143.     public function indexPublisherAction(Request $request)
  144.     {
  145.         return $this->render('base_mafo_publisher_cabinet.html.twig', [
  146.             'template' => '/base_mafo_publisher_cabinet.html.twig',
  147.         ]);
  148.     }
  149.     /**
  150.      * @Route("/", name="mafo_advertiser_homepage", host="%advertisers_subdomain%")
  151.      */
  152.     public function indexAdvertiserAction(Request $request)
  153.     {
  154.         return $this->render('base_mafo_advertiser_cabinet.html.twig', [
  155.             'template' => '/base_mafo_advertiser_cabinet.html.twig',
  156.         ]);
  157.     }
  158.     /**
  159.      * @Route("/", name="homepage")
  160.      */
  161.     public function indexAction(Request $request)
  162.     {
  163.         return $this->render('base.html.twig', [
  164.             'template' => '/templates/dashboard.html.twig',
  165.         ]);
  166.     }
  167.     /**
  168.      * @Route("/login", name="mafo_form_login")
  169.      */
  170.     public function mafoFormLoginAction(AuthenticationUtils $authenticationUtilsRequest $request)
  171.     {
  172.         //        $authenticationUtils = $authenticationUtils->get('security.authentication_utils');
  173.         // get the login error if there is one
  174.         $error $authenticationUtils->getLastAuthenticationError();
  175.         // last username entered by the user
  176.         $lastUsername $authenticationUtils->getLastUsername();
  177.         
  178.         // get APP_ENV from environment
  179.         $appEnv $_ENV['APP_ENV'] ?? 'prod';
  180.         return $this->render('/form_login.html.twig', [
  181.             'last_username' => $lastUsername,
  182.             'error' => $error,
  183.             'errorFromParam' => $request->query->get('error'),
  184.             'app_env' => $appEnv
  185.         ]);
  186.     }
  187.     /**
  188.      * @Route("/test", name="test_")
  189.      * @throws TransportExceptionInterface
  190.      */
  191.     public function testAction(Request $requestHyperApis $hyper)
  192.     {
  193.         die;
  194.         $md5 'c67cf54b08358c661ed28d7c28f63224';
  195.         $this->mmpComponents->updateMmpStatisticsFieldsInMmpReportByMd5($md5truetruetruetrue);
  196.         die;
  197.     }
  198.     private function migrateMmpMobileAppsAdvertiserId()
  199.     {
  200.         $mmpMobileApps $this->doctrine->getRepository(MmpMobileApps::class)->getMmpMobileAppsForAdvertiserMigration();
  201.         foreach ($mmpMobileApps as $mmpMobileApp) {
  202.             if ($mmpMobileApp['advertiserId']) {
  203.                 $checkMafoAdvertiserMappingExists $this->doctrine->getRepository(MafoAdvertisersMapping::class)->findOneBy([
  204.                     'systemIdentifier' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE,
  205.                     'systemIdentifierId' => $mmpMobileApp['advertiserId']
  206.                 ]);
  207.                 if ($checkMafoAdvertiserMappingExists) {
  208.                     $this->doctrine->getRepository(MmpMobileApps::class)->updateMmpMobileAppsById($mmpMobileApp['id'], [
  209.                         'mafoAdvertiserId' => $checkMafoAdvertiserMappingExists->getMafoAdvertiserId()->getId()
  210.                     ]);
  211.                 }
  212.             }
  213.         }
  214.     }
  215.     private function processCohortCsv()
  216.     {
  217.         ini_set('memory_limit''256M');
  218.         $fileDirectory $this->rootPath '/public/temp';
  219.         $files scandir($fileDirectory);
  220.         foreach ($files as $file) {
  221.             if (!$this->commonCalls->checkForString($file'cohort')) {
  222.                 continue;
  223.             }
  224.             $filePath $fileDirectory '/' $file;
  225.             //            $fileData = file_get_contents($filePath);
  226.             $file fopen($filePath'r');
  227.             $data = [];
  228.             while (($line fgetcsv($file)) !== FALSE) {
  229.                 //$line is an array of the csv elements
  230.                 $data[] = $line;
  231.                 if (sizeof($data) > 100) {
  232.                     break;
  233.                 }
  234.             }
  235.             fclose($file);
  236.             $dataHeaders $data[0];
  237.             unset($data[0]);
  238.             echo json_encode($data);
  239.             die;
  240.         }
  241.     }
  242.     /**
  243.      * @Route("/advertiser-list", name="advertiser_list")
  244.      */
  245.     public
  246.     function getAdvertiserListAction(Request $request)
  247.     {
  248.         $advertiserData $this->commonCalls->getAdvertisersListByStatusWithKeys();
  249.         $response = [];
  250.         foreach ($advertiserData as $key => $value) {
  251.             $response[$value['id']] = [
  252.                 'value' => $value['id'],
  253.                 'label' => $value['id'] . ' - ' $value['name']
  254.             ];
  255.         }
  256.         ksort($response);
  257.         header('Access-Control-Allow-Origin: *');
  258.         return new JsonResponse(array_values($response));
  259.     }
  260.     /**
  261.      * @Route("/affiliate-list", name="affiliate_list")
  262.      */
  263.     public
  264.     function getAffiliateListAction(Request $request)
  265.     {
  266.         $advertiserData $this->commonCalls->getAffiliateListByStatusWithKeys();
  267.         $response = [];
  268.         foreach ($advertiserData as $key => $value) {
  269.             $response[$value['id']] = [
  270.                 'value' => $value['id'],
  271.                 'label' => $value['id'] . ' - ' $value['name']
  272.             ];
  273.         }
  274.         ksort($response);
  275.         header('Access-Control-Allow-Origin: *');
  276.         return new JsonResponse(array_values($response));
  277.     }
  278.     /**
  279.      * @Route("/oauth", name="oauth")
  280.      */
  281.     public
  282.     function oauthAction()
  283.     {
  284.         return new JsonResponse(true);
  285.     }
  286.     /**
  287.      * @Route("/appsflyer/skadnetwork", name="appsflyer_skadnetwork")
  288.      */
  289.     public
  290.     function appsflyerSkadnetworkAction(Request $request)
  291.     {
  292.         if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_POST) {
  293.             $payload json_decode($request->getContent(), true);
  294.         } else if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_GET) {
  295.             $payload['transaction-id'] = $request->query->get('transaction-id');
  296.         }
  297.         if (isset($payload['transaction-id'])) {
  298.             $data $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->findOneBy([
  299.                 'transactionId' => $payload['transaction-id']
  300.             ]);
  301.             if ($data) {
  302.                 $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->updateSkadNetworkPostbackLogs($data->getId(), [
  303.                     'isPostbackAcknowledgedFromAppsflyer' => true
  304.                 ]);
  305.             }
  306.         }
  307.         return new JsonResponse(true);
  308.     }
  309.     /**
  310.      * Serve the SPA for any front-end route so React Router can handle it client-side
  311.      * This should be placed LAST in your routing to act as a catch-all
  312.      *
  313.      * @Route("/{reactRouting}", name="spa_catch_all", requirements={"reactRouting"="^(?!api|admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1)
  314.      */
  315.     public function spaCatchAll(): Response
  316.     {
  317.         return $this->render('base.html.twig', [
  318.             'template' => '/templates/dashboard.html.twig',
  319.         ]);
  320.     }
  321. }