/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $properties = \App\Property::with('propertyImages')->get();
     foreach ($properties as $checkProperty) {
         try {
             $results = \App\Libraries\RetsQuery::properties('Property', 'Listing', '(Matrix_Unique_ID = ' . $checkProperty['Matrix_Unique_ID'] . ')');
         } catch (Exception $e) {
             Bugsnag::notifyException($e);
         } catch (PHRETS\Exceptions\CapabilityUnavailable $e) {
             Bugsnag::notifyException($e);
         }
         foreach ($results as $property) {
             if ($property['Status'] !== 'Active') {
                 if (!empty($checkProperty->propertyImages->toArray())) {
                     $this->removeClosedImages($checkProperty->propertyImages);
                 }
                 $this->removeFromElasticSearch($property['MLSNumber']);
                 $property = \App\Property::find($checkProperty['id']);
                 if ($property) {
                     $property->delete();
                 }
             }
         }
     }
     dispatch((new \App\Jobs\RemoveUnrelatedImages())->onQueue('images'));
 }
 public function getPropertyImages($MLSNumber)
 {
     do {
         // TODO: this may be where the timeout is occuring
         $photos = \App\Libraries\RetsQuery::photos('Property', 'LargePhoto', $MLSNumber);
     } while ($photos[0]->getContentId() == null);
     foreach (array_slice($photos->toArray(), 0, 10) as $photo) {
         $imageDiffer = str_random(40);
         $localDiskImage = '/tmp' . '/property-' . $MLSNumber . '-image-' . $imageDiffer . '.jpg';
         file_put_contents($localDiskImage, (string) $photo->getContent());
         $s3File = dispatch((new UploadImagesToS3($MLSNumber, $imageDiffer . '.jpg', $localDiskImage))->onQueue('s3Upload'));
         $createImage = \App\Image::create(['dataUri' => 'https://s3.sapioweb.com/jacobsgroupvegas/properties/' . env('APP_ENV') . '/' . $MLSNumber . '/' . $imageDiffer . '.jpg']);
         $images[] = $createImage->id;
     }
     return $images;
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $days = 100;
     $time = date('H:i:s');
     $startDate = date('Y-m-d', strtotime('-40 days'));
     $date = date('Y-m-d', strtotime('-0days'));
     while ($startDate <= $date) {
         try {
             $results = \App\Libraries\RetsQuery::properties('Property', 'Listing', '(Area=101,102,103,201,202,203,204,301,302,303,401,402,403,404,405,501,502,503,504,505,601,602,603,604,605,606) AND (ListPrice=100000+) AND (PropertyType=RES) AND NOT (PropertySubType=CON) AND (Status=A) AND (OriginalEntryTimestamp=' . $startDate . 'T' . $time . '-' . date('Y-m-d', strtotime('-' . $days . 'days')) . ')');
         } catch (Exception $e) {
             Bugsnag::notifyException($e);
         } catch (PHRETS\Exceptions\CapabilityUnavailable $e) {
             Bugsnag::notifyException($e);
         }
         $days = $days - 20;
         $startDate = date('Y-m-d', strtotime("+20 days", strtotime($startDate)));
         $results = $this->appendDescription($results->toArray());
         foreach ($results as $property) {
             dispatch((new MakeProperty($property))->onQueue('createProperty'));
         }
     }
 }