diff --git a/plugins/baser-core/src/Service/ThemesService.php b/plugins/baser-core/src/Service/ThemesService.php index e60a5eaeb8..734e123179 100644 --- a/plugins/baser-core/src/Service/ThemesService.php +++ b/plugins/baser-core/src/Service/ThemesService.php @@ -32,6 +32,7 @@ use Cake\Routing\Router; use Cake\Utility\Inflector; use Laminas\Diactoros\UploadedFile; +use BaserCore\Utility\BcFile; /** * ThemesService @@ -362,6 +363,47 @@ public function loadDefaultDataPattern(string $currentTheme, string $dbDataPatte return $result; } + /** + * ヘルパーのnamespaceを変更する + */ + public function changeHelperNameSpace($newTheme) + { + $pluginPath = BcUtil::getPluginPath($newTheme); + if (!$pluginPath) return false; + if (file_exists($pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php')) { + $helperClassPath = $pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php'; + }else{ + return false; + } + $file = new BcFile($helperClassPath); + $data = $file->read(); + $file->write(preg_replace('/namespace .+?;/', 'namespace ' . $newTheme . '\View\Helper;', $data)); + return true; + } + + /** + * ヘルパーのクラス名を変更する + */ + public function ChangeHelperClassName($oldTheme,$newTheme) + { + $pluginPath = BcUtil::getPluginPath($newTheme); + if (!$pluginPath) return false; + $oldPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $oldTheme . 'Helper.php'; + $newPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $newTheme . 'Helper.php'; + if(!file_exists($newPath)) + { + if(file_exists($oldPath)) { + rename($oldPath, $newPath); + } else { + return false; + } + } + $file = new BcFile($newPath); + $data = $file->read(); + $file->write(preg_replace('/class\s+.*?Helper/', 'class ' . $newTheme . 'Helper', $data)); + return true; + } + /** * コピーする * @@ -399,6 +441,8 @@ public function copy(string $theme): bool } BcUtil::changePluginClassName($oldTheme, $newTheme); BcUtil::changePluginNameSpace($newTheme); + $this->ChangeHelperClassName($oldTheme,$newTheme); + $this->changeHelperNameSpace($newTheme); return true; }