示例#1
0
 /**
  * SYNC STATUS
  * -------------
  * 0: Failed (Other)
  * 1: Successfully Synced
  * 2: Old Data Source Sync
  * 3: New Data Source Sync
  * 4: Failed on CSV Fetch
  * 5: Columns Do Not Match (Reconfigure)
  */
 public static function boot()
 {
     parent::boot();
     // Setup event bindings...
     DataSourceSync::created(function ($ds_sync) {
     });
 }
示例#2
0
 function syncData($sync)
 {
     // Add DataSource Sync
     $ds_sync = new DataSourceSync();
     $ds_sync->sync_id = $sync->id;
     $ds_sync->datasource_id = $this->id;
     // TODO: Check if new datasource
     if (true) {
         $ds_sync->sync_status = 2;
         // Old Data Source Sync
     } else {
         $ds_sync->sync_status = 3;
         // New Data Source Sync
     }
     $ds_sync->save();
     // Fetch Data
     $csv = $this->fetch();
     \Log::info('Download completed.');
     if (!$csv) {
         $ds_sync->sync_status = 3;
         $ds_sync->save();
         return false;
     }
     // Check column change
     if (array_keys($csv[0]) != $this->columns) {
         \Log::info('Columns are differnt from configuration.');
         $ds_sync->sync_status = 4;
         $ds_sync->save();
         $this->columns = array_keys($csv[0]);
         $this->status->col = 2;
         $this->save();
         // TODO: Email column change - needs configuration before sync
         return false;
     }
     // Set Projects from data fetched
     $this->setProjects($csv, $ds_sync);
     \Log::info('Projects update completed.');
     // TODO: Send alerts created from sync
     $ds_sync->sync_status = 1;
     $ds_sync->save();
     return true;
 }