/** * @todo this is a copy of the old code, clean up! * @param unknown $fileId * @param unknown $filterId */ public function addImage($fileId, $filterId = 0, $throwException = false) { try { $query = (new \admin\image\Query())->where(['file_id' => $fileId, 'filter_id' => $filterId])->one(); if ($query && $query->fileExists) { return $query; } $fileQuery = $this->getFile($fileId); if (!$fileQuery) { throw new Exception("Unable to create image, cause the base file does not exist."); } $imagine = new Imagine(); $image = $imagine->open($fileQuery->serverSource); $fileName = $filterId . '_' . $fileQuery->systemFileName; $fileSavePath = $this->serverPath . '/' . $fileName; if (empty($filterId)) { $save = $image->save($fileSavePath); } else { $model = StorageFilter::find()->where(['id' => $filterId])->one(); if (!$model) { throw new Exception("Could not find the provided filter id '{$filterId}'."); } $newimage = $model->applyFilter($image, $imagine); $save = $newimage->save($fileSavePath); } if (!$save) { throw new Exception("unable to store file {$fileSavePath}"); } $resolution = Storage::getImageResolution($fileSavePath); $model = new StorageImage(); $model->setAttributes(['file_id' => $fileId, 'filter_id' => $filterId, 'resolution_width' => $resolution['width'], 'resolution_height' => $resolution['height']]); if (!$model->save()) { throw new Exception("Unable to save storage image, fatal database exception."); } $this->_imagesArray[$model->id] = $model->toArray(); $this->deleteHasCache($this->imageCacheKey); return $this->getImage($model->id); } catch (Exception $err) { if ($throwException) { throw new Exception($err->getMessage(), $err->getCode(), $err); } } return false; }
public function actionFilemanagerRemoveFiles() { foreach (Yii::$app->request->post('ids', []) as $id) { if (!Storage::removeFile($id)) { return false; } } return true; }