inital commit

This commit is contained in:
2026-06-19 20:08:01 +06:00
commit 8a5abeeae4
13128 changed files with 3192007 additions and 0 deletions

231
src/Shell/AppShell.php Normal file
View File

@@ -0,0 +1,231 @@
<?php
namespace App\Shell;
use App\Utility\ManageLog;
use Cake\Console\Shell;
use Cake\Mailer\Email;
use Cake\Log\Log;
/**
* App shell command.
*/
class AppShell extends Shell
{
public function getSystemCurrentTimeStamp($formate='',$time_zone = "UTC")
{
date_default_timezone_set($time_zone);
if($formate==''){
return date("Y-m-d H:i:s");
} else {
return date($formate);
}
}
/**
* Manage the available sub-commands along with their arguments and help
*
* @see http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = parent::getOptionParser();
return $parser;
}
/**
* main() method.
*
* @return bool|int|null Success or error code.
*/
public function main()
{
$this->out($this->OptionParser->help());
}
public function sendEmail($templateName, $templateContent, $to,$sub="New Client Portal Registration",$attachment = "",$from_name = APP_SMTP_FROM_NAME,$personalize = null)
{
$APP_SMTP_USERNAME = APP_SMTP_USERNAME;
$APP_SMTP_FROM_NAME = APP_SMTP_FROM_NAME;
$APP_EMAIL_CLASS = APP_EMAIL_CLASS;
$APP_SMTP_HOST = APP_SMTP_HOST;
$APP_SMTP_PORT = APP_SMTP_PORT;
$APP_SMTP_TIMEOUT = APP_SMTP_TIMEOUT;
$APP_SMTP_PASSWORD = APP_SMTP_PASSWORD;
$APP_SMTP_IS_TLS = APP_SMTP_IS_TLS;
$APP_SMTP_FROM_NAME = $from_name;
if(!empty($personalize) && $personalize->is_smtp == 1){
$APP_SMTP_USERNAME = $personalize->username;
$APP_SMTP_FROM_NAME = $personalize->smtp_from;
$APP_SMTP_HOST = $personalize->smtp_host;
$APP_SMTP_PORT = $personalize->smtp_port;
$APP_SMTP_PASSWORD = $personalize->password;
$templateContent['email_signature'] = $personalize->email_signature;
}
$SMTP_FORM_EMAIL = $APP_SMTP_USERNAME;
if($APP_SMTP_HOST == 'sandbox.smtp.mailtrap.io'){
$SMTP_FORM_EMAIL = $APP_SMTP_FROM_NAME;
}
if(isset($templateContent['company_email']) && !empty($templateContent['company_email'])){
$SMTP_FORM_EMAIL = $templateContent['company_email'];
}
if(isset($templateContent['company_name']) && !empty($templateContent['company_name'])){
$APP_SMTP_FROM_NAME = $templateContent['company_name'];
}
$default = [
'className' => $APP_EMAIL_CLASS,
'host' => $APP_SMTP_HOST,
'port' => $APP_SMTP_PORT,
'timeout' => $APP_SMTP_TIMEOUT,
'username' => $APP_SMTP_USERNAME,
'password' => $APP_SMTP_PASSWORD,
'tls' => $APP_SMTP_IS_TLS
];
try {
$email = new Email();
//$email = $email->reset();
if(!empty($personalize) && $personalize->is_smtp == 1){
$email->config($default);
} else {
$email->transport('default');
}
if (isset($templateContent['no_reply']) && !empty($templateContent['no_reply'])) {
$email = $email->from($APP_SMTP_FROM_NAME);
} else {
$email = $email->from($SMTP_FORM_EMAIL,$APP_SMTP_FROM_NAME);
}
$email->template($templateName)
->emailFormat('html')
->to($to)
->viewVars($templateContent)
->subject($sub);
if(!empty($attachment)){
$email->addAttachments($attachment);
}
$email ->send();
} catch (\Exception $ex) {
$this->log($ex);
}
}
public function sendMultipleEmail($templateName, $templateContentArray, $personalize = null) {
$APP_SMTP_USERNAME = APP_SMTP_USERNAME;
$APP_SMTP_FROM_NAME = APP_SMTP_FROM_NAME;
$APP_EMAIL_CLASS = APP_EMAIL_CLASS;
$APP_SMTP_HOST = APP_SMTP_HOST;
$APP_SMTP_PORT = APP_SMTP_PORT;
$APP_SMTP_TIMEOUT = APP_SMTP_TIMEOUT;
$APP_SMTP_PASSWORD = APP_SMTP_PASSWORD;
$APP_SMTP_IS_TLS = APP_SMTP_IS_TLS;
if (!empty($personalize)) {
$templateContent['email_signature'] = $personalize->email_signature;
if ($personalize->is_smtp == 1) {
$APP_SMTP_USERNAME = $personalize->username;
$APP_SMTP_FROM_NAME = $personalize->smtp_from;
$APP_SMTP_HOST = $personalize->smtp_host;
$APP_SMTP_PORT = $personalize->smtp_port;
$APP_SMTP_PASSWORD = $personalize->password;
}
}
$default = [
'className' => $APP_EMAIL_CLASS,
'host' => $APP_SMTP_HOST,
'port' => $APP_SMTP_PORT,
'timeout' => $APP_SMTP_TIMEOUT,
'username' => $APP_SMTP_USERNAME,
'password' => $APP_SMTP_PASSWORD,
'tls' => $APP_SMTP_IS_TLS,
];
$SMTP_FORM_EMAIL = $APP_SMTP_USERNAME;
if($APP_SMTP_HOST == 'sandbox.smtp.mailtrap.io'){
$SMTP_FORM_EMAIL = $APP_SMTP_FROM_NAME;
}
if(isset($templateContent['company_email']) && !empty($templateContent['company_email'])){
$SMTP_FORM_EMAIL = $templateContent['company_email'];
}
if(isset($templateContent['company_name']) && !empty($templateContent['company_name'])){
$APP_SMTP_FROM_NAME = $templateContent['company_name'];
}
try {
$email = new Email();
if (!empty($personalize) && $personalize->is_smtp == 1) {
$email->config($default);
} else {
$email->transport('default');
}
if(!empty($templateContentArray)){
foreach($templateContentArray as $templateContent){
$to = $templateContent['to'];
$sub = $templateContent['sub'];
$attachment = $templateContent['attachment'];
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_TO_EMAIL_INFO_setupEmailAutomation";
$L['automtion_schedule_id'] = $templateContent['automtion_schedule_id'];
$L['email'] = $to;
$L['sub'] = $sub;
$L['member_id'] = $personalize->member_id > 0 ? $personalize->member_id : 0;
$cli_logData['data'] = $L;
$this->cronjobLog($cli_logData);
if (isset($templateContent['no_reply']) && !empty($templateContent['no_reply'])) {
$email = $email->from($APP_SMTP_FROM_NAME);
} else {
$email = $email->from($SMTP_FORM_EMAIL,$APP_SMTP_FROM_NAME);
}
$email->template($templateName)
->emailFormat('html')
->to($to)
->viewVars($templateContent)
->subject($sub);
if (!empty($attachment)) {
$email->addAttachments($attachment);
}
$email->send();
}
}
} catch (Exception $ex) {
$this->log($ex);
}
}
public function cronjobLog($data){
ManageLog::createLog($data);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Datasource\ConnectionManager;
/**
* AssignPackage shell command.
*/
class AssignPackageShell extends AppShell
{
public function assignPackage(){
$connection = ConnectionManager::get('default');
$current_date = date('Y-m-d H:i:s');
$sql = "select * from cmsusers where status = 1 AND ";
$sql .= "(DATEDIFF('$current_date', created_on) > 14";
$sql .= " OR DATEDIFF('$current_date', created_on) > 31)";
$assignPackage = $connection->execute($sql)->fetchAll('assoc');
$this->loadModel('MemberPackages');
if(!empty($assignPackage)) {
foreach ($assignPackage as $pkg) {
$inpudata = [];
$now = strtotime($current_date); // or your date as well
$your_date = strtotime($pkg['created_on']);
$datediff = $now - $your_date;
$days = round($datediff / (60 * 60 * 24));
if($days > 15 && $days < 30){
$inpudata['member_id'] = $pkg['id'];
$inpudata['package_id'] = PACKAGE_WAVE_2_ID;
}else if($days > 30) {
$inpudata['member_id'] = $pkg['id'];
$inpudata['package_id'] = PACKAGE_WAVE_3_ID;
}
if(!empty($inpudata)){
$this->MemberPackages->assignPackage($inpudata);
}
}
}
}
/**
* Manage the available sub-commands along with their arguments and help
*
* @see http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = parent::getOptionParser();
return $parser;
}
/**
* main() method.
*
* @return bool|int|null Success or error code.
*/
public function main()
{
$this->out($this->OptionParser->help());
}
}

File diff suppressed because it is too large Load Diff

156
src/Shell/BackendShell.php Normal file
View File

@@ -0,0 +1,156 @@
<?php
/**
* Created by PhpStorm.
* User: rsi
* Date: 08-Feb-16
* Time: 9:30 PM
*/
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Datasource\ConnectionManager;
class BackendShell extends AppShell
{
public function initialize()
{
parent::initialize();
$this->loadModel('Artists');
}
public function main()
{
$this->out('Hello world.');
}
public function startArtistProc($schedule = null)
{
if (!$schedule) {
$this->out();
$this->err('Missing the parameter \'schedule\'');
$this->out('Please set the parameter along with the command.');
$this->out();
$this->out('eg :- backend start_artist_proc "0 * * * *"');
$this->out();
$this->out('* * * * *');
$this->out('| | | | |');
$this->out('| | | | |');
$this->out('| | | | \----- day of week (0 - 6) (0 to 6 are Sunday to Saturday,');
$this->out('| | | | or use names)');
$this->out('| | | \---------- month (1 - 12)');
$this->out('| | \--------------- day of month (1 - 31)');
$this->out('| \-------------------- hour (0 - 23)');
$this->out('\------------------------- min (0 - 59)');
$this->out();
$schedule = $this->in('Please pass in the schedule in the above mentioned format');
$this->clear();
}
$schedule = trim($schedule);
if ($this->validateSchedule($schedule)) {
$this->out('Setting up...');
$cron = $schedule . ' ' . BP_ARTISTS_CRON;
if ($this->cronjobExists(BP_ARTISTS_CRON)) {
$this->out('Existing backend job found. Removing ...');
$removeCommand = "crontab -l | grep -v '" . BP_ARTISTS_CRON . "' | crontab -";
shell_exec($removeCommand);
$this->out("Removed existing backend job!");
}
$this->appendCronjob($cron);
$this->out('New backend job added successfully!');
}
}
public function artistProc()
{
$this->out("Artist proc started!");
$connection = ConnectionManager::get('default');
$totalCommentsPerArtist = $connection->query('SELECT contents.artist_id, COUNT(contents.artist_id) AS total_comments FROM contents INNER JOIN content_comments ON content_comments.content_id = contents.id GROUP BY contents.artist_id');
$totalLikesPerArtist = $connection->query('SELECT contents.artist_id, COUNT(contents.artist_id) AS total_likes FROM contents INNER JOIN collections ON collections.content_id = contents.id WHERE collections.type = 1 GROUP BY contents.artist_id');
$totalFollowersPerArtist = $connection->query('SELECT artist_id, COUNT(*) AS total_followers FROM ( SELECT cc.user_id, c.artist_id FROM content_comments cc INNER JOIN contents c on cc.content_id = c.id UNION SELECT ccs.user_id, c.artist_id FROM collections ccs INNER JOIN contents c on ccs.content_id = c.id WHERE ccs.type = 1) AS t GROUP BY artist_id');
$connection->begin();
foreach($totalCommentsPerArtist as $totalComments){
$connection->execute('UPDATE artists SET artists.total_comments = ? WHERE artists.id = ?', [
$totalComments['total_comments'], $totalComments['artist_id']
]);
$this->out('artist_id - ' . $totalComments['artist_id']. ' total_comments - '. $totalComments['total_comments']);
}
foreach($totalLikesPerArtist as $totalLikes){
$connection->execute('UPDATE artists SET artists.total_likes = ? WHERE artists.id = ?', [
$totalLikes['total_likes'], $totalLikes['artist_id']
]);
$this->out('artist_id - ' . $totalLikes['artist_id']. ' total_likes - '. $totalLikes['total_likes']);
}
foreach($totalFollowersPerArtist as $totalFollowers){
$connection->execute('UPDATE artists SET artists.total_followers = ? WHERE artists.id = ?', [
$totalFollowers['total_followers'], $totalFollowers['artist_id']
]);
$this->out('artist_id - ' . $totalFollowers['artist_id']. ' total_followers - '. $totalFollowers['total_followers']);
}
$connection->commit();
}
function validateSchedule($schedule)
{
$scheduleParamArray = preg_split('/\s+/', $schedule);
$count = count($scheduleParamArray);
if ($count != 5) {
$this->error("Invalid schedule");
}
return true;
}
function cronjobExists($command)
{
$cronjob_exists = false;
$crontab = null;
exec('crontab -l', $crontab);
if (isset($crontab) && is_array($crontab)) {
foreach ($crontab as $tab) {
if (strpos($tab, $command) !== false) {
$cronjob_exists = true;
}
}
}
return $cronjob_exists;
}
function appendCronjob($command)
{
$output = null;
if (is_string($command) && !empty($command)) {
$executingCommand = 'echo -e "`crontab -l`\n' . $command . '" | crontab -';
exec($executingCommand, $output);
}
return $output;
}
}

View File

@@ -0,0 +1,278 @@
<?php
namespace App\Shell;
use App\Utility\ManageLog;
use Cake\Log\Log;
class ClientDocumentCleaningShell extends AppShell {
public function initialize() {
$this->loadModel('Clients');
}
public function main() {
$this->out('Start');
// ManageLog::getQueryLog('DatabaseCleaning');
$this->resourceDeleteOfInactiveClient();
$this->out('Cleaning completed');
$this->out('End');
}
private function GetDirectorySize($path){
$bytestotal = 0;
$path = realpath($path);
if($path!==false && $path!='' && file_exists($path)){
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
private function resourceDeleteOfInactiveClient(){
$cli_logData['action'] = "DELETE_INACTIVE_CLIENT_LAST_ONE_YEAR_TOTAL_FILE_SIZE_IN_BYTES";
$total_file_size = 0;
$size['epicvelocity_letter'] = 0; // Letters table
$size['client_agreement_files'] = 0; // AgreementAssignments table
$size['contact_photo'] = 0; // client table
$size['html_content'] = 0;
$size['html_history_code'] = 0;
$size['html_history_code_history_data'] = 0;
$size['pdfletters_epic_velocity'] = 0;
$size['pdfletters_super_rtg'] = 0;
$size['pdfletters_velocity'] = 0;
$size['pdfletters_zip'] = 0;
$size['rtg_letters_dropbox'] = 0;
$size['rtg_letters_google_drive'] = 0;
$size['rtg_letters_letterstream'] = 0;
$size['rtg_letters_ringcentral'] = 0;
$size['rtg_letters_zapier'] = 0;
$size['velocity'] = 0;
$size['velocity_ringcentral'] = 0;
$size['velocity_letterstream'] = 0;
$clients = $this->Clients->find()
->where(['status'=>2])
->where('DATEDIFF(CURDATE(),modified_on) >='. 365)
->toArray();
// dd($clients);
$this->loadModel('Letters');
$client_id_list = [];
if(!empty($clients)) {
foreach ($clients as $client) {
$total_size = 0;
$client_id = $client->id;
$member_id = $client->cmsuser_id;
if(empty($client)){
continue;
}
$client->status = 4; // status 4 -- is deleted from db
// $this->Clients->save($client);
$letters = $this->Letters->find()->where(['cmsuser_id'=> $member_id , 'client_id'=> $client_id])->toArray();
if(!empty($letters)){
foreach($letters as $letter){
$letter_file = WWW_ROOT."epicvelocity/letters/".$letter->zip_file;
$size['epicvelocity_letter'] = $size['epicvelocity_letter'] + $this->checkDirectoryAndDelete($letter_file);
}
}
$total_size = $total_size + $size['epicvelocity_letter'];
// client_agreement_files/<member-id>/<client-id>
$client_agreement_files_path = WWW_ROOT.'client_agreement_files/' . $member_id . "/" . $client_id ;
$size['client_agreement_files'] = $size['client_agreement_files'] + $this->checkDirectoryAndDelete($client_agreement_files_path);
$total_size = $total_size + $size['client_agreement_files'];
// contact_photo/<client-id>
$contact_photo_path = WWW_ROOT.'contact_photo/' . $client_id ;
$size['contact_photo'] = $size['contact_photo'] + $this->checkDirectoryAndDelete($contact_photo_path);
$total_size = $total_size + $size['contact_photo'];
//html_content/<member-id>/<client-id>
$html_content_path = WWW_ROOT.'html_content/' . $member_id . "/" . $client_id ;
$size['html_content'] = $size['html_content'] + $this->checkDirectoryAndDelete($html_content_path);
$total_size = $total_size + $size['html_content'];
//html_history_code/<member-id>/<client-id>
$html_history_code_path = WWW_ROOT.'html_history_code/' . $member_id . "/" . $client_id ;
$size['html_history_code'] = $size['html_history_code'] + $this->checkDirectoryAndDelete($html_history_code_path);
$total_size = $total_size + $size['html_history_code'];
//html_history_code/history_data/<member-id>/<client-id>
$html_history_code_history_data_path = WWW_ROOT.'html_history_code/history_data/' . $member_id . "/" . $client_id ;
$size['html_history_code_history_data'] = $size['html_history_code_history_data'] + $this->checkDirectoryAndDelete($html_history_code_history_data_path);
$total_size = $total_size + $size['html_history_code_history_data'];
//pdfletters/Epic Velocity/<member-id>/<client-id>
$pdfletters_epic_velocity_path = WWW_ROOT.'pdfletters/Epic Velocity/' . $member_id . "/" . $client_id ;
$size['pdfletters_epic_velocity'] = $size['pdfletters_epic_velocity'] + $this->checkDirectoryAndDelete($pdfletters_epic_velocity_path);
$total_size = $total_size + $size['pdfletters_epic_velocity'];
//pdfletters/Super RTG/<member-id>/<client-id>
$pdfletters_super_rtg_path = WWW_ROOT.'pdfletters/Super RTG/' . $member_id . "/" . $client_id ;
$size['pdfletters_super_rtg'] = $size['pdfletters_super_rtg'] + $this->checkDirectoryAndDelete($pdfletters_super_rtg_path);
$total_size = $total_size + $size['pdfletters_super_rtg'];
//pdfletters/Velocity/<member-id>/<client-id>
$pdfletters_velocity_path = WWW_ROOT.'pdfletters/Velocity/' . $member_id . "/" . $client_id ;
$size['pdfletters_velocity'] = $size['pdfletters_velocity'] + $this->checkDirectoryAndDelete($pdfletters_velocity_path);
$total_size = $total_size + $size['pdfletters_velocity'];
//pdfletters/zip/<member-id>/<client-id>
$pdfletters_zip_path = WWW_ROOT.'pdfletters/zip/' . $member_id . "/" . $client_id ;
$size['pdfletters_zip'] = $size['pdfletters_zip'] + $this->checkDirectoryAndDelete($pdfletters_zip_path);
$total_size = $total_size + $size['pdfletters_zip'];
//rtg_letters/dropbox/<member-id>/<client-id>
$rtg_letters_dropbox_path = WWW_ROOT.'rtg_letters/dropbox/' . $member_id . "/" . $client_id ;
$size['rtg_letters_dropbox'] = $size['rtg_letters_dropbox'] + $this->checkDirectoryAndDelete($rtg_letters_dropbox_path);
$total_size = $total_size + $size['rtg_letters_dropbox'];
//rtg_letters/google_drive/<member-id>/<client-id>
$rtg_letters_google_drive_path = WWW_ROOT.'rtg_letters/google_drive/' . $member_id . "/" . $client_id ;
$size['rtg_letters_google_drive'] = $size['rtg_letters_google_drive'] + $this->checkDirectoryAndDelete($rtg_letters_google_drive_path);
$total_size = $total_size + $size['rtg_letters_google_drive'];
//rtg_letters/letterstream/<member-id>/<client-id>
$rtg_letters_letterstream_path = WWW_ROOT.'rtg_letters/letterstream/' . $member_id . "/" . $client_id ;
$size['rtg_letters_letterstream'] = $size['rtg_letters_letterstream'] + $this->checkDirectoryAndDelete($rtg_letters_letterstream_path);
$total_size = $total_size + $size['rtg_letters_letterstream'];
//rtg_letters/ringcentral/<member-id>/<client-id>
$rtg_letters_ringcentral_path = WWW_ROOT.'rtg_letters/ringcentral/' . $member_id . "/" . $client_id ;
$size['rtg_letters_ringcentral'] = $size['rtg_letters_ringcentral'] + $this->checkDirectoryAndDelete($rtg_letters_ringcentral_path);
$total_size = $total_size + $size['rtg_letters_ringcentral'];
//rtg_letters/zapier/<member-id>/<client-id>
$rtg_letters_zapier_path = WWW_ROOT.'rtg_letters/zapier/' . $member_id . "/" . $client_id ;
$size['rtg_letters_zapier'] = $size['rtg_letters_zapier'] + $this->checkDirectoryAndDelete($rtg_letters_zapier_path);
$total_size = $total_size + $size['rtg_letters_zapier'];
//velocity/<member-id>/<client-id>
$velocity_path = WWW_ROOT.'velocity/' . $member_id . "/" . $client_id ;
$size['velocity'] = $size['velocity'] + $this->checkDirectoryAndDelete($velocity_path);
$total_size = $total_size + $size['velocity'];
//velocity/ringcentral/<member-id>/<client-id>
$velocity_ringcentral_path = WWW_ROOT.'velocity/ringcentral/' . $member_id . "/" . $client_id ;
$size['velocity_ringcentral'] = $size['velocity_ringcentral'] + $this->checkDirectoryAndDelete($velocity_ringcentral_path);
$total_size = $total_size + $size['velocity_ringcentral'];
//velocity/letterstream/<member-id>/<client-id>
$velocity_letterstream_path = WWW_ROOT.'velocity/letterstream/' . $member_id . "/" . $client_id ;
$size['velocity_letterstream'] = $size['velocity_letterstream'] + $this->checkDirectoryAndDelete($velocity_letterstream_path);
$total_size = $total_size + $size['velocity_letterstream'];
$total_file_size = $total_file_size + $total_size;
$client_id_list[] = ['client_id' => $client_id ,'member_id' => $member_id,
'epicvelocity_letter' => $size['epicvelocity_letter'],
'client_agreement_files' => $size['client_agreement_files'],
'contact_photo' => $size['contact_photo'],
'html_content' => $size['html_content'],
'html_history_code' => $size['html_history_code'],
'html_history_code_history_data' => $size['html_history_code_history_data'],
'pdfletters_epic_velocity' => $size['pdfletters_epic_velocity'],
'pdfletters_super_rtg' => $size['pdfletters_super_rtg'],
'pdfletters_velocity' => $size['pdfletters_velocity'],
'pdfletters_zip' => $size['pdfletters_zip'],
'rtg_letters_dropbox' => $size['rtg_letters_dropbox'],
'rtg_letters_google_drive' => $size['rtg_letters_google_drive'],
'rtg_letters_letterstream' => $size['rtg_letters_letterstream'],
'rtg_letters_ringcentral' => $size['rtg_letters_ringcentral'],
'rtg_letters_zapier' => $size['rtg_letters_zapier'],
'velocity' => $size['velocity'], // velocity root
'velocity_ringcentral' => $size['velocity_ringcentral'],
'velocity_letterstream' => $size['velocity_letterstream'],
'total_size' => $total_size];
}
}
$cli_logData['client_ids'] = $client_id_list;
$cli_logData['epicvelocity_letter'] = $size['epicvelocity_letter'];
$cli_logData['client_agreement_files'] = $size['client_agreement_files'];
$cli_logData['contact_photo'] = $size['contact_photo'];
$cli_logData['html_content'] = $size['html_content'];
$cli_logData['html_history_code'] = $size['html_history_code'];
$cli_logData['html_history_code_history_data'] = $size['html_history_code_history_data'];
$cli_logData['pdfletters_epic_velocity'] = $size['pdfletters_epic_velocity'];
$cli_logData['pdfletters_super_rtg'] = $size['pdfletters_super_rtg'];
$cli_logData['pdfletters_velocity'] = $size['pdfletters_velocity'];
$cli_logData['pdfletters_zip'] = $size['pdfletters_zip'];
$cli_logData['rtg_letters_dropbox'] = $size['rtg_letters_dropbox'];
$cli_logData['rtg_letters_google_drive'] = $size['rtg_letters_google_drive'];
$cli_logData['rtg_letters_letterstream'] = $size['rtg_letters_letterstream'];
$cli_logData['rtg_letters_ringcentral'] = $size['rtg_letters_ringcentral'];
$cli_logData['rtg_letters_zapier'] = $size['rtg_letters_zapier'];
$cli_logData['velocity'] = $size['velocity'];
$cli_logData['velocity_ringcentral'] = $size['velocity_ringcentral'];
$cli_logData['velocity_letterstream'] = $size['velocity_letterstream'];
$cli_logData['total_deleted_file_in_bytes'] = $total_file_size;
$this->cronjobLog($cli_logData);
$this->out('Total Deleted File Size In Bytes: '.$total_file_size);
}
function deleteAll($dir) {
if(is_file($dir)){
unlink($dir);
}
if(is_dir($dir)) {
foreach (glob($dir . '/*') as $file) {
if (is_dir($file))
$this->deleteAll($file);
else
unlink($file);
}
rmdir($dir);
}
}
private function checkDirectoryAndDelete($path){
$size = 0;
if(is_file($path) || is_dir($path)){
try {
if(is_file($path)){
$size = filesize($path);
}
if(is_dir($path)){
$size = $this->GetDirectorySize($path);
}
}catch (\Exception $ex){
}
}
// $this->deleteAll($path);
return $size;
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Mailer\Email;
/**
* ClientPasswordChangeEmail shell command.
*/
class ClientPasswordChangeEmailShell extends AppShell
{
public function initialize() {
parent::initialize();
$this->loadModel('Personalizes');
$this->loadModel('Logs');
$this->loadModel('ClientPasswordChangeEmailQueue');
}
/**
* Manage the available sub-commands along with their arguments and help
*
* @see http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = parent::getOptionParser();
return $parser;
}
/**
* main() method.
*
* @return bool|int|null Success or error code.
*/
public function main()
{
$this->out($this->OptionParser->help());
}
public function passwordChangeEmail()
{
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_ClientPasswordChangeEmail_passwordChangeEmail";
$this->cronjobLog($cli_logData);
$clientPasswordChanges = $this->ClientPasswordChangeEmailQueue->find('all')->limit(200)->toArray();
foreach ($clientPasswordChanges as $clientInfo){
$personalize = $this->Personalizes->getPersonalizeByMemberId($clientInfo['auth_id']);
$templateContent = [
'firstname' => $clientInfo->first_name,
'loginurl' => $clientInfo->loginurl,
'user_email' => $clientInfo->user_email,
'password' => $clientInfo->password,
'member_id' => $clientInfo->auth_id,
'client_id' => $clientInfo->client_id
];
$this->sendEmail(MANDRILL_TEMPLATE_USER_CREATION, $templateContent, $clientInfo['user_email'], $clientInfo['subject'], "","", $personalize);
// log for client info & email date whose are changing password
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_ClientPasswordChangeEmail_client_info_and_email_data";
$cli_logData['client_info'] = $clientInfo;
$cli_logData['email_data'] = $templateContent;
$this->cronjobLog($cli_logData);
$this->ClientPasswordChangeEmailQueue->destroy($clientInfo->id);
}
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_ClientPasswordChangeEmail_passwordChangeEmail";
$this->cronjobLog($cli_logData);
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Shell;
use Cake\Console\ConsoleOptionParser;
use Cake\Console\Shell;
use Cake\Log\Log;
use Psy\Shell as PsyShell;
/**
* Simple console wrapper around Psy\Shell.
*/
class ConsoleShell extends AppShell
{
/**
* Start the shell and interactive console.
*
* @return int|void
*/
public function main()
{
if (!class_exists('Psy\Shell')) {
$this->err('<error>Unable to load Psy\Shell.</error>');
$this->err('');
$this->err('Make sure you have installed psysh as a dependency,');
$this->err('and that Psy\Shell is registered in your autoloader.');
$this->err('');
$this->err('If you are using composer run');
$this->err('');
$this->err('<info>$ php composer.phar require --dev psy/psysh</info>');
$this->err('');
return 1;
}
$this->out("You can exit with <info>`CTRL-C`</info> or <info>`exit`</info>");
$this->out('');
Log::drop('debug');
Log::drop('error');
$this->_io->setLoggers(false);
restore_error_handler();
restore_exception_handler();
$psy = new PsyShell();
$psy->run();
}
/**
* Display help for this console.
*
* @return ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = new ConsoleOptionParser('console');
$parser->description(
'This shell provides a REPL that you can use to interact ' .
'with your application in an interactive fashion. You can use ' .
'it to run adhoc queries with your models, or experiment ' .
'and explore the features of CakePHP and your application.' .
"\n\n" .
'You will need to have psysh installed for this Shell to work.'
);
return $parser;
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\ORM\TableRegistry;
/**
* ConvertDbToHTML shell command.
*/
class ConvertDbToHTMLShell extends AppShell {
public function processDD() {
$file_path = "html_content";
$file_path = WWW_ROOT. $file_path;
if (!is_dir($file_path)) {
mkdir($file_path, 0777, true);
}
$dd_entity = TableRegistry::get('data_documents');
$dds = $dd_entity->find('all',array('limit'=>50))->where(['is_process'=>0])->toArray();
if(!empty($dds)){
foreach ($dds as $dd){
$member_id = $dd->cmsuser_id;
$client_id = $dd->client_id;
$dd_id = $dd->id;
$new_path = $file_path . "/" . $member_id . "/" . $client_id;
if (!is_dir($new_path)) {
mkdir($new_path, 0777, true);
}
$path = $new_path . '/' . $dd_id;
$current_dd = $dd_entity->get($dd_id);
$current_dd->is_process = 1;
$dd_entity->save($current_dd);
if (!empty($dd->html_content)) {
$this->fileWrite($path, $dd->html_content);
}
}
}
//count
}
public function processhtmlHistory() {
$file_path = "html_history_code";
$file_path = WWW_ROOT. $file_path;
if (!is_dir($file_path)) {
mkdir($file_path, 0777, true);
}
$dd_entity = TableRegistry::get('html_code_histories');
$dds = $dd_entity->find('all',array('limit'=>50))->where(['is_process'=>0])->toArray();
if(!empty($dds)){
foreach ($dds as $dd){
$member_id = $dd->member_id;
$client_id = $dd->client_id;
$dd_id = $dd->id;
$new_path = $file_path . "/" . $member_id . "/" . $client_id;
if (!is_dir($new_path)) {
mkdir($new_path, 0777, true);
}
$path = $new_path . '/' . $dd_id;
$current_dd = $dd_entity->get($dd_id);
$current_dd->is_process = 1;
$dd_entity->save($current_dd);
if (!empty($dd->code)) {
$this->fileWrite($path, $dd->code);
}
}
}
//count
}
function fileWrite($file_name, $content) {
//file_put_contents($file_name.".", $current);
try {
//$pattern = "/<script[^>]*>(?:(?!<\/script>)[^])*<\/script>/g";
//$content = preg_replace($pattern, "", $content);
$file = fopen($file_name . ".html", "w+");
fwrite($file, utf8_encode($content));
fclose($file);
} catch (Exception $e) {
}
}
}

View File

@@ -0,0 +1,206 @@
<?php
namespace App\Shell;
use App\Utility\ManageLog;
use Cake\Log\Log;
class DatabaseCleaningShell extends AppShell {
public function initialize() {
$this->loadModel('Cmsusers');
$this->loadModel('AutomationSchedules');
}
public function main() {
$this->out('Start');
ManageLog::getQueryLog('DatabaseCleaning');
$this->resourceDeleteOfInactiveMember();
$this->out('Cleaning completed');
$this->out('End');
}
private function GetDirectorySize($path){
$bytestotal = 0;
$path = realpath($path);
if($path!==false && $path!='' && file_exists($path)){
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
function deleteAll($dir) {
if(is_file($dir)){
unlink($dir);
}
if(is_dir($dir)) {
foreach (glob($dir . '/*') as $file) {
if (is_dir($file))
$this->deleteAll($file);
else
unlink($file);
}
rmdir($dir);
}
}
private function checkDirectoryAndDelete($path){
$size = 0;
if(is_file($path) || is_dir($path)){
try {
if(is_file($path)){
$size = filesize($path);
}
if(is_dir($path)){
$size = $this->GetDirectorySize($path);
}
}catch (\Exception $ex){
}
}
$this->deleteAll($path);
return $size;
}
private function resourceDeleteOfInactiveMember(){
$cli_logData['action'] = "DELETE_INACTIVE_MEMBER_LAST_SIX_MONTHS_TOTAL_FILE_SIZE_IN_BYTES";
// $this->cronjobLog($cli_logData);
$total_file_size = 0;
$size['epicvelocity_letter_atachments'] = 0;
$size['epicvelocity_clients_docs'] = 0;
$size['html_content'] = 0;
$size['html_history_code'] = 0;
$size['pdfletters'] = 0;
$size['velocity'] = 0;
$size['sertg_attachment'] = 0;
$cmsusers = $this->Cmsusers->find()
->where(['is_active'=>0])
// ->where(['id'=>2163])
->where('DATEDIFF(CURDATE(),last_login_date) >'. 183)
->toArray();
/*
$cmsusers = $this->Cmsusers->find()
->join([
'table' => 'cmsuser_usergroups',
'alias' => 'CU',
'type' => 'LEFT',
'conditions' => 'CU.cms_user_id = Cmsusers.id'
])
->select([
'Cmsusers.id', 'Cmsusers.username', 'Cmsusers.stripe_customer_id',
'Cmsusers.email', 'Cmsusers.created_on', 'CU.usergroup_id',
'CU.cms_user_id', 'Cmsusers.Phone', 'Cmsusers.status',
'Cmsusers.created_on', 'Cmsusers.is_allow_defult_pass'
])
->distinct(['Cmsusers.id'])
->where([
'Cmsusers.is_active NOT IN' => DELETED_MEMBER_STATUS,
'DATEDIFF(CURDATE(),Cmsusers.last_login_date) >'. 183,
'CU.usergroup_id' => CUSTOMER_USER_GROUP_ID
])
->toArray();
*/
// dd($cmsusers);
$this->loadModel('LetterExtras');
$this->loadModel('Sertg');
$this->loadModel('SertgAttachment');
$member_id_list = [];
if(!empty($cmsusers)) {
foreach ($cmsusers as $cmsuser) {
// $cli_logData['action'] = "Delete File For Member Id ".$cmsuser->id;
$member_id_list[] = $cmsuser->id;
if(empty($cmsuser)){
continue;
}
$cmsuser->is_active = 3; // is_active 3 -- is deleted from db
$this->Cmsusers->save($cmsuser);
$letterExtras = $this->LetterExtras->find()->where(['cmsuser_id'=>$cmsuser->id])->toArray();
$letter_extra_size['attachment'] = 0;
$letter_extra_size['clients_docs'] = 0;
if(!empty($letterExtras)) {
// epicvelocity/letters/attachment/letter_attachtment_images
$letter_path = WWW_ROOT . "epicvelocity/letters/attachment/" . $cmsuser->id;
$letter_extra_size['attachment'] = $letter_extra_size['attachment'] + $this->checkDirectoryAndDelete($letter_path);
foreach ($letterExtras as $letterExtra) {
//epicvelocity/clients_docs/html_file_path
if (!empty($letterExtra->html_file_path)) {
$letter_html_path = WWW_ROOT . "epicvelocity/clients_docs/" . $letterExtra->html_file_path;
$letter_extra_size['clients_docs'] = $letter_extra_size['clients_docs'] + $this->checkDirectoryAndDelete($letter_html_path);
}
}
}
$size['epicvelocity_letter_atachments'] = $size['epicvelocity_letter_atachments'] + $letter_extra_size['attachment'];
$size['epicvelocity_clients_docs'] = $size['epicvelocity_clients_docs'] + $letter_extra_size['clients_docs'];
//html_content/<member-id>
$size['html_content'] = $size['html_content'] + $this->checkDirectoryAndDelete(WWW_ROOT."html_content/".$cmsuser->id);
//html_history_code/<member-id>
$size['html_history_code'] = $size['html_history_code'] + $this->checkDirectoryAndDelete(WWW_ROOT."html_history_code/".$cmsuser->id);
//html_history_code/history_data/<member-id>
$size['html_history_code'] = $size['html_history_code'] + $this->checkDirectoryAndDelete(WWW_ROOT."html_history_code/history_data/".$cmsuser->id);
//pdfletters/Epic Velocity/<member-id>
$size['pdfletters'] = $size['pdfletters'] + $this->checkDirectoryAndDelete(WWW_ROOT."pdfletters/Epic Velocity/".$cmsuser->id);
//pdfletters/Super RTG/<member-id>
$size['pdfletters'] = $size['pdfletters'] + $this->checkDirectoryAndDelete(WWW_ROOT."pdfletters/Super RTG/".$cmsuser->id);
//pdfletters/Velocity/<member-id>
$size['pdfletters'] = $size['pdfletters'] + $this->checkDirectoryAndDelete(WWW_ROOT."pdfletters/Velocity/".$cmsuser->id);
//pdfletters/zip/<member-id>
$size['pdfletters'] = $size['pdfletters'] + $this->checkDirectoryAndDelete(WWW_ROOT."pdfletters/zip/".$cmsuser->id);
//velocity/<member-id>
$size['velocity'] = $size['velocity'] + $this->checkDirectoryAndDelete(WWW_ROOT."velocity/".$cmsuser->id);
//velocity/ringcentral/<member-id> => 57G
$size['velocity'] = $size['velocity'] + $this->checkDirectoryAndDelete(WWW_ROOT."velocity/ringcentral/".$cmsuser->id);
//velocity/letterstream/<member-id>
$size['velocity'] = $size['velocity'] + $this->checkDirectoryAndDelete(WWW_ROOT."velocity/letterstream/".$cmsuser->id);
}
}
foreach ($size as $s){
$total_file_size = $total_file_size + $s;
}
$cli_logData['member_ids'] = $member_id_list;
$cli_logData['epicvelocity_letter_atachments_size'] = $size['epicvelocity_letter_atachments'];
$cli_logData['epicvelocity_clients_docs_size'] = $size['epicvelocity_clients_docs'];
$cli_logData['html_content_size'] = $size['html_content'];
$cli_logData['html_history_code_size'] = $size['html_history_code'];
$cli_logData['pdfletters_size'] = $size['pdfletters'];
$cli_logData['velocity_size'] = $size['velocity'];
$cli_logData['total_deleted_file_in_bytes'] = $total_file_size;
$this->cronjobLog($cli_logData);
$this->out('Total Deleted File Size In Bytes: '.$total_file_size);
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Mailer\Email;
use Cake\Network\Exception\SocketException;
use Cake\ORM\TableRegistry;
use Cake\Cache\Cache;
use App\Utility\SmtpCheck;
use Cake\View\View;
use App\Utility\RedisCache;
/**
* EmailSender shell command.
*/
class EmailSenderShell extends AppShell
{
/**
* Gets the option parser instance and configures it.
*
* By overriding this method you can configure the ConsoleOptionParser before returning it.
*
* @return \Cake\Console\ConsoleOptionParser
* @link https://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*/
public function getOptionParser()
{
$parser = parent::getOptionParser();
$parser
->setDescription('Sends queued emails in a batch')
->addOption(
'limit',
[
'short' => 'l',
'help' => 'How many emails should be sent in this batch?',
'default' => 50,
]
)
->addOption(
'template',
[
'short' => 't',
'help' => 'Name of the template to be used to render email',
'default' => 'default',
]
)
->addOption(
'layout',
[
'short' => 'w',
'help' => 'Name of the layout to be used to wrap template',
'default' => 'default',
]
)
->addOption(
'stagger',
[
'short' => 's',
'help' => 'Seconds to maximum wait randomly before proceeding (useful for parallel executions)',
'default' => false,
]
)
->addOption(
'config',
[
'short' => 'c',
'help' => 'Name of email settings to use as defined in email.php',
'default' => 'default',
]
)
->addSubCommand(
'clearLocks',
[
'help' => 'Clears all locked emails in the queue, useful for recovering from crashes',
]
);
return $parser;
}
private function allPersonalizeEmail()
{
return Cache::remember('personalizes', function () {
return TableRegistry::get('personalizes')->getAllPersonalizeEmails();
});
}
/**
* Sends queued emails.
*
* @return void
*/
public function main()
{
$max_email_per_min = 10;
$totalItem = RedisCache::totalItem('cake_email_queue');
if($totalItem == 0){
return false;
}
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_EAMIL_QUEUE_SENDING_EMAIL";
$this->cronjobLog($cli_logData);
$personalizeEmails = $this->allPersonalizeEmail();
if($totalItem < $max_email_per_min){
$max_email_per_min = $totalItem;
}
for($i = 1; $i <= $max_email_per_min; $i++){
$e = RedisCache::pop('cake_email_queue');
if(!$e){
return false;
}
$viewVars = empty($e['template_vars']) ? [] : $e['template_vars'];
$smtpcheck = new SmtpCheck();
$sent = $smtpcheck->prepareEmail($personalizeEmails, $e,0);
if ($sent) {
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_QUEUE_EAMIL_SENT_SUCCESSFULLY";
$cli_logData['data'] = $e;
$this->cronjobLog($cli_logData);
$this->out('<success>Email was sent</success>');
} else {
$data = $viewVars;
$options['member_id'] = $e['member_id'] > 0 ? $e['member_id'] : 0;
$options['from_name'] = $e['from_name'];
$options['from_email'] = $e['from_email'];
$options['subject'] = $e['subject'];
$options['template'] = $e['template'];
$options['format'] = $e['format'];
$options['attachments'] = $e['attachments'];
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_QUEUE_EAMIL_SENT_FAILED";
$cli_logData['data'] = $data;
$this->cronjobLog($cli_logData);
$this->out('<error>Email was not sent</error>');
}
}
}
private function removeFromCacheByIndex($index){
$all_queue_emails = Cache::read('email_queue');
if(isset($all_queue_emails[$index])){
unset($all_queue_emails[$index]);
}
if(!empty($all_queue_emails)){
Cache::write('email_queue',$all_queue_emails);
}else{
Cache::delete('email_queue');
}
}
/**
* Clears all locked emails in the queue, useful for recovering from crashes.
*
* @return void
*/
public function clearLocks()
{
TableRegistry::get('EmailQueue')->clearLocks();
}
/**
* Returns a new instance of CakeEmail.
*
* @param array $config array of configs, or string to load configs from app.php
* @return Email
*/
protected function _newEmail($config)
{
return new Email($config);
}
protected function sendCustomEmail($personalize){
$APP_SMTP_USERNAME = APP_SMTP_USERNAME;
$APP_SMTP_FROM_NAME = APP_SMTP_FROM_NAME;
$APP_SMTP_HOST = APP_SMTP_HOST;
$APP_SMTP_PORT = APP_SMTP_PORT;
$APP_SMTP_PASSWORD = APP_SMTP_PASSWORD;
if (!empty($personalize) && $personalize['is_smtp'] == 1) {
$APP_SMTP_USERNAME = $personalize['username'];
$APP_SMTP_FROM_NAME = $personalize['smtp_from'];
$APP_SMTP_HOST = $personalize['smtp_host'];
$APP_SMTP_PORT = $personalize['smtp_port'];
$APP_SMTP_PASSWORD = $personalize['password'];
}
$default = [
'className' => 'Smtp',
'host' => $APP_SMTP_HOST,
'port' => $APP_SMTP_PORT,
//'timeout' => $APP_SMTP_TIMEOUT,
'username' => $APP_SMTP_USERNAME,
'password' => $APP_SMTP_PASSWORD,
//'tls' => $APP_SMTP_IS_TLS,
'tls' => true,
//'log'=> true
];
return $default;
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
use App\Utility\PaymentApi;
use App\Helper\commonLogic;
/**
* InvoicePayment shell command.
*/
class InvoicePaymentShell extends AppShell {
/**
* Manage the available sub-commands along with their arguments and help
*
* @see http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*
* @return \Cake\Console\ConsoleOptionParser
*/
//bin/cake InvoicePayment processRecurringPayments
public function processRecurringPayments() {
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_InvoicePayment_processRecurringPayments";
$this->cronjobLog($cli_logData);
$this->loadModel("Invoice");
$this->loadModel("Payments");
$current_dateTime = $this->getSystemCurrentTimeStamp();
$invoices = $this->Invoice->getRecurringInvoices();
$commonLogic = new commonLogic();
if (!empty($invoices)) {
foreach ($invoices as $invoice) {
$is_payment_process = 0;
// log for every recurring invoice info
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_recurring_invoice_info";
$cli_logData['invoice_data'] = $invoice;
$this->cronjobLog($cli_logData);
if (!empty($invoice->payment_end_date) && strtotime($invoice->payment_end_date) < strtotime($current_dateTime)) {
continue;
}
$cmsuser_id = $invoice->cmsuser_id;
$payment_subscription_id = $invoice->payment_subscription_id;
//commonLogic
if($invoice->subscription_type == 2){
// GET user credential from payments table
$credentials = $this->Payments->getPaymentSetupByMemberIdAndType($cmsuser_id, AUTHORIZE_DOT_NET_TYPE);
// API CALL for authentication & subscription
$pamentApi = new PaymentApi($credentials['credentials']['api_login_id'], $credentials['credentials']['transaction_key']);
$paymentList = $pamentApi->getSubscription($payment_subscription_id, $cmsuser_id);
// process payment
$this->processPayments($paymentList, $invoice);
}else if($invoice->subscription_type == 3){
$template_content = $commonLogic->sendInvoiceEmail($invoice->id);
}else if($invoice->subscription_type == 4){ // for one time invoice
$is_payment_process = 1;
$commonLogic->sendInvoiceEmail($invoice->id);
}
//update next_action date by subscription info
$this->Invoice->updateNextActionDate($invoice->id, $invoice->next_action_date, json_decode($invoice->subcription_data, true),$is_payment_process);
}
}
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_InvoicePayment_processRecurringPayments";
$this->cronjobLog($cli_logData);
}
private function processPayments($paymentList, $invoice) {
$this->loadModel('InvoicePaymentStatus');
if (!empty($paymentList)) {
$payment_subscription_id = $invoice->payment_subscription_id;
$invoice_payment_statusdata['amount'] = $invoice->sum;
$invoice_payment_statusdata['currency'] = $invoice->currency;
$invoice_payment_statusdata['member_id'] = $invoice->cmsuser_id;
$invoice_payment_statusdata['client_id'] = $invoice->client_id;
$invoice_payment_statusdata['invoice_id'] = $invoice->id;
$invoice_payment_statusdata['is_recurring'] = 1;
$invoice_payment_statusdata['subscription_id'] = $payment_subscription_id;
$invoice_payment_statusdata['action_date'] = $invoice->next_action_date;
//get all existing transactions of this subscription id
$dbTransactionList = $this->InvoicePaymentStatus->getTransactionIdListBySubscriptionId($payment_subscription_id);
foreach ($paymentList as $payment) {
$trans_id = $payment->getTransId(); // transaction id status from api
if (!in_array($trans_id, $dbTransactionList)) {
$trans_status = $payment->getResponse(); // transaction status from api
//insert new record in payment status tbl
$invoice_payment_statusdata['status'] = 0;
if (strtoupper($trans_status) == strtoupper("This transaction has been approved.")) {
$invoice_payment_statusdata['status'] = 1;
}
$invoice_payment_statusdata['transaction_id'] = $trans_id;
$this->InvoicePaymentStatus->insertInvoicePaymentStatus($invoice_payment_statusdata);
}
}
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Shell;
use App\Utility\ManageLog;
use App\View\Helper\CommonHelper;
use Cake\Datasource\ConnectionManager;
use Cake\Log\Log;
class LogsCleaningShell extends AppShell {
public function initialize() {}
public function main() {
$this->out('Start');
$this->logCleaning();
$this->out('Cleaning completed');
$this->out('End');
}
private function logCleaning() {
$cli_logData['action'] = "DELETED_LOG_FILES_FROM_15_DAYS_AGO_AND_FILE_SIZE_IN_BYTES";
$logDirectory = LOGS; // Path to logs directory
$main_interval = TOTAL_DAYS;
$total_file_delete_at_a_time = TOTAL_FILE_DELETE_AT_A_TIME;
$fileSize = 0;
$deleteFileCount = 0;
// Get current time and time 15 days ago
$currentDateTime = date('Y-m-d');
$fifteenDaysAgo = date('Y-m-d', strtotime('-15 days'));
// Get list of log files
$files = scandir($logDirectory);
// Iterate through each file
foreach ($files as $file) {
// Check if it's a log file
if ((strpos($file, '.log') !== false) && ($deleteFileCount>=0 && $deleteFileCount<$total_file_delete_at_a_time)) {
$filePath = $logDirectory . DS . $file;
$fileCreationTime = date('Y-m-d',filemtime($filePath)); // Get file creation time
$interval = $this->dateDiffInDays($currentDateTime,$fileCreationTime);
// Check if file was created exactly 15 days ago
if ($interval>$main_interval && $file != "cli-debug.log") {
// Get the file size
$fileSize = $fileSize + filesize($filePath);
// Remove the file
unlink($filePath);
$deleteFileCount++;
}
}
}
$cli_logData['file_size'] = $fileSize;
$cli_logData['deleted_file_count'] = $deleteFileCount;
$this->cronjobLog($cli_logData);
$this->out('Log cleanup complete.');
}
private function dateDiffInDays($to_date, $from_date) {
$day = 0;
// Calculating the difference in timestamps
$diff = strtotime($from_date) - strtotime($to_date);
// 1 day = 24 hours
// 24 * 60 * 60 = 86400 seconds
$day = abs(round($diff / 86400));
return (int)$day;
}
}

View File

@@ -0,0 +1,399 @@
<?php
namespace App\Shell;
use App\Utility\ManageLog;
use Cake\Log\Log;
class MemberDocumentCleaningShell extends AppShell {
public function initialize() {
$this->loadModel('Cmsusers');
}
public function main() {
$this->out('Start');
// ManageLog::getQueryLog('DatabaseCleaning');
$this->resourceDeleteOfDeletedMember();
$this->out('Cleaning completed');
$this->out('End');
}
private function GetDirectorySize($path){
$bytestotal = 0;
$path = realpath($path);
if($path!==false && $path!='' && file_exists($path)){
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
function deleteAll($dir) {
if(is_file($dir)){
unlink($dir);
}
if(is_dir($dir)) {
foreach (glob($dir . '/*') as $file) {
if (is_dir($file))
$this->deleteAll($file);
else
unlink($file);
}
rmdir($dir);
}
}
private function checkDirectoryAndDelete($path){
$size = 0;
if(is_file($path) || is_dir($path)){
try {
if(is_file($path)){
$size = filesize($path);
}
if(is_dir($path)){
$size = $this->GetDirectorySize($path);
}
}catch (\Exception $ex){
}
}
if(DIRECTORY_DELETE_PERMISSION == 1) {
$this->deleteAll($path);
}
return $size;
}
private function resourceDeleteOfDeletedMember(){
$cli_logData['action'] = "DELETE_DOCUMENTS_OF_DELETED_MEMBER_TOTAL_FILE_SIZE_IN_BYTES";
$total_file_size = 0;
$total_contact_photo = 0;
$total_credit_analysis_pdf = 0;
$total_credit_analysis_template = 0;
$total_email_queue = 0;
$total_media = 0;
$total_member_education_templates = 0;
$total_member_email_attachment = 0;
$total_member_email_template_attachment = 0;
$total_member_email_template_body = 0;
$total_member_help_templates = 0;
$total_epicvelocity_printpdf = 0;
$total_epicvelocity_clients_docs = 0;
$total_epicvelocity_letter = 0;
$total_epicvelocity_letters_account = 0;
$total_epicvelocity_letters_attachment = 0;
$total_rtg_letters_dropbox = 0;
$total_rtg_letters_google_drive = 0;
$total_rtg_letters_letterstream = 0;
$total_rtg_letters_ringcentral = 0;
$total_rtg_letters_zapier = 0;
$cmsusers = $this->Cmsusers->find()
->where(['is_active' => 3 , 'is_deleted'=>0])
->limit(CRONJOB_LIMIT)
->toArray();
/*
$cmsusers = $this->Cmsusers->find()
->join([
'table' => 'cmsuser_usergroups',
'alias' => 'CU',
'type' => 'LEFT',
'conditions' => 'CU.cms_user_id = Cmsusers.id'
])
->select([
'Cmsusers.id', 'Cmsusers.username', 'Cmsusers.stripe_customer_id',
'Cmsusers.email', 'Cmsusers.created_on', 'CU.usergroup_id',
'CU.cms_user_id', 'Cmsusers.Phone', 'Cmsusers.status',
'Cmsusers.created_on', 'Cmsusers.is_allow_defult_pass'
])
->distinct(['Cmsusers.id'])
->where([
'Cmsusers.is_active IN' => DELETED_MEMBER_STATUS,
'Cmsusers.is_deleted' => 0,
'CU.usergroup_id' => CUSTOMER_USER_GROUP_ID
])
->limit(CRONJOB_LIMIT)
->toArray();
*/
$this->loadModel('LetterExtras');
$this->loadModel('Letters');
$member_id_list = [];
if(!empty($cmsusers)) {
foreach ($cmsusers as $cmsuser) {
$size['contact_photo'] = 0;
$size['credit_analysis_pdf'] = 0;
$size['credit_analysis_template'] = 0;
$size['email_queue'] = 0;
$size['media'] = 0;
$size['member_education_templates'] = 0;
$size['member_email_attachment'] = 0;
$size['member_email_template_attachment'] = 0;
$size['member_email_template_body'] = 0;
$size['member_help_templates'] = 0;
$size['epicvelocity_printpdf'] = 0;
$size['epicvelocity_clients_docs'] = 0;
$size['epicvelocity_letter'] = 0;
$size['epicvelocity_letters_account'] = 0;
$size['epicvelocity_letters_attachment'] = 0;
$size['rtg_letters_dropbox'] = 0;
$size['rtg_letters_google_drive'] = 0;
$size['rtg_letters_letterstream'] = 0;
$size['rtg_letters_ringcentral'] = 0;
$size['rtg_letters_zapier'] = 0;
$total_size = 0;
$member_id = $cmsuser->id;
if(empty($cmsuser)){
continue;
}
if(DIRECTORY_DELETE_PERMISSION == 1) {
$cmsuser->is_deleted = 1;
$cmsuser->is_active = 4;
$this->Cmsusers->save($cmsuser);
}
// contact_photo/<client-id
$this->loadModel('Clients');
$total_client = 0;
$clients = $this->Clients->find()
->where(['cmsuser_id'=> $member_id ])
->toArray();
if(!empty($clients)) {
$total_client = count($clients);
foreach ($clients as $client) {
$contact_photo_path = WWW_ROOT . 'contact_photo/' . $client->id;
$size['contact_photo'] = $size['contact_photo'] + $this->checkDirectoryAndDelete($contact_photo_path);
}
}
$total_size = $total_size + $size['contact_photo'];
$total_contact_photo = $total_contact_photo + $size['contact_photo'];
// credit_analysis_pdf/<member-id>
$credit_analysis_pdf_path = WWW_ROOT.'credit_analysis_pdf/' . $member_id ;
$size['credit_analysis_pdf'] = $size['credit_analysis_pdf'] + $this->checkDirectoryAndDelete($credit_analysis_pdf_path);
$total_size = $total_size + $size['credit_analysis_pdf'];
$total_credit_analysis_pdf = $total_credit_analysis_pdf + $size['credit_analysis_pdf'];
// credit_analysis_template/Member/<member-id>
$credit_analysis_template_path = WWW_ROOT.'credit_analysis_template/Member/' . $member_id ;
$size['credit_analysis_template'] = $size['credit_analysis_template'] + $this->checkDirectoryAndDelete($credit_analysis_template_path);
$total_size = $total_size + $size['credit_analysis_template'];
$total_credit_analysis_template = $total_credit_analysis_template + $size['credit_analysis_template'];
//email_queue/<member-id>
$email_queue_path = WWW_ROOT.'email_queue/' . $member_id ;
$size['email_queue'] = $size['email_queue'] + $this->checkDirectoryAndDelete($email_queue_path);
$total_size = $total_size + $size['email_queue'];
$total_email_queue = $total_email_queue + $size['email_queue'];
//media/companies/<member-id>
$media_path = WWW_ROOT.'media/companies/' . $member_id ;
$size['media'] = $size['media'] + $this->checkDirectoryAndDelete($media_path);
$total_size = $total_size + $size['media'];
$total_media = $total_media + $size['media'];
if($total_client > 0){
//member_education_templates/<member-id>
$member_education_templates_path = WWW_ROOT.'member_education_templates/' . $member_id ;
$size['member_education_templates'] = $size['member_education_templates'] + $this->checkDirectoryAndDelete($member_education_templates_path);
$total_size = $total_size + $size['member_education_templates'];
$total_member_education_templates = $total_member_education_templates + $size['member_education_templates'];
//member_email_attachment/<member-id>
$member_email_attachment_path = WWW_ROOT.'member_email_attachment/' . $member_id ;
$size['member_email_attachment'] = $size['member_email_attachment'] + $this->checkDirectoryAndDelete($member_email_attachment_path);
$total_size = $total_size + $size['member_email_attachment'];
$total_member_email_attachment = $total_member_email_attachment + $size['member_email_attachment'];
//member_email_template_attachment/<member-id>
$member_email_template_attachment_path = WWW_ROOT.'member_email_template_attachment/' . $member_id ;
$size['member_email_template_attachment'] = $size['member_email_template_attachment'] + $this->checkDirectoryAndDelete($member_email_template_attachment_path);
$total_size = $total_size + $size['member_email_template_attachment'];
$total_member_email_template_attachment = $total_member_email_template_attachment + $size['member_email_template_attachment'];
//member_email_template_body/<member-id>
$member_email_template_body_path = WWW_ROOT.'member_email_template_body/' . $member_id ;
$size['member_email_template_body'] = $size['member_email_template_body'] + $this->checkDirectoryAndDelete($member_email_template_body_path);
$total_size = $total_size + $size['member_email_template_body'];
$total_member_email_template_body = $total_member_email_template_body + $size['member_email_template_body'];
//member_help_templates/<member-id>
$member_help_templates_path = WWW_ROOT.'member_help_templates/' . $member_id ;
$size['member_help_templates'] = $size['member_help_templates'] + $this->checkDirectoryAndDelete($member_help_templates_path);
$total_size = $total_size + $size['member_help_templates'];
$total_member_help_templates = $total_member_help_templates + $size['member_help_templates'];
}
//epicvelocity/printpdf/<member-id>
$epicvelocity_printpdf_path = WWW_ROOT.'epicvelocity/printpdf/' . $member_id ;
$size['epicvelocity_printpdf'] = $size['epicvelocity_printpdf'] + $this->checkDirectoryAndDelete($epicvelocity_printpdf_path);
$total_size = $total_size + $size['epicvelocity_printpdf'];
$total_epicvelocity_printpdf = $total_epicvelocity_printpdf + $size['epicvelocity_printpdf'];
//epicvelocity/clients_docs/<html_file_path>
$letterExtras = $this->LetterExtras->find()->where(['cmsuser_id' => $member_id])->toArray();
if(!empty($letterExtras)) {
foreach ($letterExtras as $letterExtra) {
if (!empty($letterExtra->html_file_path)) {
$letter_html_path = WWW_ROOT . "epicvelocity/clients_docs/" . $letterExtra->html_file_path;
$size['epicvelocity_clients_docs'] = $size['epicvelocity_clients_docs'] + $this->checkDirectoryAndDelete($letter_html_path);
}
}
}
$total_size = $total_size + $size['epicvelocity_clients_docs'];
$total_epicvelocity_clients_docs = $total_epicvelocity_clients_docs + $size['epicvelocity_clients_docs'];
//epicvelocity/letter/<zip_file>
$letters = $this->Letters->find()->where(['cmsuser_id'=> $member_id ])->toArray();
if(!empty($letters)){
foreach($letters as $letter){
$letter_file = WWW_ROOT."epicvelocity/letters/".$letter->zip_file;
$size['epicvelocity_letter'] = $size['epicvelocity_letter'] + $this->checkDirectoryAndDelete($letter_file);
}
}
$total_size = $total_size + $size['epicvelocity_letter'];
$total_epicvelocity_letter = $total_epicvelocity_letter + $size['epicvelocity_letter'];
// epicvelocity/letters/account/<member-id>
$epicvelocity_letters_account_path = WWW_ROOT.'epicvelocity/letters/account/' . $member_id;
$size['epicvelocity_letters_account'] = $size['epicvelocity_letters_account'] + $this->checkDirectoryAndDelete($epicvelocity_letters_account_path);
$total_size = $total_size + $size['epicvelocity_letters_account'];
$total_epicvelocity_letters_account = $total_epicvelocity_letters_account + $size['epicvelocity_letters_account'];
// epicvelocity/letters/attachment/<member-id>
$epicvelocity_letters_attachment_path = WWW_ROOT.'epicvelocity/letters/attachment/' . $member_id ;
$size['epicvelocity_letters_attachment'] = $size['epicvelocity_letters_attachment'] + $this->checkDirectoryAndDelete($epicvelocity_letters_attachment_path);
$total_size = $total_size + $size['epicvelocity_letters_attachment'];
$total_epicvelocity_letters_attachment = $total_epicvelocity_letters_attachment + $size['epicvelocity_letters_attachment'];
//rtg_letters/dropbox/<member-id>
$rtg_letters_dropbox_path = WWW_ROOT.'rtg_letters/dropbox/' . $member_id ;
$size['rtg_letters_dropbox'] = $size['rtg_letters_dropbox'] + $this->checkDirectoryAndDelete($rtg_letters_dropbox_path);
$total_size = $total_size + $size['rtg_letters_dropbox'];
$total_rtg_letters_dropbox = $total_rtg_letters_dropbox + $size['rtg_letters_dropbox'];
//rtg_letters/google_drive/<member-id>
$rtg_letters_google_drive_path = WWW_ROOT.'rtg_letters/google_drive/' . $member_id ;
$size['rtg_letters_google_drive'] = $size['rtg_letters_google_drive'] + $this->checkDirectoryAndDelete($rtg_letters_google_drive_path);
$total_size = $total_size + $size['rtg_letters_google_drive'];
$total_rtg_letters_google_drive = $total_rtg_letters_google_drive + $size['rtg_letters_google_drive'];
//rtg_letters/letterstream/<member-id>
$rtg_letters_letterstream_path = WWW_ROOT.'rtg_letters/letterstream/' . $member_id ;
$size['rtg_letters_letterstream'] = $size['rtg_letters_letterstream'] + $this->checkDirectoryAndDelete($rtg_letters_letterstream_path);
$total_size = $total_size + $size['rtg_letters_letterstream'];
$total_rtg_letters_letterstream = $total_rtg_letters_letterstream + $size['rtg_letters_letterstream'];
//rtg_letters/ringcentral/<member-id>
$rtg_letters_ringcentral_path = WWW_ROOT.'rtg_letters/ringcentral/' . $member_id ;
$size['rtg_letters_ringcentral'] = $size['rtg_letters_ringcentral'] + $this->checkDirectoryAndDelete($rtg_letters_ringcentral_path);
$total_size = $total_size + $size['rtg_letters_ringcentral'];
$total_rtg_letters_ringcentral = $total_rtg_letters_ringcentral + $size['rtg_letters_ringcentral'];
//rtg_letters/zapier/<member-id>
$rtg_letters_zapier_path = WWW_ROOT.'rtg_letters/zapier/' . $member_id ;
$size['rtg_letters_zapier'] = $size['rtg_letters_zapier'] + $this->checkDirectoryAndDelete($rtg_letters_zapier_path);
$total_size = $total_size + $size['rtg_letters_zapier'];
$total_rtg_letters_zapier = $total_rtg_letters_zapier + $size['rtg_letters_zapier'];
$total_file_size = $total_file_size + $total_size;
$member_id_list[] = ['member_id' => $member_id, 'email' => $cmsuser->email , 'total_client' => $total_client,
'contact_photo' => $size['contact_photo'],
'credit_analysis_pdf' => $size['credit_analysis_pdf'],
'credit_analysis_template' => $size['credit_analysis_template'],
'email_queue' => $size['email_queue'],
'media' => $size['media'],
'member_education_templates' => $size['member_education_templates'],
'member_email_attachment' => $size['member_email_attachment'],
'member_email_template_attachment' => $size['member_email_template_attachment'],
'member_email_template_body' => $size['member_email_template_body'],
'member_help_templates' => $size['member_help_templates'],
'epicvelocity_printpdf' => $size['epicvelocity_printpdf'],
'epicvelocity_clients_docs' => $size['epicvelocity_clients_docs'],
'epicvelocity_letter' => $size['epicvelocity_letter'],
'epicvelocity_letters_account' => $size['epicvelocity_letters_account'],
'epicvelocity_letters_attachment' => $size['epicvelocity_letters_attachment'],
'rtg_letters_dropbox' => $size['rtg_letters_dropbox'],
'rtg_letters_google_drive' => $size['rtg_letters_google_drive'],
'rtg_letters_letterstream' => $size['rtg_letters_letterstream'],
'rtg_letters_ringcentral' => $size['rtg_letters_ringcentral'],
'rtg_letters_zapier' => $size['rtg_letters_zapier'],
'total_size' => $total_size];
}
}
$cli_logData['member_ids'] = $member_id_list;
$cli_logData['contact_photo'] = $total_contact_photo;
$cli_logData['credit_analysis_pdf'] = $total_credit_analysis_pdf;
$cli_logData['email_queue'] = $total_email_queue;
$cli_logData['media'] = $total_media;
$cli_logData['member_education_templates'] = $total_member_education_templates;
$cli_logData['member_email_attachment'] = $total_member_email_attachment;
$cli_logData['member_email_template_attachment'] = $total_member_email_template_attachment;
$cli_logData['member_email_template_body'] = $total_member_email_template_body;
$cli_logData['member_help_templates'] = $total_member_help_templates;
$cli_logData['epicvelocity_printpdf'] = $total_epicvelocity_printpdf;
$cli_logData['epicvelocity_clients_docs'] = $total_epicvelocity_clients_docs;
$cli_logData['epicvelocity_letters'] = $total_epicvelocity_letter;
$cli_logData['epicvelocity_letters_account'] = $total_epicvelocity_letters_account;
$cli_logData['epicvelocity_letters_attachment'] = $total_epicvelocity_letters_attachment;
$cli_logData['rtg_letters_dropbox'] = $total_rtg_letters_dropbox;
$cli_logData['rtg_letters_google_drive'] = $total_rtg_letters_google_drive;
$cli_logData['rtg_letters_letterstream'] = $total_rtg_letters_letterstream;
$cli_logData['rtg_letters_ringcentral'] = $total_rtg_letters_ringcentral;
$cli_logData['rtg_letters_zapier'] = $total_rtg_letters_zapier;
$cli_logData['total_deleted_file_in_bytes'] = $total_file_size;
$this->cronjobLog($cli_logData);
$this->out('Total Deleted File Size In Bytes: '.$total_file_size);
}
}

View File

@@ -0,0 +1,569 @@
<?php
namespace App\Shell;
use Cake\Filesystem\File;
use cake\Filesystem\Folder;
use PhpOffice\PhpSpreadsheet\IOFactory;
class MemberDocumentTransferShell extends AppShell
{
public function initialize()
{
$this->loadModel('Cmsusers');
$this->loadModel('Clients');
$this->loadModel('Letters');
$this->loadModel('LetterExtras');
}
public function main()
{
$this->out('Start');
if(defined('APP_ROOT_TRANSFER') && APP_ROOT_TRANSFER){
$this->resourcesForMember();
}else {
$this->getListOfFiles();
}
$this->out('Resource Transfer Completed');
$this->out('End');
}
private function GetDirectorySize($path)
{
$bytestotal = 0;
$path = realpath($path);
if ($path !== false && $path != '' && file_exists($path)) {
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object) {
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
private function resourcesForMember()
{
$cli_logData['action'] = "MOVE_MEMBER_DOCUMENT";
$total_file_size = 0;
// $spreadsheet = IOFactory::load(WWW_ROOT . 'active_member.xlsx');
// $active_members = $spreadsheet->getActiveSheet()->toArray();
// $active_members = array_slice($active_members, 1);
$active_members = $this->getMember();
$member_logs = array();
foreach ($active_members as $member) {
$file_size = 0;
if (empty($member)) {
continue;
}
$size = [
'agreement_signed_content' => 0,
'agreenment_contents' => 0,
'certificates_pdf' => 0,
'chat_attachment' => 0,
'client_popup_content' => 0,
'client_agreement_files' => 0,
'contact_photo' => 0,
'credit_analysis_pdf' => 0,
'credit_analysis_template' => 0,
'email_queue' => 0, 'media' => 0,
'member_education_templates' => 0,
'member_email_attachment' => 0,
'member_email_template_attachment' => 0,
'member_email_template_body' => 0,
'member_help_templates' => 0,
'html_content' => 0,
'html_history_code' => 0,
'html_history_code_history_data' => 0,
'pdfletters_epic_velocity' => 0,
'pdfletters_super_rtg' => 0,
'pdfletters_velocity' => 0,
'pdfletters_zip' => 0,
'velocity' => 0,
'velocity_ringcentral' => 0,
'velocity_letterstream' => 0,
'epicvelocity_attachment' => 0,
'epicvelocity_printpdf' => 0,
'epicvelocity_letters_account' => 0,
'epicvelocity_letters_attachment' => 0,
'epicvelocity_clients_docs' => 0,
'epicvelocity_letter' => 0,
'rtg_letters_dropbox' => 0,
'rtg_letters_google_drive' => 0,
'rtg_letters_letterstream' => 0,
'rtg_letters_ringcentral' => 0,
'rtg_letters_zapier' => 0];
$cmsuser = $this->Cmsusers->find()
->where(['email' => $member])
->first();
$member_id = $cmsuser->id;
//agreement_signed_content/<member-id>
$size['agreement_signed_content'] = $size['agreement_signed_content'] + $this->transferDirectory('agreement_signed_content/', $member_id);
$file_size = $file_size + $size['agreement_signed_content'];
//agreenment_contents/<member-id>
$size['agreenment_contents'] = $size['agreenment_contents'] + $this->transferDirectory('agreenment_contents/', $member_id);
$file_size = $file_size + $size['agreenment_contents'];
//certificates/pdf/<member-id>
$size['certificates_pdf'] = $size['certificates_pdf'] + $this->transferDirectory('certificates/pdf/', $member_id);
$file_size = $file_size + $size['certificates_pdf'];
//chat_attachment/<member-id>
$size['chat_attachment'] = $size['chat_attachment'] + $this->transferDirectory('chat_attachment/', $member_id);
$file_size = $file_size + $size['chat_attachment'];
// client_agreement_files/<member-id>/
$size['client_agreement_files'] = $size['client_agreement_files'] + $this->transferDirectory('client_agreement_files/', $member_id);
$file_size = $file_size + $size['client_agreement_files'];
// client_popup_content/<member-id>/
$size['client_popup_content'] = $size['client_popup_content'] + $this->transferDirectory('client_popup_content/', $member_id);
$file_size = $file_size + $size['client_popup_content'];
// credit_analysis_pdf/<member-id>
$size['credit_analysis_pdf'] = $size['credit_analysis_pdf'] + $this->transferDirectory('credit_analysis_pdf/', $member_id);
$file_size = $file_size + $size['credit_analysis_pdf'];
// credit_analysis_template/Member/<member-id>
$size['credit_analysis_template'] = $size['credit_analysis_template'] + $this->transferDirectory('credit_analysis_template/Member/', $member_id);
$file_size = $file_size + $size['credit_analysis_template'];
//email_queue/<member-id>
$size['email_queue'] = $size['email_queue'] + $this->transferDirectory('email_queue/', $member_id);
$file_size = $file_size + $size['email_queue'];
//media/companies/<member-id>
$size['media'] = $size['media'] + $this->transferDirectory('media/companies/', $member_id);
$file_size = $file_size + $size['media'];
//member_education_templates/<member-id>
$size['member_education_templates'] = $size['member_education_templates'] + $this->transferDirectory('member_education_templates/', $member_id);
$file_size = $file_size + $size['member_education_templates'];
//member_email_attachment/<member-id>
$size['member_email_attachment'] = $size['member_email_attachment'] + $this->transferDirectory('member_email_attachment/', $member_id);
$file_size = $file_size + $size['member_email_attachment'];
//member_email_template_attachment/<member-id>
$size['member_email_template_attachment'] = $size['member_email_template_attachment'] + $this->transferDirectory('member_email_template_attachment/', $member_id);
$file_size = $file_size + $size['member_email_template_attachment'];
//member_email_template_body/<member-id>
$size['member_email_template_body'] = $size['member_email_template_body'] + $this->transferDirectory('member_email_template_body/', $member_id);
$file_size = $file_size + $size['member_email_template_body'];
//member_help_templates/<member-id>
$size['member_help_templates'] = $size['member_help_templates'] + $this->transferDirectory('member_help_templates/', $member_id);
$file_size = $file_size + $size['member_help_templates'];
//html_content/<member-id>
$size['html_content'] = $size['html_content'] + $this->transferDirectory('html_content/', $member_id);
$file_size = $file_size + $size['html_content'];
//html_history_code/<member-id>
$size['html_history_code'] = $size['html_history_code'] + $this->transferDirectory('html_history_code/', $member_id);
$file_size = $file_size + $size['html_history_code'];
//html_history_code/history_data/<member-id>
$size['html_history_code_history_data'] = $size['html_history_code_history_data'] + $this->transferDirectory('html_history_code/history_data/', $member_id);
$file_size = $file_size + $size['html_history_code_history_data'];
//pdfletters/Epic Velocity/<member-id>
$size['pdfletters_epic_velocity'] = $size['pdfletters_epic_velocity'] + $this->transferDirectory('pdfletters/Epic Velocity/', $member_id);
$file_size = $file_size + $size['pdfletters_epic_velocity'];
//pdfletters/Super RTG/<member-id>
$size['pdfletters_super_rtg'] = $size['pdfletters_super_rtg'] + $this->transferDirectory('pdfletters/Super RTG/', $member_id);
$file_size = $file_size + $size['pdfletters_super_rtg'];
//pdfletters/Velocity/<member-id>
$size['pdfletters_velocity'] = $size['pdfletters_velocity'] + $this->transferDirectory('pdfletters/Velocity/', $member_id);
$file_size = $file_size + $size['pdfletters_super_rtg'];
//pdfletters/zip/<member-id>
$size['pdfletters_zip'] = $size['pdfletters_zip'] + $this->transferDirectory('pdfletters/zip/', $member_id);
$file_size = $file_size + $size['pdfletters_zip'];
//velocity/<member-id>
$size['velocity'] = $size['velocity'] + $this->transferDirectory('velocity/', $member_id);
$file_size = $file_size + $size['velocity'];
//velocity/ringcentral/<member-id>
$size['velocity_ringcentral'] = $size['velocity_ringcentral'] + $this->transferDirectory('velocity/ringcentral/', $member_id);
$file_size = $file_size + $size['velocity_ringcentral'];
//velocity/letterstream/<member-id>
$size['velocity_letterstream'] = $size['velocity_letterstream'] + $this->transferDirectory('velocity/letterstream/', $member_id);
$file_size = $file_size + $size['velocity_letterstream'];
// epicvelocity/letters/attachment/<member-id>/
$size['epicvelocity_attachment'] = $size['epicvelocity_attachment'] + $this->transferDirectory('epicvelocity/letters/attachment/', $member_id);
$file_size = $file_size + $size['epicvelocity_attachment'];
//epicvelocity/printpdf/<member-id>
$size['epicvelocity_printpdf'] = $size['epicvelocity_printpdf'] + $this->transferDirectory('epicvelocity/printpdf/', $member_id);
$file_size = $file_size + $size['epicvelocity_printpdf'];
// epicvelocity/letters/account/<member-id>
$size['epicvelocity_letters_account'] = $size['epicvelocity_letters_account'] + $this->transferDirectory('epicvelocity/letters/account/', $member_id);
$file_size = $file_size + $size['epicvelocity_letters_account'];
//epicvelocity/clients_docs/<html_file_path>
$letterExtras = $this->LetterExtras->find()->where(['cmsuser_id' => $member_id])->toArray();
if (!empty($letterExtras)) {
foreach ($letterExtras as $letterExtra) {
if (!empty($letterExtra->html_file_path)) {
$size['epicvelocity_clients_docs'] = $size['epicvelocity_clients_docs'] + $this->calculateDirectorySize(WWW_ROOT . "epicvelocity/clients_docs/" . $letterExtra->html_file_path);
$this->transferFile('epicvelocity/clients_docs/', $letterExtra->html_file_path);
$file_size = $file_size + $size['epicvelocity_clients_docs'];
}
}
}
//epicvelocity/letter/<zip_file>
$letters = $this->Letters->find()->where(['cmsuser_id' => $member_id])->toArray();
if (!empty($letters)) {
foreach ($letters as $letter) {
$size['epicvelocity_letter'] = $size['epicvelocity_letter'] + $this->calculateDirectorySize(WWW_ROOT . "epicvelocity/letters/" . $letter->zip_file);
$this->transferFile('epicvelocity/letter/', $letter->zip_file);
$file_size = $file_size + $size['epicvelocity_letter'];
}
}
//rtg_letters/dropbox/<member-id>
$size['rtg_letters_dropbox'] = $size['rtg_letters_dropbox'] + $this->transferDirectory('rtg_letters/dropbox/', $member_id);
$file_size = $file_size + $size['rtg_letters_dropbox'];
//rtg_letters/google_drive/<member-id>
$size['rtg_letters_google_drive'] = $size['rtg_letters_google_drive'] + $this->transferDirectory('rtg_letters/google_drive/', $member_id);
$file_size = $file_size + $size['rtg_letters_google_drive'];
//rtg_letters/letterstream/<member-id>
$size['rtg_letters_letterstream'] = $size['rtg_letters_letterstream'] + $this->transferDirectory('rtg_letters/letterstream/', $member_id);
$file_size = $file_size + $size['rtg_letters_letterstream'];
//rtg_letters/ringcentral/<member-id>
$size['rtg_letters_ringcentral'] = $size['rtg_letters_ringcentral'] + $this->transferDirectory('rtg_letters/ringcentral/', $member_id);
$file_size = $file_size + $size['rtg_letters_ringcentral'];
//rtg_letters/zapier/<member-id>
$size['rtg_letters_zapier'] = $size['rtg_letters_zapier'] + $this->transferDirectory('rtg_letters/zapier/', $member_id);
$file_size = $file_size + $size['rtg_letters_zapier'];
$clients = $this->Clients->find()
->where(['cmsuser_id' => $cmsuser->id])
->toArray();
if (!empty($clients)) {
foreach ($clients as $client) {
$client_id = $client->id;
$member_id = $client->cmsuser_id;
if (empty($client)) {
continue;
}
$client->status = 4; // status 4 -- is deleted from db
// $this->Clients->save($client);
// contact_photo/<client-id>
$size['contact_photo'] = $size['contact_photo'] + $this->transferDirectory('contact_photo/', $client_id);
$file_size = $file_size + $size['contact_photo'];
}
}
$total_file_size = $total_file_size + $file_size;
$member_logs[$cmsuser->email] = ['member' => $member_id, 'files' => $size];
}
$cli_logData['data'] = $member_logs;
$cli_logData['total_file_size'] = $total_file_size;
$this->cronjobLog($cli_logData);
$this->out('Total Moved File Size In Bytes: ' . $total_file_size);
}
private function calculateDirectorySize($path)
{
$size = 0;
if (is_file($path) || is_dir($path)) {
try {
if (is_file($path)) {
$size = filesize($path);
}
if (is_dir($path)) {
$size = $this->GetDirectorySize($path);
}
} catch (\Exception $ex) {
}
}
return $size;
}
private function copyFolderContents($sourceFolder, $destinationFolder)
{
$size = 0;
$folder = new Folder($sourceFolder);
[$subfolders, $files] = $folder->read(true, true);
if (!is_dir($destinationFolder)) {
mkdir($destinationFolder, 0755, true);
}
foreach ($files as $file) {
$filePath = $sourceFolder . DS . $file;
$destinationPath = $destinationFolder . DS . $file;
$fileObj = new File($filePath);
$size += $fileObj->size();
if (SERVER == 1) {
$this->serverCommand($filePath, $destinationPath);
} else {
$fileObj->copy($destinationPath);
}
}
foreach ($subfolders as $subfolderName) {
$size += $this->copyFolderContents(
$sourceFolder . DS . $subfolderName,
$destinationFolder . DS . $subfolderName
);
}
return $size;
}
private function transferDirectory($root_dir, $target_dir)
{
if (empty($root_dir) || empty($target_dir)) {
return 0;
}
$source_path = SOURCE_DIRECTORY . $root_dir . DS . $target_dir;
$destination = DESTINATION_DIRECTORY . DS . $root_dir . DS . $target_dir;
if (!is_dir($source_path)) {
return 0;
}
$this->saveFolderPath($root_dir . DS . $target_dir);
return $this->copyFolderContents($source_path, $destination);
}
public function transferFile($dir, $file_name)
{
$message = 'Source file not found.';
$source_path = SOURCE_DIRECTORY . $dir . DS . $file_name;
$destination = DESTINATION_DIRECTORY . DS . $dir;
$destination_path = $destination . DS . $file_name;
$folder = new Folder($destination, true, 0755);
$file = new File($source_path);
if ($file->exists()) {
if (SERVER == 1) {
$this->serverCommand($source_path, $destination_path);
} else {
if ($file->copy($destination_path)) {
$message = 'File transferred successfully.';
} else {
$message = 'Failed to copy the file.';
}
}
}
$this->saveFilePath($dir . DS . $file_name);
return $message;
}
private function getListOfFiles()
{
$cli_logData['action'] = "MOVE_ROOT_DOCUMENT";
$source_dir_path = SOURCE_DIRECTORY;
$destination_dir_path = DESTINATION_DIRECTORY;
$folder = new Folder($source_dir_path);
list($directories, $files) = $folder->read();
new Folder($destination_dir_path, true, 0755);
$file_list = [];
foreach ($files as $key => $file) {
$sourceFile = new File($source_dir_path . $file);
$destinationFilePath = $destination_dir_path . $file;
$sourceFile->copy($destinationFilePath);
$file_list[$file] = ['source' => $destination_dir_path . $file, 'message' => "Done"];
}
$directory_list = [];
foreach ($directories as $key => $directory) {
$transfer = $this->transferFixedFolder($source_dir_path . $directory, $directory);
$directory_list[$directory] = ['destination' => $destination_dir_path . $directory, 'response' => $transfer];
}
$cli_logData['data'] = $directory_list;
$this->cronjobLog($cli_logData);
$this->out('Transfer Completed.');
}
private function transferFixedFolder($dir, $transfer_dir)
{
$transfer = [];
// if (!$this->memberFolderList($transfer_dir)) {
if ($this->webRootFolders($transfer_dir)) {
$source_path = SOURCE_DIRECTORY . DS . $transfer_dir;
$destination = DESTINATION_DIRECTORY . DS . $transfer_dir;
if (!is_dir($source_path)) {
return 0;
}
return $this->copyFolderContents($source_path, $destination);
}
return $transfer;
}
private function memberFolderList($value)
{
$source_dir_name = $value . '/';
$member_folder = ['agreement_signed_content/', 'agreenment_contents/', 'certificates/pdf/', 'chat_attachment/', 'client_agreement_files/',
'agreenment_contents/', 'certificates/', 'chat_attachment/', 'client_agreement_files/', 'client_popup_content/', 'credit_analysis_pdf/',
'credit_analysis_template/Member/', 'email_queue/', 'credit_analysis_template/',
'media/companies/', 'member_education_templates/', 'member_email_attachment/', 'member_email_template_attachment/',
'member_email_template_body/', 'member_help_templates/', "html_content/", "html_history_code/", "html_history_code/history_data/",
"pdfletters/", "pdfletters/Epic Velocity/", "pdfletters/Super RTG/", "pdfletters/Velocity/", "pdfletters/zip/", "velocity/", "velocity/ringcentral/",
"velocity/letterstream/", "epicvelocity/", "epicvelocity/letters/attachment/", 'rtg_letters/dropbox/', 'rtg_letters/google_drive/', 'rtg_letters/', 'rtg_letters/letterstream/',
'rtg_letters/ringcentral/', 'rtg_letters/zapier/', 'contact_photo/', 'epicvelocity/letter/', 'epicvelocity/clients_docs/'];
return in_array($source_dir_name, $member_folder);
}
private function serverCommand($source, $destination)
{
$command = "rsync -avz $source $destination";
exec($command, $output, $return_var);
}
private function saveFolderPath($path){
$fileName = 'folder_paths.txt';
$filePath = WWW_ROOT . DS . $fileName;
file_put_contents($filePath, $path. PHP_EOL, FILE_APPEND);
}
private function saveFilePath($path){
$fileName = 'file_paths.txt';
$filePath = WWW_ROOT . DS . $fileName;
file_put_contents($filePath, $path. PHP_EOL, FILE_APPEND);
}
private function webRootFolders($value)
{
$source_dir_name = $value . '/';
$webroot_folder = [
'AdminAccountImage/',
'GuestForms/',
'REST-Client/',
'RTG/',
'Redis/',
'V1.0/',
'V2.0/',
'V3.0/',
'admin_lte/',
'admin_RTG/',
'api/',
'attach-documents/',
'bootstrap/',
'build/',
'cmsuser_logo/',
'credit_analysis_default/',
'compiles/',
'cronjob/',
'css/',
'datepicker/',
'dist/',
'dropbox/',
'fonts/',
'forum/',
'images/',
'invoice-logo/',
'js/',
'loading/',
'magnify/',
'mpdf60/',
'new_layout/',
'payment_vendor/',
'pie-semi-chart/',
'plugins/',
'project-media-files/',
'rtgv3/',
'tshirts/',
'zapier/',
'user-photo/'
];
return in_array($source_dir_name, $webroot_folder);
}
private function getMember()
{
$emails = [
'tmoment09@gmail.com',
'tagee52283@aol.com',
'ashantitreasures@gmail.com',
'consumerresourcesolutions@gmail.com',
'carlos.montes33@gmail.com',
'bdawson92073@gmail.com',
'davidmauime@gmail.com',
'foster23jordan@gmail.com',
'kashem2003@gmail.com',
'dmiddleton@sagecredit-business.com',
'christine.dunn22@gmail.com',
'credithackerjim@gmail.com',
'aphifer2@aol.com',
'kevindbaskerville1@gmail.com',
'abrafinancialgroup@gmail.com',
'Barbra.gray@yahoo.com',
'dan@danhollis.com',
'brijetjordan@yahoo.com',
'carmansmith5@gmail.com',
'johnniesmith99@gmail.com',
'karenforbes2020@gmail.com',
'roguewesley@gmail.com',
'customerservice@eanddcreditconsultant.com',
'sau.tagaloa@gmail.com',
'tony@tonyscreditrepair.com',
'cpsjerry@gmail.com',
'2123inna@gmail.com',
'ARICBOST@GMAIL.COM',
'info@upgradefinancialservices.com',
'Don_millions@yahoo.com',
'dinah@dbeverly.com',
'wvalerie@swbell.net',
'maurice@gattenterprises.com',
'karinaferrer@creditrepairreno.com',
'support@m2cacademy.com',
'jesse@coachjmiller.com',
];
return $emails;
}
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* Created by PhpStorm.
* User: rsi
* Date: 08-Feb-16
* Time: 9:30 PM
*/
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\Mailer\Email;
use Stripe;
use DateTime;
use App\Utility\createDirZip;
use Kunnu\Dropbox\DropboxApp;
use Kunnu\Dropbox\DropboxFile;
use Kunnu\Dropbox\Dropbox;
//App::import('Controller', 'Registration');
class ProcessBackupShell extends AppShell {
public function initialize() {
parent::initialize();
$this->loadModel('Cmsusers');
$this->loadModel('Usergroups');
$this->loadModel('CmsuserUsergroups');
}
public function dropboxBackup() {
require WWW_ROOT.'/dropbox/vendor/autoload.php';
ini_set('max_execution_time', 6000);
ini_set('memory_limit', '1024M');
ini_set('upload_max_filesize', '256M');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$to = "rajibcuetcse@gmail.com";
$day = date("d");
$month = date("F");
$year = date("Y");
$time = date("h:i A");
$current_date = $day . "-" . $month . " " . $time . " GMT +6";
//$this->
//setting dropbox credentials
$token = DROPBOX_TOKEN;
$clientId = DROPBOX_CLIENT_ID;
$clientSecret = DROPBOX_CLIENT_SECRET;
$app = new DropboxApp($clientId, $clientSecret, $token);
$dropbox = new Dropbox($app);
if ($dropbox) {
$projectFolder = $month . "," . "$year" . "/" . $day . "-" . $month . " " . $time . " GMT +6";
$new_zip_file_name = "backup_" . $day . "_" . $month . "_" . $year . ".zip";
$src_file = WWW_ROOT."/dropbox/".$new_zip_file_name;
$file_path = __DIR__.'/../../../'.PROJECT_DIR_NAME;
$dropbox_dir = WWW_ROOT."dropbox";
$this->deleteZipAndSqlFiles($dropbox_dir);
$createZip = new createDirZip();
$createZip->testZip($file_path, $src_file);
// $zipfile = $this->testZip($file_path, $src_file);
//$zipfile = $this->zipData($file_path, $src_file);
// echo $zipfile;exit;
$database = APP_DB_DATABASE_NAME;
$user = APP_DB_USERNAME;
$pass = APP_DB_PASSWORD;
$host = APP_DB_HOST;
$templateName = 'project_backup_email';
$db_file = "rtg_" . $day . "_" . $month . "_" . $year . ".sql";
$exe_db_file = $dropbox_dir."/".$db_file;
exec("mysqldump --user={$user} --password={$pass} --host={$host} {$database} --result-file={$exe_db_file} 2>&1", $output);
if (file_exists($src_file) && file_exists($exe_db_file)) {
try{
$src_path = $src_file;
$dpx_src_path = "/" . $projectFolder . "/" . $new_zip_file_name;
//echo $dpx_src_path;exit;
$dropboxFile = new DropboxFile($src_path);
$file = $dropbox->upload($dropboxFile, $dpx_src_path, ['autorename' => false]);
$db_path = $exe_db_file;
$dpx_db_path = "/" . $projectFolder . "/" . $db_file;
$dropboxDbFile = new DropboxFile($db_path);
$file = $dropbox->upload($dropboxDbFile, $dpx_db_path, ['autorename' => false]);
if ($file) {
echo "upload successfull";
@unlink($src_file);
@unlink($db_path);
$subject = "RTG Backup success";
$templateContent['description'] = "RTG Backup successfull on ".$current_date;
}else{
$subject = "RTG Backup failed";
$templateContent['description'] = "RTG Backup failed to send on dropbox at ".$current_date;
}
$this->sendEmail($templateName, $templateContent, $to, $subject);
}catch(\Exception $e){
$subject = "RTG Backup failed";
$templateContent['description'] = "RTG Backup failed on ".$current_date;
$templateContent['description'] .= "<br/>";
$templateContent['description'] .= $e->getMessage();
$this->sendEmail($templateName, $templateContent, $to, $subject);
echo '<pre>';print_r($e->getMessage());
}
}else{
echo "project zip or sql file not created.";exit;
}
} else {
echo "Your given dropbox credentials are wrong";exit;
}
$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "dropboxBackup","dropboxBackup");
}
private function zipData($source, $destination) {
if (extension_loaded('zip')) {
if (file_exists($source)) {
$zip = new \ZipArchive();
if ($zip->open($destination, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
$source = realpath($source);
if (is_dir($source)) {
$iterator = new \RecursiveDirectoryIterator($source);
// skip dot files while iterating
$iterator->setFlags(\RecursiveDirectoryIterator::SKIP_DOTS);
$files = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = realpath($file);
if (is_dir($file)) {
//echo $source . '/'."======".$file . '/'."===========".str_replace($source . '/', '', $file . '/');exit;
$zip->addEmptyDir(str_replace($source . '/', '', basename($file) . '/'));
} else if (is_file($file)) {
$zip->addFile($file, str_replace($source . '/', '', basename($file)));
}
}
} else if (is_file($source)) {
$zip->addFromString(basename($source), file_get_contents($source));
}
}
return $zip->close();
}
}
return false;
}
private function deleteZipAndSqlFiles($dir){
$zipfiles = glob($dir."/*.zip");
$sqlfiles = glob($dir."/*.sql");
if(!empty($zipfiles)){
foreach($zipfiles as $zip){
@unlink($zip);
}
}
if(!empty($sqlfiles)){
foreach($sqlfiles as $sql){
@unlink($sql);
}
}
}
}

View File

@@ -0,0 +1,698 @@
<?php
/**
* Created by PhpStorm.
* User: rsi
* Date: 08-Feb-16
* Time: 9:30 PM
*/
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\Mailer\Email;
use Stripe;
use DateTime;
//App::import('Controller', 'Registration');
class ProcessDataShell extends AppShell {
public function initialize() {
parent::initialize();
$this->loadModel('Cmsusers');
$this->loadModel('Usergroups');
$this->loadModel('CmsuserUsergroups');
}
public function preMain($schedule = null)
{
if (!$schedule) {
$this->out();
$this->err('Missing the parameter \'schedule\'');
$this->out('Please set the parameter along with the command.');
$this->out();
$this->out('eg :- backend start pre main "*/60 * * * *"');
$this->out();
$this->out('* * * * *');
$this->out('| | | | |');
$this->out('| | | | |');
$this->out('| | | | \----- day of week (0 - 6) (0 to 6 are Sunday to Saturday,');
$this->out('| | | | or use names)');
$this->out('| | | \---------- month (1 - 12)');
$this->out('| | \--------------- day of month (1 - 31)');
$this->out('| \-------------------- hour (0 - 23)');
$this->out('\------------------------- min (0 - 59)');
$this->out();
$schedule = $this->in('Please pass in the schedule in the above mentioned format');
$this->clear();
}
$schedule = trim($schedule);
if ($this->validateSchedule($schedule)) {
$this->out('Setting up...');
$cron = $schedule . ' ' . USER_COUNTRY_NAME_CODE;
if ($this->cronjobExists(USER_COUNTRY_NAME_CODE)) {
$this->out('Existing backend job found. Removing ...');
$removeCommand = "crontab -l | grep -v '" . USER_COUNTRY_NAME_CODE . "' | crontab -";
shell_exec($removeCommand);
$this->out("Removed existing backend job!");
}
$this->appendCronjob($cron);
$this->out('New backend job added successfully!');
}
}
// */10 * * * cd /var/www/html && bin/cake processData
public function main() {
$this->out('Start');
$plan_id_array = $this->objectToArray(json_decode(RTG_PLAN_ID));
$total_record_processed = 0;
foreach($plan_id_array as $index=>$stripePlanId){
\Stripe\Stripe::setApiKey(APP_STRIPE_SECRET_KEY);
$Subscriptions = \Stripe\Subscription::all(
array(
'limit' => 110, // in the first time, put 5 then 10, 15, 20 etc....till 50
'created' => array(
'gte' => strtotime('-40 min'),
'lte' => strtotime('0 min')
),
//'starting_after' => 'sub_BQdvHBBf8lfjsR',
"plan" => $stripePlanId
)
);
/* echo "<pre>";
print_r( $Subscriptions->__toArray(true));
echo "<br/>"; */
foreach ($Subscriptions->data as $subscription) {
// Do something with $subscription
//$subscription->id
$customerObj = \Stripe\Customer::retrieve($subscription->customer);
$customer = $customerObj->__toArray(true);
//$customer = $customerArray['sources']['data'][0];
$cmsuser = [];
$isRecordExist = $this->checkemail($customer['email']);
if(!$isRecordExist){
//check success subscription in last 50 mins
$successfulCharge = false;
$chargeList = \Stripe\Charge::all(
array(
'limit' => 110, // in the first time, put 5 then 10, 15, 20 etc....till 50
'created' => array(
'gte' => strtotime('-50 min'),
'lte' => strtotime('0 min')
),
"failure_code"=>null,
"customer" => $customer['id']
)
);
foreach ($chargeList->data as $charge) {
// Do something with $subscription
if(empty($charge->failure_code)) {
$successfulCharge = true;
break;
}
}
/* echo "<pre>";
print_r($successfulCharge);exit; */
if($successfulCharge){
$total_record_processed++;
$cmsuser = $this->Cmsusers->newEntity();
$password = rand(100000,999999);
$cmsuser = $this->createUser($cmsuser,["email" => $customer['email'],
"password" => $password,
"address_zip" => "",
"stripe_customer_id" => $customer['id'],
"phone" => "",
"cardholder_name" => "",
"permission_version" => "1",
"ip" => "",
"is_first_login" => "1",
"package_id" => "2",
"img_path" => "",
"username" => $customer['email'],
"language" => "en",
"retype_password" => $password,
]);
$customerName = explode("@",$customer['email']);
if ($this->Cmsusers->save($cmsuser)) {
// add User To User Group
$this->addUserToUserGroup($cmsuser->id, USER_GROUP_ID);
// add User To Default Packages
$this->addUserToPackages($cmsuser->id,PACKAGE_ID);
$this->addUserToPackages($cmsuser->id,PACKAGE_WAVE_1_ID);
$template_content = array(
'firstname' => $customerName[0],
'user_email'=> $customer['email'],
'password' => $password,
'loginurl' => APP_SERVER_HOST_URL
);
//echo "Going to send email to :::".$customer['email'];
$this->sendEmail(MANDRILL_TEMPLATE_USER_CREATION, $template_content, $cmsuser->email);
}else{
// echo "::::::No data added----".$customer['email']."<br>\n";
}
}
}else{
// do nothing
}
}
}
//insert logs into process logs
//$total_record_processed
$this->saveLogs("REG",$total_record_processed);
/* echo "Customer process completed...";
exit; */
$this->out('End');
$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "main","main");
}
private function checkemail($email)
{
$result = false;
$table_Cmsusers = TableRegistry::get("Cmsusers");
$defaultCmsusers = $table_Cmsusers->find('all')
->select(['id','email'])
->where(['Cmsusers.email'=>$email])
->first();
// return $defaultCmsusers;
if(!empty($defaultCmsusers)){
$result = true;
}
return $result;
}
public function checkUserByEmailAndStripeId($email,$stripe_customer_id)
{
$resultId = 0;
if(!empty($email)){
$table_Cmsusers = TableRegistry::get("Cmsusers");
$defaultCmsusers = $table_Cmsusers->find('all')
->select(['id','email'])
->where(['Cmsusers.email'=>$email, 'Cmsusers.stripe_customer_id'=>$stripe_customer_id])
->first();
if(!empty($defaultCmsusers)){
$resultId = $defaultCmsusers->id;
}
}
return $resultId;
}
private function addUserToUserGroup($user_id, $usergroup_id)
{
$table_user_groups_user = TableRegistry::get("CmsuserUsergroups");
$entity = $table_user_groups_user->newEntity();
$entity->cms_user_id = $user_id;
$entity->usergroup_id = $usergroup_id;
if($table_user_groups_user->save($entity)){
return true;
} else {
return false;
}
}
public function addUserToPackages($user_id, $package_id)
{
$table_member_packages = TableRegistry::get("MemberPackages");
$entity = $table_member_packages->newEntity();
$entity->member_id = $user_id;
$entity->package_id = $package_id;
$entity->status = 1;
$entity->created_on = date('Y-m-d h:i:s');
if($table_member_packages->save($entity)){
return true;
} else {
return false;
}
}
private function objectToArray($d) {
if (is_object($d))
$d = get_object_vars($d);
return is_array($d) ? array_map(__METHOD__, $d) : $d;
}
private function saveLogs($process_name,$number_of_record_processed){
$logTable = TableRegistry::get("ProcessLogs");
$entity = $logTable->newEntity();
$entity->process_name = $process_name;
$entity->number_of_record_processed = $number_of_record_processed;
$entity->created_on = date('Y-m-d h:i:s');
$logTable->save($entity);
}
private function saveStripeCustsomerLog($type,$stripe_customer_id){
$logTable = TableRegistry::get("StripeCustomerLogs");
$entity = $logTable->newEntity();
$entity->type = $type;
$entity->stripe_customer_id = $stripe_customer_id;
$entity->activity_datetime = date('Y-m-d h:i:s');
$logTable->save($entity);
}
public function failSubscription() {
$this->out('Start failure');
// $plan_id_array = $this->objectToArray(json_decode(RTG_PLAN_ID));
$total_record_processed = 0;
//if(!empty($plan_id_array)){
// foreach($plan_id_array as $index=>$stripePlanId){
//$this->saveLogs("FS1",$total_record_processed);
\Stripe\Stripe::setApiKey(APP_STRIPE_SECRET_KEY);
// $Subscriptions = \Stripe\Subscription::all(
// array(
// 'limit' => 110, // in the first time, put 5 then 10, 15, 20 etc....till 50
// 'created' => array(
// 'gte' => strtotime('-10 min'),
// 'lte' => strtotime('0 min')
// ),
// // "cancel_at_period_end" => true,
// "plan" => $stripePlanId,
// //'starting_after' => 'sub_BQdvHBBf8lfjsR',
// )
// );
$Subscriptions = \Stripe\Charge::all(
array(
'limit' => 110, // in the first time, put 5 then 10, 15, 20 etc....till 50
'created' => array(
'gte' => strtotime('-15 min'),
'lte' => strtotime('0 min')
)
)
);
foreach ($Subscriptions->data as $subscription) {
// Do something with $subscription
if(!empty($subscription->failure_code)) {
$customerObj = \Stripe\Customer::retrieve($subscription->customer);
$customer = $customerObj->__toArray(true);
$cmsuser = [];
$user_id = $this->checkUserByEmailAndStripeId($customer['email'],$customer['id']);
if(!empty($user_id))
{
$availableCmsUserGroups = $this->CmsuserUsergroups->find('all',[
'conditions'=>[
'CmsuserUsergroups.cms_user_id'=>$user_id,
'CmsuserUsergroups.usergroup_id'=>USER_GROUP_ID
]
]);
if(!empty($availableCmsUserGroups->toArray())){
$total_record_processed++;
$this->CmsuserUsergroups->deleteAll(
[
'CmsuserUsergroups.cms_user_id' => $user_id,
'CmsuserUsergroups.usergroup_id' => USER_GROUP_ID
],
false
);
$this->saveStripeCustsomerLog(1,$customer['id']);
}
}
}
// }
// }
}
//$total_record_processed
$this->saveLogs("FSB",$total_record_processed);
$this->out('End failure');
}
public function successCharge() {
$this->out('Start success');
// $plan_id_array = $this->objectToArray(json_decode(RTG_PLAN_ID));
$total_record_processed = 0;
// if(!empty($plan_id_array)){
// foreach($plan_id_array as $index=>$stripePlanId){
\Stripe\Stripe::setApiKey(APP_STRIPE_SECRET_KEY);
$chargeList = \Stripe\Charge::all(
array(
'limit' => 110, // in the first time, put 5 then 10, 15, 20 etc....till 50
'created' => array(
'gte' => strtotime('-17 min'),
'lte' => strtotime('0 min')
),
"failure_code"=>null,
)
);
foreach ($chargeList->data as $subscription) {
// Do something with $subscription
//$subscription->id
$customerObj = \Stripe\Customer::retrieve($subscription->customer);
$customer = $customerObj->__toArray(true);
//$customer = $customerArray['sources']['data'][0];
$cmsuser = [];
// Check Cmsuser table for this user
$user_id = $this->checkUserByEmailAndStripeId($customer['email'],$customer['id']);
if(!empty($user_id)){
// $this->loadModel('CmsuserUsergroups');
// check user_id in CmsuserUsergroups table
$availableCmsUserGroups = $this->CmsuserUsergroups->find('all',[
'conditions'=>[
'CmsuserUsergroups.cms_user_id'=>$user_id,
'CmsuserUsergroups.usergroup_id'=>USER_GROUP_ID
]
]);
// pr($availableCmsUserGroups); die;
if(empty($availableCmsUserGroups->toArray()))
{
$total_record_processed++;
// add User To User Group
if($this->addUserToUserGroup($user_id, USER_GROUP_ID)){
$template_content = array(
'loginurl' => APP_SERVER_HOST_URL
);
$this->saveStripeCustsomerLog(2,$customer['id']);
//echo "Going to send email to :::".$customer['email'];
$this->sendEmail(MANDRILL_TEMPLATE_USER_REACTIVATION, $template_content, $customer['email']);
}
}
}
}
//}
// }
//$total_record_processed
$this->saveLogs("CRG",$total_record_processed);
$this->out('End success');
$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "successCharge","successCharge");
}
public function checkSubscription(){
$plan_id_array = $this->objectToArray(json_decode(RTG_PLAN_ID));
$total_record_processed = 0;
foreach($plan_id_array as $index=>$stripePlanId){
\Stripe\Stripe::setApiKey(APP_STRIPE_SECRET_KEY);
$Subscriptions = \Stripe\Subscription::all(
array(
'limit' => 110, // in the first time, put 5 then 10, 15, 20 etc....till 50
'created' => array(
'gte' => strtotime('-25 min'),
'lte' => strtotime('0 min')
),
//'starting_after' => 'sub_BQdvHBBf8lfjsR',
"plan" => $stripePlanId
)
);
/* echo "<pre>";
print_r( $Subscriptions->__toArray(true));
echo "<br/>"; */
foreach ($Subscriptions->data as $subscription) {
// Do something with $subscription
//$subscription->id
$customerObj = \Stripe\Customer::retrieve($subscription->customer);
$customer = $customerObj->__toArray(true);
//$customer = $customerArray['sources']['data'][0];
$cmsuser = [];
$isRecordExist = $this->checkemail($customer['email']);
if(!$isRecordExist){
$total_record_processed++;
$cmsuser = $this->Cmsusers->newEntity();
$password = rand(100000,999999);
$cmsuser = $this->createUser($cmsuser,["email" => $customer['email'],
"password" => $password,
"address_zip" => "",
"stripe_customer_id" => $customer['id'],
"phone" => "",
"cardholder_name" => "",
"permission_version" => "1",
"ip" => "",
"is_first_login" => "1",
"package_id" => "2",
"img_path" => "",
"username" => $customer['email'],
"language" => "en",
"retype_password" => $password,
]);
$customerName = explode("@",$customer['email']);
if ($this->Cmsusers->save($cmsuser)) {
// add User To User Group
$this->addUserToUserGroup($cmsuser->id, USER_GROUP_ID);
// add User To Default Packages
$this->addUserToPackages($cmsuser->id,PACKAGE_ID);
$this->addUserToPackages($cmsuser->id,PACKAGE_WAVE_1_ID);
$template_content = array(
'firstname' => $customerName[0],
'user_email'=> $customer['email'],
'password' => $password,
'loginurl' => APP_SERVER_HOST_URL
);
//echo "Going to send email to :::".$customer['email'];
$this->sendEmail(MANDRILL_TEMPLATE_USER_CREATION, $template_content, $cmsuser->email);
}else{
// echo "::::::No data added----".$customer['email']."<br>\n";
}
}else{
// do nothing
}
}
}
}
private function createUser($cmsuser,$data) {
$cmsuser = $this->Cmsusers->patchEntity($cmsuser, $data);
$cmsuser->reset_password_token = '';
$cmsuser->created_on = date('Y-m-d H:i:s'); // date('Y-m-d H:i:s', strtotime("-61 day")); //
$cmsuser->updated_on = date('Y-m-d H:i:s');
$cmsuser->status = STATUS_ACTIVE;
$cmsuser->company_id = 8;
return $cmsuser;
}
function validateSchedule($schedule)
{
$scheduleParamArray = preg_split('/\s+/', $schedule);
$count = count($scheduleParamArray);
if ($count != 5) {
$this->error("Invalid schedule");
}
return true;
}
function cronjobExists($command)
{
$cronjob_exists = false;
$crontab = null;
exec('crontab -l', $crontab);
if (isset($crontab) && is_array($crontab)) {
foreach ($crontab as $tab) {
if (strpos($tab, $command) !== false) {
$cronjob_exists = true;
}
}
}
return $cronjob_exists;
}
function appendCronjob($command)
{
$output = null;
if (is_string($command) && !empty($command)) {
$executingCommand = 'echo -e "`crontab -l`\n' . $command . '" | crontab -';
exec($executingCommand, $output);
}
return $output;
}
//For closeing tickets that are not replied for more than 7 days
public function closeTicket()
{
$closed_time = CLOSE_TICKET_TIME -1;
$date = date("Y-m-d H:i:s",strtotime('-'.$closed_time.' days'));
$supportTable = TableRegistry::get('supports');
$supports = $supportTable->find()->where(['reply_date <'=> $date, 'status'=>1])->limit(20);
foreach($supports as $support){
$support->status = SUPPORT_STATUS_CLOSED;
$supportTable->save($support);
$template_content = [
'ticket_id'=>$support->id
];
$this->sendEmail(CLOSE_TICKET, $template_content, $support->email,$support->title);
}
$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "closeTicket","closeTicket");
}
//For archieving tickets that are not replied for more than 20 days
function archieveTicket(){
$archive_time = ARCHIEVE_TICKET_TIME -1;
$date = date("Y-m-d H:i:s",strtotime('-'.$archive_time .' days'));
$supportTable = TableRegistry::get('supports');
$supports = $supportTable->find()->where(['reply_date <'=> $date, 'status'=>2])->limit(20);
$current_time = $this->getSystemCurrentTimeStamp();
foreach($supports as $closedsupportObj){
$archievesupportTable = TableRegistry::get('supports_archieved');
$archievesupportObj = $archievesupportTable->newEntity();
$archievesupportObj->id = $closedsupportObj->id;
$cms_user_id = $archievesupportObj->cms_user_id = $closedsupportObj->cms_user_id;
// remove auto increment and assign direct object in one line
$archievesupportObj->priority = $closedsupportObj->priority;
$archievesupportObj->parent_id = $closedsupportObj->parent_id;
$archievesupportObj->user_type = $closedsupportObj->user_type;
$archievesupportObj->email = $closedsupportObj->email;
$archievesupportObj->name = $closedsupportObj->name;
$archievesupportObj->title = $closedsupportObj->title;
$archievesupportObj->description = $closedsupportObj->description;
$file_name = $archievesupportObj->file_name = $closedsupportObj->file_name;
$archievesupportObj->status = SUPPORT_STATUS_ARCHIEVED;
$archievesupportObj->is_read = $closedsupportObj->is_read;
$archievesupportObj->reply_date = $closedsupportObj->reply_date;
$archievesupportObj->created_on = !empty($closedsupportObj->created_on) ? $closedsupportObj->created_on : $current_time;
if($archievesupportTable->save($archievesupportObj)){
$supportTable->delete($closedsupportObj);
if (!is_dir(WWW_ROOT.'media/companies/'.$cms_user_id.'/archieved/')) {
mkdir(WWW_ROOT.'media/companies/'.$cms_user_id.'/archieved/', 0777, true);
}
if(!empty($file_name)){
$active_dir = WWW_ROOT.'media/companies/'.$cms_user_id.'/tickets/'.$file_name;
$archieve_dir = WWW_ROOT.'media/companies/'.$cms_user_id.'/archieved/'.$file_name;
if (copy( $active_dir, $archieve_dir )) {
unlink($active_dir);
}
}
}
}
$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "archieveTicket","archieveTicket");
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Shell;
use App\Utility\CurlRequest;
use Cake\I18n\FrozenTime;
class ProxyRenewalProcessShell extends AppShell {
private $proxy_url = 'https://proxy.webshare.io/api/v2';
// private $proxy_token = 'sq79yog0m570ays438scbkro80oo5un9o7fphbhm';
private $proxy_token = 'qayi6t20hm3q5se6cqfw7wown7kt142xolvvj3ol';
public function main() {
$this->out('Start');
$this->renewSubscription();
$this->out('End');
}
private function getSubscription(){
$curlRequest = new CurlRequest();
$URL = $this->proxy_url . "/subscription/";
$headers = ['Authorization:'.$this->proxy_token,'Content-Type:application/json'];
$result = $curlRequest->makeCurlGetRequest(null,$URL,$headers);
return json_decode($result);
}
private function renewSubscription(){
$current_date = new FrozenTime('now');
$subscription = $this->getSubscription();
if(!empty($subscription)){
$subscription_end_date = new FrozenTime($subscription->end_date);
$subscription_end_date = $subscription_end_date->format('Y-m-d');
$current_date = $current_date->format('Y-m-d');
if(isset($subscription->end_date) && $subscription_end_date == $current_date){
$cli_logData['ACTION'] = "RENEW SUBSCRIPTION";
$curlRequest = new CurlRequest();
$URL = $this->proxy_url ."/subscription/checkout/renew/";
$headers = ['Authorization:'.$this->proxy_token,'Content-Type:application/json'];
$param = ['term' => $subscription->term , 'payment_method' => $subscription->payment_method , 'recaptcha' => ''];
$result = $curlRequest->makeCurlRequest(json_encode($param),$URL,$headers);
$response = json_decode($result,true);
$cli_logData['RESULT'] = $response;
$this->cronjobLog($cli_logData);
$this->out('RENEW SUBSCRIPTION COMPLETED');
}
}
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace App\Shell;
use App\Utility\ManageLog;
use App\Utility\CurlRequest;
class ProxyUpdateShell extends AppShell {
public function initialize() {
}
public function main() {
$this->out('Start');
$this->proxyUpdate();
$this->out('End');
}
private function proxyUpdate(){
$cli_logData['ACTION'] = "PROXIES UPDATE";
$remove_text = ':gwgvgihz:xxwxnrwagewm';
$token = 'mffnfrxwxltpywruukqswshdfmrzaysfqpcszuqr';
$country = 'united%20states';
$curlRequest = new CurlRequest();
$URL = "https://proxy.webshare.io/api/v2/proxy/list/download/{$token}/-/any/username/direct/{$country}/";
$result = $curlRequest->makeCurlGetRequest(null,$URL);
$result = str_replace($remove_text, '', $result);
$ip_proxies = array_filter(array_map('trim', explode("\n", $result)));
if(empty($ip_proxies)){
$this->out('Proxies not found');
}
$result = $this->removeBlockIps($ip_proxies);
$result = $this->replaceFileText($result);
$cli_logData['total_proxies'] = count($ip_proxies);
$this->cronjobLog($cli_logData);
$this->out('Proxies Update Completed');
}
private function replaceFileText($proxies)
{
$proxiesPath = ROOT.'/scrapper/proxies.txt';
if (!$proxiesPath || !file_exists($proxiesPath)) {
$this->out('proxies.txt Path is not correct '.$proxiesPath);
}
// Write the new content back to the file
return file_put_contents($proxiesPath, $proxies);
}
private function removeBlockIps($ip_proxies)
{
$block_proxiesPath = ROOT.'/scrapper/proxies_block_ips.txt';
if (!$block_proxiesPath || !file_exists($block_proxiesPath)) {
$this->out('proxies_block_ips.txt Path is not correct '.$block_proxiesPath);
}
$block_proxies = file_get_contents($block_proxiesPath);
$ip_block_proxies = array_filter(array_map('trim', explode("\n", $block_proxies)));
// Remove matching items
$filtered_ips = array_diff($ip_proxies, $ip_block_proxies);
// Convert back to string
return implode("\n", $filtered_ips);
}
}

View File

@@ -0,0 +1,242 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
use RingCentral\SDK\SDK;
/**
* Ringcentral shell command.
*/
class RingcentralShell extends AppShell {
/**
* Manage the available sub-commands along with their arguments and help
*
* @see http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function processRCFax() {
require (WWW_ROOT.'Staff/vendor/autoload.php');
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_Ringcentral_processRCFax";
$this->cronjobLog($cli_logData);
$this->loadModel('FaxNumberFiles');
$this->loadModel('FaxNumbers');
//$this->loadModel('Logs');
$status = STATUS_ACTIVE;
$allFaxNumbers = $this->FaxNumbers->getAllFaxNumbers($status);
//pr($allFaxNumbers); exit;
$filterdFaxNumbers = [];
$IdList = array();
$membersList = [];
$addedNumber = [];
if (!empty($allFaxNumbers)) {
foreach ($allFaxNumbers as $faxNumbers) {
if (!array_key_exists($faxNumbers->fax_number, $filterdFaxNumbers)) {
$filterdFaxNumbers[$faxNumbers->fax_number] = $faxNumbers;
}
if (!array_key_exists($faxNumbers->member_id, $membersList)) {
$membersList[$faxNumbers->member_id] = $faxNumbers;
}
}
}
if (!empty($membersList)) {
$rcsdk = NULL;
foreach ($membersList as $member_id => $parentFaxNumberObj) {
// connect with Ringcentrol with $parentFaxNumberObj
$faxCredential['ring_client_id'] = $parentFaxNumberObj['fax_client_id'];
$faxCredential['ring_client_secret'] = $parentFaxNumberObj['fax_client_secret'];
$faxCredential['ring_password'] = $parentFaxNumberObj['fax_password'];
$faxCredential['ring_server'] = $parentFaxNumberObj['fax_server'];
$faxCredential['ring_extension'] = $parentFaxNumberObj['fax_extension'];
$faxCredential['ring_account'] = $parentFaxNumberObj['fax_account'];
$rcsdk = new SDK($faxCredential['ring_client_id'], $faxCredential['ring_client_secret'], $faxCredential['ring_server'], 'Fax|SMS|MMS', '1.0.0');
$platform = $rcsdk->platform();
try {
$platform->login($faxCredential['ring_account'], $faxCredential['ring_extension'], $faxCredential['ring_password']);
if ($rcsdk->platform()->loggedIn()) {
//$this->errorLog("RingCentral Fax Success", "Yes authenticated");
$logData['status'] = 1;
$logData['description'] = "";
}
} catch (\Exception $e) {
$logData['status'] = 2;
if (!empty($e->getMessage())) {
$logData['description'] = $e->getMessage();
$error_string = "Member ID: ".$member_id." Error message : ".$e->getMessage();
$this->errorLog("RingCentral Fax Error ", $error_string);
// log RingCentral Fax auth Error
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_RingCentral_Fax_auth_error";
$cli_logData['message'] = $error_string;
$this->cronjobLog($cli_logData);
}
}
$faxNumberFiles = $this->FaxNumberFiles->getFaxNumberFilesWithFaxNumberByMemberId($member_id);
$fileListAssoc = array();
$filteredFaxNumberFiles = array();
if (!empty($faxNumberFiles)) {
foreach ($faxNumberFiles as $fxfile) {
//set filtered
if (!in_array($fxfile->fax_number->id, $filteredFaxNumberFiles)) {
$filteredFaxNumberFiles[] = $fxfile->fax_number->id;
}
if($fxfile->fax_number->letter_type == 2){
$pdf_real_path = "epicvelocity/pdf/ringcentral/" . $fxfile->fax_number->id . "/" . $fxfile->fax_file_path;
}else if($fxfile->fax_number->letter_type == 1){
$pdf_real_path = "velocity/fax/pdf/" . $fxfile->fax_number->id . "/" . $fxfile->fax_file_path;
}
$relative_path = $pdf_real_path;
$pdf_real_path = WWW_ROOT . $pdf_real_path;
$current_fax_number = $fxfile->fax_number->fax_number;
if (file_exists($pdf_real_path)) {
$logData['source'] = "Sent to member Fax by cronjob";
try {
$request = $rcsdk->createMultipartBuilder()->setBody(array(
'to' => array(
array('phoneNumber' => $current_fax_number),
),
'faxResolution' => 'High',
'coverIndex' => 0))
->add(fopen($pdf_real_path, 'r'), basename($pdf_real_path))
->request('/account/~/extension/~/fax');
$response = $platform->sendRequest($request);
$status = $response->response()->getStatusCode();
if ($status == 200) {
$logData['status'] = 1;
$logData['description'] = "";
// after success delete current row from second table by id
$this->FaxNumberFiles->deleteFaxnumberFileById($fxfile->id);
} else {
// log RingCentral Fax auth Error
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_RingCentral Fax Failed";
$cli_logData['message'] = "Parent_id : " . $fxfile->fax_number->id . " File name : " . $fxfile['fax_file_path'];
$this->cronjobLog($cli_logData);
// count_attempt increment after failed
$this->FaxNumberFiles->updateFaxNumberFilesById($fxfile->id);
}
} catch (\Exception $e) {
$this->FaxNumberFiles->updateFaxNumberFilesById($fxfile->id);
$logData['status'] = 2;
$logData['description'] = $e->getMessage();
$error_string = "Member ID: ".$member_id." Error message : ".$e->getMessage();
$this->errorLog("RingCentral Fax Error ", $error_string);
}
//$this->Logs->createtLog($logData);
}
}
}
// select * from T1 where member_id=<>
$from_parent = $this->FaxNumbers->getFaxNumbersBymemberId($member_id);
if (!empty($from_parent)) {
//for(all first table record){
foreach ($from_parent as $parent) {
if ($parent->id > 0) {
//get record from T2 where fax_number_id =<PK of T1> 4/5/6/7
$from_child = $this->FaxNumberFiles->getFaxNumberFilesByFaxNumberId($parent->id);
//if(record not found in T2 by 4/5/6/7){
if (empty($from_child)) {
//delete from T1 by 4/5/6/7, delete relevant directory
if($parent->letter_type == 2){
$pdf_real_path = __DIR__ . "/../../webroot/epicvelocity/pdf/ringcentral/" . $parent->id;
}else if($parent->letter_type == 1){
$pdf_real_path = __DIR__ . "/../../webroot/velocity/fax/pdf/" . $parent->id;
}
if(file_exists($pdf_real_path)){
$this->delete_directory($pdf_real_path);
$this->FaxNumbers->deleteFaxnumberById($parent->id);
}
}
}
}
}
//}
//if there are no files, delete parent, remove directory
// if (!empty($filteredFaxNumberFiles)) {
// foreach ($filteredFaxNumberFiles as $value) {
// $pk_id = $value;
// $result = $this->FaxNumberFiles->getFaxNumberFilesByFaxNumberId($pk_id);
// if(empty($result)){
// $pdf_real_path = __DIR__ . "/../../webroot/epicvelocity/pdf/ringcentral/".$pk_id;
// $this->delete_directory($pdf_real_path);
// $this->FaxNumbers->deleteFaxnumberById($pk_id);
// }
//
// }
// }
}
}
$this->FaxNumberFiles->removeAllFailedFax(); // delete file & record where attempt count > 2
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_Ringcentral_processRCFax";
$this->cronjobLog($cli_logData);
}
private function delete_directory($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while ($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname . "/" . $file))
@unlink($dirname . "/" . $file);
else
delete_directory($dirname . '/' . $file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
private function errorLog($type, $error) {
$current_date = date('Y-m-d H:i:s');
$file = fopen(WWW_ROOT . "epicvelocity/sertg_export_error.txt", "a");
fwrite($file, "\n\n" . $current_date . " : " . $type . " : " . $error);
fclose($file);
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Shell;
use App\Common\PDFLetters;
use Cake\Console\Shell;
/**
*SaveLetterRemove shell command.
*/
class SaveLetterRemoveShell extends AppShell
{
/**
* Manage the available sub-commands along with their arguments and help
*
* @see http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help
*
* @return \Cake\Console\ConsoleOptionParser
*/
public function processSaveLettersRemoved(){
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_processSaveLettersRemoved";
$this->cronjobLog($cli_logData);
$this->loadModel("PdfLetters");
$data_source = $this->PdfLetters->getConnection();
try {
$data_source->begin();
$root_folder = WWW_ROOT . PDFLetters::ROOT_FORDER;
$velocity_type_array = EPIC_AND_SERTG_DROPDOWN;
$saveLetterObjList = $this->PdfLetters->getRemovablePdfLetters();
$num_of_letters = count($saveLetterObjList);
$logdata = [];
if ($num_of_letters > 0) {
foreach ($saveLetterObjList as $saveLetterObj) {
$logdata[] = $saveLetterObj;
$member_id = $saveLetterObj->member_id;
$velocity_type = $saveLetterObj->velocity_type;
$client_id = $saveLetterObj->client_id;
$velocity_id = $saveLetterObj->velocity_id;
$previous_file = $root_folder . "/" . $velocity_type_array[$velocity_type] . "/" . $member_id . "/" . $client_id . "/" . $velocity_id;
// status inactive and remove file
if ($this->PdfLetters->statusUpdateById($saveLetterObj->id, 0)) {
PDFLetters::deleteDir($previous_file);
}
}
$data_source->commit();
}
}catch (\Exception $exception){
$data_source->rollback();
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_exception_processSaveLettersRemoved";
$cli_logData['exception'] = $exception->getMessage();
$cli_logData['exception_trace'] = $exception->getTrace();
$this->cronjobLog($cli_logData);
}
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_processSaveLettersRemoved";
$cli_logData['executed_letters'] = $num_of_letters;
if(!empty($logdata)){
$cli_logData['data'] = $logdata;
}
$this->cronjobLog($cli_logData);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Shell;
use Cake\Console\Shell;
/**
* SendMailToGuest shell command.
*/
class SendMailToGuestShell extends AppShell
{
public function processEmail(){
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_SendMailToGuest_processEmail";
$this->cronjobLog($cli_logData);
$this->loadModel('Guest');
$guests = $this->Guest->getNeverLoggedInGuest();
if(!empty($guests)){
foreach ($guests as $guest){
$to = $guest->email;
$templateContent['guest_id'] = $guest->id;
$templateContent['email'] = $to;
$templateContent['main_domain'] = APP_SERVER_HOST_URL;
$this->sendEmail(GUEST_REMINDER_EMAIL_TEMPLATE, $templateContent, $to,"Your Purchase is Ready!");
// log for every guest user email sending
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_send_email_to_guest_user";
$cli_logData['email_data'] = $templateContent;
$this->cronjobLog($cli_logData);
$this->Guest->updateNextActionDateByInterval($guest->id, $guest->next_action_date,1);
}
}
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_SendMailToGuest_processEmail";
$this->cronjobLog($cli_logData);
}
}

View File

@@ -0,0 +1,205 @@
<?php
namespace App\Shell;
use Cake\Datasource\ConnectionManager;
class UpdateDataItemKeyValuesShell extends AppShell {
public function initialize() {
$this->loadModel('CreditAnalyzerReports');
$this->loadModel('DataItemKeyValues');
}
public function main($limit=100) {
$this->out('Start');
$this->updateDataItemKeyValuesTable($limit);
$this->out('Update completed');
$this->out('End');
}
private function UpdateDataCreditAnalyzerReport()
{
$client_id = 35612;
$client_id = 36139;
$connection = ConnectionManager::get('default');
$table = 'credit_analyzer_reports';
// $sql = "SELECT MAX(id) as id, COUNT(id) as row_count,client_id from " .$table. " group by client_id HAVING COUNT(client_id)>2" ;
$sql = "SELECT MAX(id) as id, COUNT(id) as row_count,client_id from " .$table. " where client_id=".$client_id." group by client_id HAVING COUNT(client_id)>2" ;
// dd($sql);
$statement = $connection->prepare($sql);
$statement->execute();
$clients_data = $statement->fetchAll();
// dd($data);
foreach ($clients_data as $client)
{
$id = $client[0];
$client_id = $client[2];
// $this->loadModel('CreditAnalyzerReportsTable');
$client_info = $this->CreditAnalyzerReports->find()
->where(['client_id'=>$client_id,'id'=>$id])
->first();
if(!empty($client_info)) {
$deleted_items = json_decode($client_info['deleted_items'], true);
$update_to_negative_items = json_decode($client_info['update_to_negative_items'], true);
$update_to_positive_items = json_decode($client_info['update_to_positive_items'], true);
$new_added_items = json_decode($client_info['new_added_items'], true);
// dd($deleted_items,$update_to_negative_items,$update_to_positive_items,$new_added_items);
$total_added_item = $this->getAccountData($new_added_items['account']) +
$this->getInqueryData($new_added_items['inquiry']) +
$this->getPersonalInfoData($new_added_items['personal_info']);
$total_deletd_item = $this->getAccountData($deleted_items['account']) +
$this->getPersonalInfoData($deleted_items['personal_info']) +
$this->getInqueryData($deleted_items['inquiry']);
$total_update_to_negative_item = $this->getAccountData($update_to_negative_items['account']) +
$this->getPersonalInfoData($update_to_negative_items['personal_info']) +
$this->getInqueryData($update_to_negative_items['inquiry']);
$total_update_to_positive_item = $this->getAccountData($update_to_positive_items['account']) +
$this->getPersonalInfoData($update_to_positive_items['personal_info']) +
$this->getInqueryData($update_to_positive_items['inquiry']);
$set_string = 'deleted='.$total_deletd_item.', update_to_negative='.$total_update_to_negative_item.', update_to_positive='.$total_update_to_positive_item.', new_added='.$total_added_item;
$this->updateCreditAnalyzerReport($id,$set_string);
// dd($total_deletd_item, $total_added_item, $total_update_to_negative_item, $total_update_to_positive_item);
}
// dd($client_info);
}
}
private function getInqueryData($data){
return count($data);
}
private function getPersonalInfoData($data){
$personal_info_total = 0;
foreach ($data as $key=>$value) {
if (!empty($value['fkey'])) {
$trans = 0;
$exp = 0;
$equif = 0;
if (!empty($value['fkey']['TransUnion']['data'])) {
$trans = 1;
}
if (!empty($value['fkey']['Experian']['data'])) {
$exp = 1;
}
if (!empty($value['fkey']['Equifax']['data'])) {
$equif = 1;
}
$personal_info_total = $personal_info_total + ($trans+$exp+$equif);
}
}
return $personal_info_total;
}
private function getAccountData($data){
$account_total = 0;
foreach ($data as $key=>$value) {
if (!empty($value['fkey'])) {
$trans = 0;
$exp = 0;
$equif = 0;
if (!empty($value['fkey']['trans']['accountno'])) {
$trans = 1;
}
if (!empty($value['fkey']['exp']['accountno'])) {
$exp = 1;
}
if (!empty($value['fkey']['equif']['accountno'])) {
$equif = 1;
}
$account_total = $account_total + ($trans+$exp+$equif);
}
}
return $account_total;
}
private function updateCreditAnalyzerReport($id,$set_string){
$connection = ConnectionManager::get('default');
$table = 'credit_analyzer_reports';
$sql = "update " .$table. " set ".$set_string." WHERE id=".$id ;
$statement = $connection->prepare($sql);
$statement->execute();
}
private function updateDataItemKeyValuesTable($limit)
{
$clients = $this->DataItemKeyValues->find()
->where(['is_processed'=>0,'is_delete' => 1])
->limit($limit)
->toArray();
if(!empty($clients)) {
foreach ($clients as $client) {
$transUnion = json_decode($client['value1'], true);
$experian = json_decode($client['value5'], true);
$equifax = json_decode($client['value6'], true);
$client['type'] = !empty($transUnion['account']) ? 4: 3;
$client['type2'] = !empty($experian['account']) ? 4: 3;
$client['type3'] = !empty($equifax['account']) ? 4: 3;
$client['is_processed'] = 1;
$this->DataItemKeyValues->save($client);
}
}
}
}

View File

@@ -0,0 +1,160 @@
<?php
namespace App\Shell;
class UpdateDataItemsShell extends AppShell {
public function initialize() {
$this->loadModel('CreditAnalyzerReports');
$this->loadModel('HtmlCodeHistories');
}
public function main($client_id=null)
{
$this->out('Start');
$message = 'Please provide a client id';
if (isset($client_id)){
$this->updateDataItemKeyValues($client_id);
$message = 'Update completed';
}
$this->out($message);
$this->out('End');
}
private function updateDataItemKeyValues($member_id){
// $member_id = 51;
// $analyzers = $this->CreditAnalyzerReports->getAllCreditAnalyzer($member_id);
// foreach ($analyzers as $analyzer){
// dd($analyzers);
$client_id = $member_id;
// $client_id=19549;
$historys = $this->CreditAnalyzerReports->getAllHistorysByCientId($client_id);
$history_count = count($historys);
if(!empty($historys) && $history_count >1){
foreach ($historys as $key=>$history) {
if($history_count == ($key+1)){
break;
}
$data_first = $historys[$key];
$data_last = $historys[$key+1];
$path_last = WWW_ROOT . "html_history_code/history_data/" . $history['member_id'] . "/" . $history['client_id'] . "/".$data_last['history_id'].".json";
$path_first = WWW_ROOT . "html_history_code/history_data/" . $history['member_id'] . "/" . $history['client_id'] . "/".$data_first['history_id'].".json";
//dd($path_last,$path_first);
$data[$key] = $data_first['history_id'];
$data[$key+1]= $data_last['history_id'];
$json_data_lasts = json_decode(file_get_contents($path_last), true);
$json_data_firsts = json_decode(file_get_contents($path_first), true);
// removed items
$removed_items = [];
foreach ($json_data_firsts['bank_info'] as $json_data_first) {
$keyValue = $json_data_first['bank_name'];
$result = array_filter($json_data_lasts['bank_info'], function ($var) use ($keyValue) {
return ($var['bank_name'] == $keyValue);
});
if (empty($result)) {
$removed_items[] = $json_data_first;
}
}
// added items
$added_items = [];
foreach ($json_data_lasts['bank_info'] as $json_data_last) {
$keyValue = $json_data_last['bank_name'];
$result = array_filter($json_data_firsts['bank_info'], function ($var) use ($keyValue) {
return ($var['bank_name'] == $keyValue);
});
if (empty($result)) {
$added_items[] = $json_data_last;
}
}
$history_data = $this->HtmlCodeHistories->getHistoryData($history['history_id']);
$deleted_accounts['delete_account'] = $removed_items;
$deleted_accounts['dd_id'] = $history_data['dd_id'];
// dd($deleted_accounts);
$this->addOrRemoveAccount($deleted_accounts);
$added_accounts['added_account'] = $added_items;
$added_accounts['dd_id'] = $history_data['dd_id'];
$this->addOrRemoveAccount($added_accounts);
// $this->addOrRemoveAccount($added_items);
// dd($added_items);
// $removed_items = json_encode($removed_items);
// $added_items = json_encode($added_items);
// dd($removed_items, $added_items);
}
}
// dd($history_count,$data);
// }
}
private function addOrRemoveAccount($items){
if(!empty($items['delete_account'])) {
foreach ($items['delete_account'] as $key => $value) {
$removeData['dd_id'] = $items['dd_id'];
$removeData['key'] = $value['bank_name'];
$removeData['value'] = 1;
$this->loadModel('DataItemKeyValues');
$this->DataItemKeyValues->updateItemkeyValueById($removeData);
}
}
if(!empty($items['added_account'])) {
foreach ($items['added_account'] as $key => $value) {
$removeData['dd_id'] = $items['dd_id'];
$removeData['key'] = $value['bank_name'];
$removeData['value'] = 0;
$this->loadModel('DataItemKeyValues');
$this->DataItemKeyValues->updateItemkeyValueById($removeData);
}
}
// $result['button_type'] = $response['button_type'];
//
// if(strpos($response['refresh_date'],$remove_refresh_text)){
// $result['button_type'] = 2;
// }
// $pb['is_remove_from_report'] = 0;
// if($inputData['value'] == "1"){
// $pb['is_remove_from_report'] = 1;
// }
}
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* Created by PhpStorm.
* User: rsi
* Date: 08-Feb-16
* Time: 9:30 PM
*/
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\Mailer\Email;
use Stripe;
use DateTime;
//require '../webroot/dropbox/vendor/autoload.php';
//App::import('Controller', 'Registration');
class sendTomemberEmailShell extends AppShell {
public function initialize() {
parent::initialize();
$this->loadModel('Personalizes');
$this->loadModel('Logs');
}
public function sendToMemberEmail(){
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_sendTomemberEmail_sendToMemberEmail";
$this->cronjobLog($cli_logData);
$this->loadModel('Cmsusers');
$this->loadModel('Personalizes');
$this->loadModel('Sertg');
$cmsusers = $this->Cmsusers->find()
->select(['Cmsusers.id','Cmsusers.email'])
->where([
'Cmsusers.is_receive_notification' => 1,
'Cmsusers.is_active' => STATUS_ACTIVE,
'DATE(Cmsusers.received_notification_date) <> DATE(NOW())'
])->toArray();
if(!empty($cmsusers)){
foreach ($cmsusers as $cmsuser){
$no_of_yellow = $this->Sertg->isNextSelectionNearestDay($cmsuser->id);
if($no_of_yellow > 0){
$personalize = $this->Personalizes->getPersonalizeByMemberId($cmsuser->id);
$templateContent['member_id'] = $cmsuser->id;
$templateContent['client_id'] = 0;
$templateContent['source'] = "Send to member email by cronjob";
$this->sendEmail("sendtomember_email", $templateContent, $cmsuser->email, "You Have Clients Waiting To Be Helped", "",$personalize);
//log for yellow color client files sending email notification
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_NEAREST_DAY_CLIENT_FILE_SENDING_EMAIL_NOTIFICATION";
$cli_logData['email_data'] = $templateContent;
$cli_logData['cmsuser_data'] = $cmsuser;
$this->cronjobLog($cli_logData);
$update_cmsuser = $this->Cmsusers->get($cmsuser->id);
$update_cmsuser->received_notification_date = date('Y-m-d');
$this->Cmsusers->save($update_cmsuser);
}
}
}
//$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "sendToMemberEmail","sendToMemberEmail");
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_sendTomemberEmail_sendToMemberEmail";
$this->cronjobLog($cli_logData);
}
// bin/cake sendTomemberEmail sendLetterNotificationEmail
public function sendLetterNotificationEmail(){
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_START_sendTomemberEmail_sendLetterNotificationEmail";
$this->cronjobLog($cli_logData);
$this->loadModel('Cmsusers');
$this->loadModel('Contacts');
$this->loadModel('Personalizes');
$letter_email_schedulesTable = TableRegistry::get('letter_email_schedules');
$letter_email_schedules = $letter_email_schedulesTable->find()->where(['is_active'=>STATUS_ACTIVE])->toArray();
// pr($letter_email_schedules); exit;
if(!empty($letter_email_schedules)){
foreach ($letter_email_schedules as $letter_email_schedule){
date_default_timezone_set($letter_email_schedule->gmt);
$current_date = date('Y-m-d H:i:s');
$current_date = strtotime($current_date);
$db_datetime = strtotime($letter_email_schedule->datetime);
if($current_date > $db_datetime){
$templateContent['member_id'] = $letter_email_schedule->member_id;
$templateContent['client_id'] = $letter_email_schedule->client_id;
$templateContent['source'] = "Send to client email by cronjob";
$templateContent['client_name'] = $letter_email_schedule->client_name;
$templateContent['set'] = LETTER_TYPE_FOR_MAIL[$letter_email_schedule->letter_set];
$templateContent['letter_signature'] = nl2br($letter_email_schedule->letter_email_signature);
$email_subject = "Great News! We Have Started Your ".$templateContent['set']." Set Of Letters";
$templateContent['email_title'] = $email_subject;
$client = $this->Contacts->getMemberIdByClientEmail($letter_email_schedule->client_email);
$personalize = $this->Personalizes->getPersonalizeByMemberId($client->cmsuser_id);
$this->sendEmail('sendclientemail', $templateContent, $letter_email_schedule->client_email,$email_subject,"","DO NOT REPLY",$personalize);
// log for letter notification email to client info & email data
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_LETTER_NOTIFICATION_CLIENT_INFO_EMAIL_DATA";
$cli_logData['client_info'] = $client;
$cli_logData['email_data'] = $templateContent;
$this->cronjobLog($cli_logData);
$schedules = $letter_email_schedulesTable->get($letter_email_schedule->id);
$letter_email_schedulesTable->delete($schedules);
}
}
}
//$this->Cmsusers->shellLog(date('Y-m-d H:i:s'), "sendLetterNotificationEmail","sendLetterNotificationEmail");
$cli_logData = [];
$cli_logData['action'] = "CRONJOB_END_sendTomemberEmail_sendLetterNotificationEmail";
$this->cronjobLog($cli_logData);
}
}