src/Controller/DefaultController.php line 421

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