Exemple #1
0
 /**
  * Sync table record accoring to their id
  * @param $table
  * @param $Id
  * @return array|string
  */
 public function syncId($table, $Id)
 {
     $table = ucfirst($table);
     $retData = $this->load($table, $Id);
     if (!is_array($retData)) {
         return 'Record Id = ' . $Id . ' from table ' . $table . ' was not found';
     }
     $inst = $this->createInstance($table);
     $newInst = $inst::find($Id);
     if (isset($newInst)) {
         try {
             $newInst->update($retData);
         } catch (Exception $e) {
             Log::syncException($table, $retData, $e->getMessage());
         }
     } else {
         try {
             $inst::create($retData);
         } catch (Exception $e) {
             Log::syncException($table, $retData, $e->getMessage());
         }
     }
     return $retData;
 }
Exemple #2
0
 /**
  * Fetch data from Infusionsoft and insert into database
  * @param $table
  * @return array|int
  */
 private function fetcher($table, $page = null)
 {
     $retData = $this->query($table, $page);
     if (!is_array($retData)) {
         return $retData;
     } elseif (empty($retData)) {
         return $retData;
     }
     $inst = $this->createInstance($table);
     if ($page == 0 || $page == null) {
         DB::table($table)->truncate();
     }
     foreach ($retData as $data) {
         try {
             $inst::create($data);
         } catch (Exception $e) {
             if ($table === 'DataFormField') {
                 Log::fetchException($table, $data, $e->getMessage());
                 $data['Values'] = json_encode($data['Values'], JSON_FORCE_OBJECT);
                 $inst::create($data);
             } else {
                 Log::fetchException($table, $data, $e->getMessage());
             }
         }
     }
     return count($retData);
 }