Skip to content

Commit

Permalink
テーマをコピーした際にヘルパーの重複エラーが表示される #3978
Browse files Browse the repository at this point in the history
  • Loading branch information
IwasakiRyuichi committed Dec 25, 2024
1 parent 174c718 commit 3a1f7ff
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/baser-core/src/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ public function copy(string $theme): bool
}
BcUtil::changePluginClassName($oldTheme, $newTheme);
BcUtil::changePluginNameSpace($newTheme);
BcUtil::changeHelperClassName($oldTheme,$newTheme);
BcUtil::changeHelperNameSpace($newTheme);
return true;
}

Expand Down
53 changes: 53 additions & 0 deletions plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,59 @@ public static function changePluginClassName(string $oldPlugin, string $newPlugi
return true;
}

/**
* ヘルパーのnamespaceを書き換える
* @param $newPlugin
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public static function changeHelperNameSpace($newPlugin)
{
$pluginPath = BcUtil::getPluginPath($newPlugin);
if (!$pluginPath) return false;
if(file_exists($pluginPath . 'src/view/helper' . DS . 'Helper.php')) {
$helperClassPath = $pluginPath . 'stc/view/helper' . DS . $newPlugin . 'Helper.php';
}elseif (file_exists($pluginPath . 'src/view/helper' . DS . $newPlugin . 'Helper.php')) {
$helperClassPath = $pluginPath . 'src/view/helper' . DS . $newPlugin . 'Helper.php';
}else{
return false;
}
$file = new BcFile($helperClassPath);
$data = $file->read();
$file->write(preg_replace('/namespace .+?;/', 'namespace ' . $newPlugin . '\View\Helper;', $data));
return true;
}

/**
* へルパーのクラス名を変更する
* @param string $oldPlugin
* @param string $newPlugin
* @return bool
*/
public static function changeHelperClassName(string $oldPlugin, string $newPlugin)
{
$pluginPath = BcUtil::getPluginPath($newPlugin);
if (!$pluginPath) return false;
$oldTypePath = $pluginPath . 'src/View/Helper' . DS . 'helper.php';
$oldPath = $pluginPath . 'src/view/Helper' . DS . $oldPlugin . 'Helper.php';
$newPath = $pluginPath . 'src/view/Helper' . DS . $newPlugin . 'Helper.php';
if(!file_exists($newPath)) {
if(file_exists($oldTypePath)) {
rename($oldTypePath, $newPath);
} elseif(file_exists($oldPath)) {
rename($oldPath, $newPath);
} else {
return false;
}
}
$file = new BcFile($newPath);
$data = $file->read();
$file->write(preg_replace('/class\s+.*?Helper/', 'class ' . $newPlugin . 'Helper', $data));
return true;
}

/**
* httpからのフルURLを取得する
*
Expand Down

0 comments on commit 3a1f7ff

Please sign in to comment.