public function run($model_id = null) { $descriptions = \Yii::$app->request->post('description', []); $sortOrder = (array) \Yii::$app->request->post('id', []); foreach ($descriptions as $id => $description) { $values = ['image_description' => $description]; if ($model_id !== null) { $values['object_model_id'] = $model_id; } Image::updateAll($values, 'id = :id', [':id' => $id]); } if (count($sortOrder) > 0) { $priorities = []; $start = 0; $ids = []; foreach ($sortOrder as $tid) { $priorities[intval($tid)] = $start++; $ids[] = intval($tid); } $case = 'CASE `id`'; foreach ($priorities as $k => $v) { $case .= ' when "' . $k . '" then "' . $v . '"'; } $case .= ' END'; $sql = "UPDATE " . Image::tableName() . " SET sort_order = " . $case . " WHERE id IN(" . implode(', ', $ids) . ")"; \Yii::$app->db->createCommand($sql)->execute(); } }
public function run() { if (Yii::$app->request->isAjax === false) { throw new NotAcceptableHttpException(); } $oldName = Yii::$app->request->post('oldname', ''); $newName = Yii::$app->request->post('newname', ''); if (!empty($oldName) && !empty($newName) && $oldName !== $newName) { try { /** * @var Filesystem $fs */ $fs = Yii::$app->getModule('image')->fsComponent; if ($fs->has($oldName)) { if ($fs->rename($oldName, $newName)) { Image::updateAll(['filename' => $newName], ['filename' => $oldName]); } else { throw new Exception('Error in renaming'); } } else { throw new Exception('No files to rename'); } } catch (Exception $except) { return $except->getMessage(); } return $newName; } return ''; }