/** * Rename current page * * @param string $new_name * @return afResponse * @author Sergey Startsev */ public function rename($new_name) { $response = afResponseHelper::create(); if ($this->isNew()) { return $response->success(false)->message("Page doesn't exists, create widget first"); } $old_name = $this->getName(); $oldPath = $this->getPagePath(); $newPath = $this->getPagePath($new_name); if (file_exists($newPath)) { return $response->success(false)->message("Page <b>{$new_name}</b> already exists"); } $renamed = afsViewModelHelper::renameAction($old_name, $new_name, self::MODULE, $this->getApplication(), 'app'); afsFileSystem::create()->rename($oldPath, $newPath); if (!file_exists($oldPath) && file_exists($newPath)) { return $response->success(true)->message("Renamed page from <b>{$old_name}</b> to <b>{$new_name}</b>!"); } return $response->success(false)->message("Can't rename page from <b>{$old_name}</b> to <b>{$new_name}</b>!"); }
/** * Rename current widget * * @param string $new_name * @return afResponse * @author Sergey Startsev */ public function rename($new_name) { $response = afResponseHelper::create(); if ($this->isNew()) { return $response->success(false)->message("Widget doesn't exists, create widget first"); } $old_name = $this->getAction(); $module = $this->getModule(); $place = $this->getPlace(); $type = $this->getPlaceType(); $oldPath = $this->getPlaceConfigPath() . DIRECTORY_SEPARATOR . "{$old_name}.xml"; $newPath = $this->getPlaceConfigPath() . DIRECTORY_SEPARATOR . "{$new_name}.xml"; if (file_exists($newPath)) { return $response->success(false)->message("View {$new_name} already exists"); } $renamed = afsViewModelHelper::renameAction($old_name, $new_name, $module, $place, $type); afsFileSystem::create()->rename($oldPath, $newPath); if (!file_exists($oldPath) && file_exists($newPath)) { return $response->success(true)->message("Renamed page from <b>{$old_name}</b> to <b>{$new_name}</b>!"); } return $response->success(false)->message("Can't rename page from <b>{$old_name}</b> to <b>{$new_name}</b>!"); }