Jump to content

shivsingh7150

Newbie
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About shivsingh7150

  • Rank
    Junior Member
  1. shivsingh7150

    Insert to DB with Hook not working

    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
  2. 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()}"; } } }); .
  3. Welcome to WHMCS.Community shivsingh7150! We're glad you're here please take some time to familiarise yourself with the Community Rules & Guidelines and take a moment to introduce yourself to other WHMCS.Community members in the Introduce Yourself Board.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated