<?php
 namespace App\Cron\Job; class CreditCardNumbersTruncate extends \App\Cron\Job\Utils\GeneralAbstract { protected $category = 'operational'; public function validateSettings(\App\Entity\Messages $msgs, array $fields) { if ($fields['scheduleOptions']['type']!='scheduled') { $msgs->addWarningText('The process can only run `once per day or less`.'); } } protected function executeJob() { $this->logger->info(sprintf("Start truncating credit card numbers.")); $ccStorage = new \App\Utils\CreditCard\Storage(); $truncateCardsList = $ccStorage->getCardsToBeTruncated(); if (!$truncateCardsList) { $this->logger->idle("No truncating credit cards found."); } else { $this->logger->info(sprintf("Found %s credit card(s) that will be truncated.", count($truncateCardsList))); } foreach ($truncateCardsList as $idCc) { \DB::startTransaction(); $this->logger->info(sprintf("Start truncating credit card #%s.", $idCc)); $ccStorage->truncateCardNumber($idCc); \DB::commitTransaction(); $this->logger->success(sprintf("Truncated credit card #%s.", $idCc)); } if ($truncateCardsList) { $this->logger->success(sprintf("Successfully truncated %s credit card(s).", count($truncateCardsList))); } } } 