/**
  * Saves an asset transform.
  *
  * @param AssetTransformModel $transform
  *
  * @throws Exception
  * @return bool
  */
 public function saveTransform(AssetTransformModel $transform)
 {
     if ($transform->id) {
         $transformRecord = AssetTransformRecord::model()->findById($transform->id);
         if (!$transformRecord) {
             throw new Exception(Craft::t('Can’t find the transform with ID “{id}”.', array('id' => $transform->id)));
         }
     } else {
         $transformRecord = new AssetTransformRecord();
     }
     $transformRecord->name = $transform->name;
     $transformRecord->handle = $transform->handle;
     $heightChanged = $transformRecord->width != $transform->width || $transformRecord->height != $transform->height;
     $modeChanged = $transformRecord->mode != $transform->mode || $transformRecord->position != $transform->position;
     $qualityChanged = $transformRecord->quality != $transform->quality;
     if ($heightChanged || $modeChanged || $qualityChanged) {
         $transformRecord->dimensionChangeTime = new DateTime('@' . time());
     }
     $transformRecord->mode = $transform->mode;
     $transformRecord->position = $transform->position;
     $transformRecord->width = $transform->width;
     $transformRecord->height = $transform->height;
     $transformRecord->quality = $transform->quality;
     $transformRecord->format = $transform->format;
     $recordValidates = $transformRecord->validate();
     if ($recordValidates) {
         $transformRecord->save(false);
         // Now that we have a transform ID, save it on the model
         if (!$transform->id) {
             $transform->id = $transformRecord->id;
         }
         return true;
     } else {
         $transform->addErrors($transformRecord->getErrors());
         return false;
     }
 }
 /**
  * @return array
  */
 private function _loadAssetTransforms()
 {
     if (is_null($this->_assetTransforms)) {
         $this->_assetTransforms = array();
         $models = AssetTransformModel::populateModels(AssetTransformRecord::model()->findAll());
         foreach ($models as $model) {
             $this->_assetTransforms[$model->handle] = $model;
         }
     }
 }