shivsingh7150 Posted January 10, 2019 Share Posted January 10, 2019 Hello i am want to insert some value every day to a extra table created by me. so i am doing it by hook as below below noting doing. $filePre = date('Y-m-d', strtotime(' -1 day')); ///// One day old Date $updated_at = $created_at = date('Y-m-d H:i:s'); ///// Current date $extension = '.zip'; $nameArray = ('', 'domain', 'india', 'us'); ///// Add more database file name string after $filePre $test = ''; foreach ($nameArray as $fileName) { $test .= "$fileName <br>"; } add_hook('PreCronJob', 1, function($database) { $filePre = date('Y-m-d', strtotime(' -1 day')); ///// One day old Date $created_at = date('Y-m-d H:i:s', strtotime(' -1 day')); ///// Current date $updated_at = date('Y-m-d H:i:s'); ///// Current date $extension = '.zip'; $nameArray = ("4"=>"", "2"=>"domain", "1"=>"india", "7"=>"us"); ///// Database tyep with file name foreach ($nameArray as $whois_type => $fileName) { $whois_file = $filePre.''.$fileName.''.$extension; use WHMCS\Database\Capsule; try { Capsule::connection()->transaction( function ($connectionManager) { /** @var \Illuminate\Database\Connection $connectionManager */ $connectionManager->table('whois_database')->insert( [ 'whois_file' => $whois_file, 'whois_status' => 0, 'whois_type' => $whois_type, 'created_at' => $created_at, 'updated_at' => $updated_at, ] ); } ); echo 'cron test'; } catch (\Exception $e) { echo "Uh oh! Inserting didn't work, but I was able to rollback. {$e->getMessage()}"; } } }); . 0 Quote Link to comment Share on other sites More sharing options...
shivsingh7150 Posted January 10, 2019 Author Share Posted January 10, 2019 hello i have fixed it myself so please close this topic. my working code: <?php add_hook('PreCronJob', 1, function($vars) { $filePre = date('Y-m-d', strtotime(' -1 day')); ///// One day old Date $created_at = date('Y-m-d H:i:s', strtotime(' -1 day')); ///// Current date $updated_at = date('Y-m-d H:i:s'); ///// Current date $extension = '.zip'; $nameArray = array("4"=>"", "2"=>"-domain", "1"=>"-india", "7"=>"-us"); ///// Database tyep with file name foreach ($nameArray as $whois_type => $fileName) { $whois_md5 = md5(generateRandomString()); $whois_file = $filePre.''.$fileName.''.$extension; try { Illuminate\Database\Capsule\Manager::table("whois_database")->insert(array( "whois_md5" => $whois_md5, "whois_file" => $whois_file, "whois_status" => '0', "whois_type" => $whois_type, "created_at" => $created_at, "updated_at" => $updated_at)); } catch (Exception $e) { return array("status" => "error", "description" => "Unable to create table whois_database: " . $e->getMessage()); } } }); Thanks for attention 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.