migrate - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of migrate.php

  1. <?php
  2.  
  3. use Illuminate\Database\Migrations\Migration;
  4. use TIM\Models\CronJob;
  5. use TIM\Models\EmergencyNumber;
  6. use TIM\Modules\CronJob\Helper\CronJobString;
  7.  
  8. class CreateCronjobEmergencyLogs extends Migration
  9. {
  10.     /**
  11.      * Run the migrations.
  12.      *
  13.      * @return void
  14.      */
  15.     public function up()
  16.     {
  17.         // If emergency number exists, create cron job
  18.         if (EmergencyNumber::count() > 0) {
  19.             $cronJob = new CronJob();
  20.             $cronJob->class = CronJob::DELETE_EMERGENCY_LOGS_JOB_CLASS;
  21.             $cronJob->payload = [];
  22.             $cronJob->cron = app(CronJobString::class)->buildCron(CronJobString::TYPE_DAILY, "5", 0, 0);
  23.             $cronJob->enabled = true;
  24.             $cronJob->system = true;
  25.             $cronJob->save();
  26.         }
  27.     }
  28.  
  29.     /**
  30.      * Reverse the migrations.
  31.      *
  32.      * @return void
  33.      */
  34.     public function down()
  35.     {
  36.         if (CronJob::where("class", CronJob::DELETE_EMERGENCY_LOGS_JOB_CLASS)->count() > 0) {
  37.             CronJob::where('class', CronJob::DELETE_EMERGENCY_LOGS_JOB_CLASS)->delete();
  38.         }
  39.     }
  40. }
  41.  
File Description
  • migrate
  • PHP Code
  • 24 Jun-2019
  • 1.06 Kb
You can Share it: