public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $existing = $this->getVuforiaInfo();
     if (!$this->updating) {
         $this->updating = true;
         if (!$existing && $this->TargetWidth) {
             $this->vuforiaAPIService->uploadNewTarget($this);
         }
         if ($existing && $this->isChanged('TargetWidth')) {
             // update the existing
             $this->vuforiaAPIService->updateTarget($this);
         }
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($this->getExtension() == 'png' || $this->getExtension() == 'gif') {
         $this->convertToJPEG();
     }
     if (!$this->TargetWidth) {
         $this->TargetWidth = 200;
     }
     $existing = $this->getVuforiaInfo();
     if (!$this->updating) {
         $this->updating = true;
         if (!$existing && $this->TargetWidth) {
             $this->vuforiaAPIService->uploadNewTarget($this);
         }
         if ($existing && $this->isChanged('TargetWidth')) {
             // update the existing
             $this->vuforiaAPIService->updateTarget($this);
         }
     }
 }