src/Controller/DefaultController.php line 373

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 Psr\Cache\CacheItemPoolInterface;
  95. use App\Services\NewAdjustAPI;
  96. use Symfony\Contracts\HttpClient\HttpClientInterface;
  97. use Twig\Environment;
  98. //use Ramsey\Uuid\Uuid;
  99. class DefaultController extends AbstractController
  100. {
  101. private $commonCalls;
  102. private $doctrine;
  103. private $brandHasofferApi;
  104. private $tuneApi;
  105. private $projectDir;
  106. private $mmpComponents;
  107. private $financialToolsComponents;
  108. private $gearmanClientInterface;
  109. private $alerts;
  110. private $rootPath;
  111. private $afApi;
  112. private $s3;
  113. private AdjustAPI $adjustApi;
  114. private $showLoginForm;
  115. public function __construct(GearmanClientInterface $gearmanClientInterface, Common $commonCalls, ManagerRegistry $doctrine, BrandHasofferApi $brandHasofferApi, string $projectDir, MmpComponents $mmpComponents, Alerts $alerts, ParameterBagInterface $params, AppsflyerAPI $afApi, AdjustAPI $adjustApi, FinancialToolsComponents $financialToolsComponents, S3 $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", host="%main_subdomain%")
  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", host="%main_subdomain%")
  169. */
  170. public function mafoFormLoginAction(AuthenticationUtils $authenticationUtils, Request $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. // get APP_ENV from environment
  178. $appEnv = $_ENV['APP_ENV'] ?? 'prod';
  179. return $this->render('/form_login.html.twig', [
  180. 'last_username' => $lastUsername,
  181. 'error' => $error,
  182. 'errorFromParam' => $request->query->get('error'),
  183. 'show_login_form' => $_ENV['APP_ENV'] === 'dev'
  184. ]);
  185. }
  186. /**
  187. * @Route("/test", name="test_", host="%main_subdomain%")
  188. * @throws TransportExceptionInterface
  189. */
  190. public function testAction(Request $request, ParameterBagInterface $params)
  191. {
  192. die;
  193. }
  194. public function encode(array $payload): string
  195. {
  196. $key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.4-y-tvc0_uDOaUvjwcMwGXXH1Ei1dDizOW__P_Q_w6Y";
  197. $header = [
  198. "alg" => "HS512",
  199. "typ" => "JWT"
  200. ];
  201. $encodedHeader = rtrim(strtr(base64_encode(json_encode($header)), '+/', '-_'), '=');
  202. $encodedPayload = rtrim(strtr(base64_encode(json_encode($payload)), '+/', '-_'), '=');
  203. $signature = hash_hmac('sha512', "$encodedHeader.$encodedPayload", $key, true);
  204. $encodedSignature = rtrim(strtr(base64_encode($signature), '+/', '-_'), '=');
  205. return "{$encodedHeader}.{$encodedPayload}.{$encodedSignature}";
  206. }
  207. private function migrateMmpMobileAppsAdvertiserId()
  208. {
  209. $mmpMobileApps = $this->doctrine->getRepository(MmpMobileApps::class)->getMmpMobileAppsForAdvertiserMigration();
  210. foreach ($mmpMobileApps as $mmpMobileApp) {
  211. if ($mmpMobileApp['advertiserId']) {
  212. $checkMafoAdvertiserMappingExists = $this->doctrine->getRepository(MafoAdvertisersMapping::class)->findOneBy([
  213. 'systemIdentifier' => Config::MAFO_SYSTEM_IDENTIFIER_TUNE_MOBILE,
  214. 'systemIdentifierId' => $mmpMobileApp['advertiserId']
  215. ]);
  216. if ($checkMafoAdvertiserMappingExists) {
  217. $this->doctrine->getRepository(MmpMobileApps::class)->updateMmpMobileAppsById($mmpMobileApp['id'], [
  218. 'mafoAdvertiserId' => $checkMafoAdvertiserMappingExists->getMafoAdvertiserId()->getId()
  219. ]);
  220. }
  221. }
  222. }
  223. }
  224. private function processCohortCsv()
  225. {
  226. ini_set('memory_limit', '256M');
  227. $fileDirectory = $this->rootPath . '/public/temp';
  228. $files = scandir($fileDirectory);
  229. foreach ($files as $file) {
  230. if (!$this->commonCalls->checkForString($file, 'cohort')) {
  231. continue;
  232. }
  233. $filePath = $fileDirectory . '/' . $file;
  234. // $fileData = file_get_contents($filePath);
  235. $file = fopen($filePath, 'r');
  236. $data = [];
  237. while (($line = fgetcsv($file)) !== FALSE) {
  238. //$line is an array of the csv elements
  239. $data[] = $line;
  240. if (sizeof($data) > 100) {
  241. break;
  242. }
  243. }
  244. fclose($file);
  245. $dataHeaders = $data[0];
  246. unset($data[0]);
  247. echo json_encode($data);
  248. die;
  249. }
  250. }
  251. /**
  252. * @Route("/advertiser-list", name="advertiser_list", host="%main_subdomain%")
  253. */
  254. public
  255. function getAdvertiserListAction(Request $request)
  256. {
  257. $advertiserData = $this->commonCalls->getAdvertisersListByStatusWithKeys();
  258. $response = [];
  259. foreach ($advertiserData as $key => $value) {
  260. $response[$value['id']] = [
  261. 'value' => $value['id'],
  262. 'label' => $value['id'] . ' - ' . $value['name']
  263. ];
  264. }
  265. ksort($response);
  266. header('Access-Control-Allow-Origin: *');
  267. return new JsonResponse(array_values($response));
  268. }
  269. /**
  270. * @Route("/affiliate-list", name="affiliate_list", host="%main_subdomain%")
  271. */
  272. public
  273. function getAffiliateListAction(Request $request)
  274. {
  275. $advertiserData = $this->commonCalls->getAffiliateListByStatusWithKeys();
  276. $response = [];
  277. foreach ($advertiserData as $key => $value) {
  278. $response[$value['id']] = [
  279. 'value' => $value['id'],
  280. 'label' => $value['id'] . ' - ' . $value['name']
  281. ];
  282. }
  283. ksort($response);
  284. header('Access-Control-Allow-Origin: *');
  285. return new JsonResponse(array_values($response));
  286. }
  287. /**
  288. * @Route("/oauth", name="oauth", host="%main_subdomain%")
  289. */
  290. public
  291. function oauthAction()
  292. {
  293. return new JsonResponse(true);
  294. }
  295. /**
  296. * @Route("/appsflyer/skadnetwork", name="appsflyer_skadnetwork", host="%main_subdomain%")
  297. */
  298. public
  299. function appsflyerSkadnetworkAction(Request $request)
  300. {
  301. if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_POST) {
  302. $payload = json_decode($request->getContent(), true);
  303. } else if ($_SERVER['REQUEST_METHOD'] === Config::HTTP_METHOD_GET) {
  304. $payload['transaction-id'] = $request->query->get('transaction-id');
  305. }
  306. if (isset($payload['transaction-id'])) {
  307. $data = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->findOneBy([
  308. 'transactionId' => $payload['transaction-id']
  309. ]);
  310. if ($data) {
  311. $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->updateSkadNetworkPostbackLogs($data->getId(), [
  312. 'isPostbackAcknowledgedFromAppsflyer' => true
  313. ]);
  314. }
  315. }
  316. return new JsonResponse(true);
  317. }
  318. /**
  319. * Serve the SPA for any front-end route so React Router can handle it client-side
  320. * This should be placed LAST in your routing to act as a catch-all
  321. *
  322. * @Route("/{reactRouting}", name="spa_catch_all", requirements={"reactRouting"="^(?!api|!admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1, host="%main_subdomain%")
  323. */
  324. public function spaCatchAll(): Response
  325. {
  326. if (!$this->getUser()) {
  327. return $this->redirectToRoute('mafo_form_login');
  328. }
  329. return $this->render('base.html.twig', [
  330. 'template' => '/templates/dashboard.html.twig',
  331. ]);
  332. }
  333. /**
  334. * Serve the SPA for any front-end route so React Router can handle it client-side
  335. * This should be placed LAST in your routing to act as a catch-al
  336. *
  337. * @Route("/{reactRouting}", name="spa_catch_all_advertiser", requirements={"reactRouting"="^(?!api|!admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1, host="%advertisers_subdomain%")
  338. */
  339. public function spaCatchAllAdvertiser(): Response
  340. {
  341. if (!$this->getUser()) {
  342. return $this->redirectToRoute('client_advertiser_login');
  343. }
  344. return $this->render('base_mafo_advertiser_cabinet.html.twig', [
  345. 'template' => '/base_mafo_advertiser_cabinet.html.twig',
  346. ]);
  347. }
  348. /**
  349. * Serve the SPA for any front-end route so React Router can handle it client-side
  350. * This should be placed LAST in your routing to act as a catch-al
  351. *
  352. * @Route("/{reactRouting}", name="spa_catch_all_publisher_cabinet", requirements={"reactRouting"="^(?!api|!admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1, host="%publishers_subdomain%")
  353. */
  354. public function spaCatchAllPublisherCabinet(): Response
  355. {
  356. if (!$this->getUser()) {
  357. return $this->redirectToRoute('client_publisher_login');
  358. }
  359. return $this->render('base_mafo_publisher_cabinet.html.twig', [
  360. 'template' => '/base_mafo_publisher_cabinet.html.twig'
  361. ]);
  362. }
  363. /**
  364. * Serve the SPA for adcabinet host
  365. *
  366. * @Route("/", name="adcabinet_homepage", methods={"GET"}, host="%adcabinet_subdomain%")
  367. * @Route("/{reactRouting}", name="spa_catch_all_adcabinet", requirements={"reactRouting"="^(?!api|!admin|_wdt|_profiler).*"}, methods={"GET"}, priority=-1, host="%adcabinet_subdomain%")
  368. */
  369. public function spaCatchAllAdCabinet(): Response
  370. {
  371. if (!$this->getUser()) {
  372. return $this->redirectToRoute('client_adcabinet_login');
  373. }
  374. return $this->render('base_mafo_advertiser_cabinet.html.twig', [
  375. 'template' => '/base_mafo_advertiser_cabinet.html.twig',
  376. ]);
  377. }
  378. }