I need your opinion with detecting scenarios
We’re saving an image to a gallery
public function afterSave($insert,$changedAttributes)
{
if ($this->getScenario()==self::SCENARIO_CREATE)//if we create image, we're resizing the image file and update gallery's count +1
{
ImageSet::updateAllCounters(['count'=>1],"pk = ".$this->imageSetPk); //ImageSet is the gallery that gets an update count of images + 1
try {
$this->createFiles();//the original image is been resized here
} catch (RuntimeException $e)
{
$this->delete();//if i got a wrong or broken image that throws exception from my image processor - I delete this model right away
}
}
return parent::afterSave($insert,$changedAttributes);
}
I think there is a better way to use b[/b] and $this->delete(). I need your advice.