| Conditions | 8 |
| Paths | 9 |
| Total Lines | 30 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | public function run() |
||
|
|
|||
| 18 | { |
||
| 19 | if (Yii::$app->request->isAjax === false) { |
||
| 20 | throw new NotAcceptableHttpException(); |
||
| 21 | } |
||
| 22 | $oldName = Yii::$app->request->post('oldname', ''); |
||
| 23 | $newName = Yii::$app->request->post('newname', ''); |
||
| 24 | if (!empty($oldName) && !empty($newName) && $oldName !== $newName) { |
||
| 25 | try { |
||
| 26 | /** |
||
| 27 | * @var Filesystem $fs |
||
| 28 | */ |
||
| 29 | $fs = Yii::$app->getModule('image')->fsComponent; |
||
| 30 | if ($fs->has($oldName)) { |
||
| 31 | if ($fs->rename($oldName, $newName)) { |
||
| 32 | Image::updateAll(['filename' => $newName], ['filename' => $oldName]); |
||
| 33 | } else { |
||
| 34 | throw new Exception('Error in renaming'); |
||
| 35 | } |
||
| 36 | } else { |
||
| 37 | throw new Exception('No files to rename'); |
||
| 38 | } |
||
| 39 | |||
| 40 | } catch (Exception $except) { |
||
| 41 | return $except->getMessage(); |
||
| 42 | } |
||
| 43 | return $newName; |
||
| 44 | } |
||
| 45 | return ''; |
||
| 46 | } |
||
| 47 | } |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.